每当我使用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"
...
}