Terraform v0.12.20
provider.google v3.16.0
I am trying to create a tf file which I can use to create any of the three uptime checks with the resource google_monitoring_uptime_check_config
(uptime_url gce_instance gae_app).
The issue I am having is the labels field inside the monitored_resource block will have different values for each type.
I have defined the variable as such for one example:
variable "resource_type_labels" {
type = map
default = {
"project_id" = "my_project"
"module_id" = "default"
"version_id" = "20200zzzxxc"
"zone" = "us-central"
}
description = "Labels for the resource type. Labels are different for each resource type."
}
The goal would be in a .tfvar file I could override the resource_type_labels with the correct values for that type, and then have it build the monitored_resource block with the correct number of key value entries.
Example: gae_app has 4 values and uptime_url has 2 values.
Output should look like this according to the example.
monitored_resource {
type = "uptime_url"
labels = {
project_id = "my-project-name"
host = "192.168.1.1"
}
}
Can you tell me how I need to code it in the .tf file?
I have tried so many different ways with no success.
Here is just one example:
monitored_resource {
type = var.type
labels = {
for_each = var.resource_type_labels
(var.resource_type_labels.key) = (var.resource_type_labels.value)
}
}
Thank You in advance!