I´m using the aws_cloudformation_stack resource in Terraform to gather IDs about cloudformation security group stacks like so:
data "aws_cloudformation_stack" "vpc-prod-sg" {
name = "vpc-prod-sg"
}
I define a list in my main.tf file with names that represent these security groups like this:
sg_ingress = ["DevMyAppLinkingSecurityGroup", "DevDBLinkingSecurityGroup"]
In my module I assign the values from the Cloufformation stacks to the names in the list this:
security_groups = [contains(var.sg_ingress, "DevMyAppLinkingSecurityGroup") ? "${data.aws_cloudformation_stack.vpc-prod-sg.outputs["DevMyAppLinkingSecurityGroup"]}" : 0, contains(var.sg_ingress, "DevDBLinkingSecurityGroup") ? "${data.aws_cloudformation_stack.vpc-prod-sg.outputs["DevDBLinkingSecurityGroup"]}" : 0]
However, when I run the terraform plan, the list is populated with the values I want, but it also add an additional entry to the list with value of zero. It looks like this:
+ security_groups = [
+ "0",
+ "sg-05443559898348",
+ "sg-05435345443545593"
I'm baffled as to where this zero is coming from or how I can deal with it. Has anyone come across anything similar?
0
. That seems the most likely cause here. – Matt Schuchard