Terraform 1.4.3: implementing Conditional Logic in Resource Creation for GCP Cloud Functions
I'm trying to create a Cloud Function in GCP using Terraform 1.4.3, but I keep working with issues when using conditional logic within my resource block. I want to create a function only if a specific variable is set to true, but it seems like my approach is not working as expected. Here's a snippet of my Terraform code: ```hcl variable "create_function" { type = bool default = false } resource "google_cloudfunctions_function" "my_function" { count = var.create_function ? 1 : 0 name = "myFunction" runtime = "nodejs14" entry_point = "handler" source_archive_bucket = google_storage_bucket.function_bucket.name source_archive_object = google_storage_bucket_object.function_archive.name event_trigger { event_type = "providers/cloud.pubsub/eventTypes/topic.publish" resource = google_pubsub_topic.my_topic.id } } ``` In this setup, I expect the function to be created only if `create_function` is set to true. However, when I set the variable to true and execute `terraform apply`, I always receive the following behavior: ``` behavior: Resource 'google_cloudfunctions_function.my_function' not found on main.tf line 10, in resource "google_cloudfunctions_function" "my_function": 10: count = var.create_function ? 1 : 0 ``` I've double-checked that the variable is being passed correctly and even tried using `locals` to determine if the value was being recognized. I also tried using `count` as a condition on other resources, and it seems to work correctly there. I suspect there might be some nuance or limitation with how Google Cloud Functions handle `count`. Has anyone faced similar issues, or can you suggest what I might be doing wrong? I'm looking for advice on best practices when implementing conditional resource creation in Terraform for GCP services.