首页 > 解决方案 > Terraform 将新安全组添加到现有安全组

问题描述

我在 terraform 的 Autoscaling 模块中创建了一个新的安全组。我想将此安全组添加到模块数据库中的现有安全组中。数据库模块中使用的安全组已经通过控制台创建。如何将新的安全组添加到 terraform 中的现有安全组?

标签: amazon-web-servicesterraformaws-security-groupterraform-modules

解决方案


如果要更改控制台创建的 SG,则必须手动对其进行编辑。

如果更改terraform创建的SG,可以手动获取已存在SG的id,添加到SG的规则中

编辑:

你需要输出:

output "security_group_id" {
  description = "Security group ID attached to the EKS workers."
  value       = module.auto_scaling_module.security_group_id
}

比使用 data.tf 中的数据导入

data "terraform_remote_state" "autoscaling" {
  backend = "s3"
  config  = {
    region = "us-west-1"
    bucket = "wherestatelocate"
    key    = "path"
  }
}

比在数据库模块中使用它

  security_groups    = [data.terraform_remote_state.autoscaling.outputs.security_group_id
]

这就是我正在使用的


推荐阅读