I have a module that creates multiple outputs. The value of each output being an account number.
I'd like to use the count parameter on a resource to do iteration using the values from the module mentioned above. However, I'm learning that you cannot do interpolation on a variable default or layered interpolation.
What is the right way to handle this in terraform?
variable "service_node_accounts" {
description = "List of Account IDs"
type = "list"
default = ["${module.accounts.qa}", "${module.accounts.staging}", "${module.accounts.prod}"]
}
data "aws_ami" "service_node_1_0" {
filter {
name = "name"
values = ["service-node-1.0"]
}
owners = ["self"] # Canonical
}
resource "aws_ami_launch_permission" "service_node_1_0" {
count = "${length(var.service_node_accounts)}"
image_id = "${aws_ami.service_node_1_0.id}"
account_id = "${var.service_node_accounts[count.index]}"
}
terraform plan...
default may not contain interpolations
Consider using locals where interpolations are allowed.
locals {
# Untested but should work in theory
service_node_accounts = ["${module.accounts.qa}", "${module.accounts.staging}", "${module.accounts.prod}"]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With