This question is similar to this one, but is more complicated: Terraform, "ignore_changes" and sub-blocks.
I'm doing this:
variable "myapp_config" {
type = object({
app_name = string
google_bigtable_clusters = any
})
default = {
app_name = "myapp"
google_bigtable_clusters = {
instance01 = [
{
zone = "us-west1-a"
num_nodes = 1
},
{
zone = "us-west4-a"
num_nodes = 1
},
{
zone = "us-central1-a"
num_nodes = 1
},
{
zone = "us-east1-b"
num_nodes = 1
},
],
instance02 = [
{
zone = "us-east4-a"
num_nodes = 1
},
{
zone = "northamerica-northeast1-a"
num_nodes = 1
},
{
zone = "europe-west4-a"
num_nodes = 1
},
],
instance03 = [
{
zone = "europe-west6-a"
num_nodes = 1
},
{
zone = "asia-south1-a"
num_nodes = 1
},
],
}
}
}
I'm looping over a var to create google_bigtable_instance resource but I need to ignore the num_nodes
fields. I can't figure out how to do this
resource "google_bigtable_instance" "myinstances" {
for_each = var.myapp_config.google_bigtable_clusters
name = "${var.myapp_config.app_name}--${each.key}"
deletion_protection = true
dynamic "cluster" {
iterator = instance
for_each = each.value
content {
cluster_id = instance.value.zone
zone = instance.value.zone
num_nodes = instance.value.num_nodes
storage_type = "SSD"
}
}
lifecycle {
# num_nodes are variable so I can't statically set the index numbers
# ignore_changes = ["cluster.*.num_nodes"]
ignore_changes = ["cluster.${each.key}.num_nodes"]
}
}
I get this error:
A single static variable reference is required: only attribute access and
indexing with constant keys. No calculations, function calls, template
expressions, etc are allowed here.
I hope this isn't impossible. I'm not about to statically write out all these resources because the list is going to grow and this is what for_each is designed for.
Edit
Realized ${each.key} is not what I want I need to get the index number of that nested list.