【问题标题】:Terraform for aws security group create with name prefix使用名称前缀创建 AWS 安全组的 Terraform
【发布时间】:2020-08-27 02:58:13
【问题描述】:

每当我使用 terraform 模块创建 aws 安全组时,它都会创建一个 sgname 前缀,例如 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

【问题讨论】:

  • 问题是什么?
  • 修改问题

标签: terraform terraform-provider-aws aws-security-group


【解决方案1】:

因此,使用此模块,您可以设置以下内容:

module "sg" {
  source = "terraform-aws-modules/security-group/aws"
  use_name_prefix = false
  name = "my-sg-name"
  ...
}

【讨论】:

  • 那行得通。一个更好的名字应该是“use_name_postfix”......
猜你喜欢
  • 2019-02-23
  • 2019-08-20
  • 2013-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-06
  • 1970-01-01
  • 2020-05-30
相关资源
最近更新 更多