I'm very new to Terraform and excited to use it.
I've created the security group A
by Terraform and I want to attach the security group A
into the existing security group B
. I was trying to figure it out that it looks like object assign and spread operator in javascript.
I imagined like below,
data "aws_security_group" "A" {
id = "<id>"
}
resource "aws_security_group" "A" {
...data.aws_security_group.A,
ingress = [ ...data.aws_security_group.A.ingress]
}
and this is what I thought so far,
resource "aws_security_group" "A" {
vpc_id = var.a_vpc_id
ingress = [module.eks.aws_security_group.cluster] // I only want to add this ingress into the existing ingress at security group A
lifecycle = {
ignore_changes = [
ingress // ignore existing ingress
]
}
}
Is there any syntax or tweak to accomplish what I want? Any reference and keyword will make me happy.
(Updated) almost real code.
variable "internal_vpc_id" {
default = "vpc-12345678"
}
module "eks" {
....
}
resource "aws_security_group" "internal" {
vpc_id = var.internal_vpc_id
ingress = [
module.eks.aws_security_group.cluster,
module.eks.aws_security_group.workers,
module.eks.aws_security_group_rule.cluster_egress_internet,
module.eks.aws_security_group_rule.cluster_https_worker_ingress
]
lifecycle {
ignore_changes = [
ingress
]
}
}
question from:
https://stackoverflow.com/questions/65839907/update-and-append-new-properties-on-exising-resource-on-aws-using-terraform 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…