Terraform scenarios: Dynamic Block Not Generating Resources as Expected in GCP
I'm collaborating on a project where I'm sure I'm missing something obvious here, but I'm trying to use a dynamic block in my Terraform script to create multiple Google Cloud Pub/Sub subscriptions based on a variable list, but I'm working with an scenario where the subscriptions are not being created as expected. I have defined a variable `subscription_names` in my `variables.tf` file like this: ```hcl variable "subscription_names" { type = list(string) default = ["sub1", "sub2", "sub3"] } ``` In my main configuration, I am using a dynamic block within a `google_pubsub_topic` resource to create subscriptions. I expected three subscriptions to be created, but only the topic itself gets created, and I don't see any errors in the output. Here's the relevant snippet from my `main.tf`: ```hcl resource "google_pubsub_topic" "my_topic" { name = "my_topic" } resource "google_pubsub_subscription" "subscriptions" { for_each = toset(var.subscription_names) name = each.value topic = google_pubsub_topic.my_topic.id } ``` I have validated that `subscription_names` is being populated correctly, and I'm using Terraform version 1.2.0. I expected the `google_pubsub_subscription` resource to iterate over the list and create a subscription for each name in `subscription_names`, but Terraform applies the changes without actually creating the subscriptions. I also checked the state file, and it shows no entries for the subscriptions, which makes me think they're just being skipped. I've tried running `terraform plan` and `terraform apply` multiple times, and I've even added some debug logging. The output is always the same, indicating that no resources were created for the subscriptions. Is there something I'm missing in my configuration, or is there a limitation with dynamic blocks in this context? Any advice would be appreciated! Is there a better approach? This is happening in both development and production on Windows 11. I appreciate any insights! Am I approaching this the right way?