适用于 AWS 的地形安全组使用名称前缀创建



每当我使用 terraform 模块创建 AWS 安全组时,它都会创建一个 sgname-前缀,例如 user-service-20200511140358261500000001。 因此,总是地形应用删除现有的 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"
...
}

最新更新