使用名称前缀创建 aws 安全组的 Terraform
Terraform for aws security group create with name prefix
每当我使用 terraform 模块创建 aws 安全组时,它都会创建一个 sgname-prefix,例如 user-service-20200511140358261500000001。
因为这总是 terraform apply 删除现有的 sg 并创建新的 sg 即使没有改变它。
如何让它创建仅使用名称而不使用任何时间戳的 SG,例如:user-service-20200511140358261500000001 或
如何使 sg 保持不变而不改变以冻结?
示例代码
module "vote_service_sg" {
source = "terraform-aws-modules/security-group/aws"
name = "user-service"
description = "Security group for user-service with custom ports open within VPC, and PostgreSQL publicly open"
vpc_id = "vpc-xxx"
ingress_cidr_blocks = ["10.10.0.0/16"]
ingress_rules = ["https-443-tcp"]
ingress_with_cidr_blocks = [
{
from_port = 8080
to_port = 8090
protocol = "tcp"
description = "User-service ports"
cidr_blocks = "10.10.0.0/16"
},
{
rule = "postgresql-tcp"
cidr_blocks = "0.0.0.0/0"
},
]
}
模块:https://github.com/terraform-aws-modules/terraform-aws-security-group
因此,使用此模块,您可以设置以下内容来解决问题:
module "sg" {
source = "terraform-aws-modules/security-group/aws"
use_name_prefix = false
name = "my-sg-name"
...
}
每当我使用 terraform 模块创建 aws 安全组时,它都会创建一个 sgname-prefix,例如 user-service-20200511140358261500000001。 因为这总是 terraform apply 删除现有的 sg 并创建新的 sg 即使没有改变它。
如何让它创建仅使用名称而不使用任何时间戳的 SG,例如:user-service-20200511140358261500000001 或 如何使 sg 保持不变而不改变以冻结?
示例代码
module "vote_service_sg" {
source = "terraform-aws-modules/security-group/aws"
name = "user-service"
description = "Security group for user-service with custom ports open within VPC, and PostgreSQL publicly open"
vpc_id = "vpc-xxx"
ingress_cidr_blocks = ["10.10.0.0/16"]
ingress_rules = ["https-443-tcp"]
ingress_with_cidr_blocks = [
{
from_port = 8080
to_port = 8090
protocol = "tcp"
description = "User-service ports"
cidr_blocks = "10.10.0.0/16"
},
{
rule = "postgresql-tcp"
cidr_blocks = "0.0.0.0/0"
},
]
}
模块:https://github.com/terraform-aws-modules/terraform-aws-security-group
因此,使用此模块,您可以设置以下内容来解决问题:
module "sg" {
source = "terraform-aws-modules/security-group/aws"
use_name_prefix = false
name = "my-sg-name"
...
}