简体   繁体   English

Terraform 将新安全组添加到现有安全组

[英]Terraform add new security group to an existing security group

I have created a new security group in the Autoscaling module in terraform.我在 terraform 的 Autoscaling 模块中创建了一个新的安全组。 I want to add this security group to an existing security group in the module Database.我想将此安全组添加到模块数据库中的现有安全组中。 The security group used in the database module is already created through the console.数据库模块中使用的安全组已经通过控制台创建。 How to add a new security group to an existing security group in terraform?如何在 terraform 中的现有安全组中添加新的安全组?

If you want to change the SG created by console, you have to edit it manually.如果要更改控制台创建的 SG,则必须手动对其进行编辑。

If you change the SG created by terraform, you can get the id of the existed SG manually and add it to a rule of SG如果更改terraform创建的SG,可以手动获取已存在SG的id,添加到SG的规则中

EDIT:编辑:

You need to output:您需要 output:

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

Than import by using data in data.tf比使用 data.tf 中的数据导入

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

Than use it in database module比在数据库模块中使用它

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

This is what i am using这就是我正在使用的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM