# Google Monitoring Uptime Check - monitored\_resource - labels

**URL:** <https://discuss.hashicorp.com/t/google-monitoring-uptime-check-monitored-resource-labels/7572>\
**Category:** Terraform\
**Created:** [April 10, 2020, 7:58pm UTC](https://discuss.hashicorp.com/t/google-monitoring-uptime-check-monitored-resource-labels/7572 "2020-04-10T19:58:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwohlin](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/mwohlin/32/5939_2.png) [@mwohlin](https://discuss.hashicorp.com/u/mwohlin)\
**Post date:** [April 10, 2020, 7:58pm UTC](https://discuss.hashicorp.com/t/google-monitoring-uptime-check-monitored-resource-labels/7572/1 "2020-04-10T19:58:36Z")

</div>

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:

```auto
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.

```auto
  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:

```auto
  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!

---

<div class="post-metadata">

**Author:** ![mwohlin](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/mwohlin/32/5939_2.png) [@mwohlin](https://discuss.hashicorp.com/u/mwohlin)\
**Post date:** [April 11, 2020, 4:09am UTC](https://discuss.hashicorp.com/t/google-monitoring-uptime-check-monitored-resource-labels/7572/2 "2020-04-11T04:09:50Z")

</div>

Update: I did some more reading about inline blocks and I tried this logic.

```auto
  monitored_resource {
    type = var.type

    dynamic "labels" {
      for_each = var.resource_type_labels
      content {
        labels.key = labels.value
      }
    }
  }

```

But when I run terraform apply I get this error.

```auto
$ terraform apply --var-file monitoring-uptime-check.tfvars

Error: Argument or block definition required

  on monitoring-uptime-check-https.tf line 33, in resource "google_monitoring_uptime_check_config" "uptime_check":
  33: labels.key = labels.value

An argument or block definition is required here. To set an argument, use the
equals sign "=" to introduce the argument value.

```

---

<div class="post-metadata">

**Author:** ![mwohlin](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/mwohlin/32/5939_2.png) [@mwohlin](https://discuss.hashicorp.com/u/mwohlin)\
**Post date:** [April 15, 2020, 11:46pm UTC](https://discuss.hashicorp.com/t/google-monitoring-uptime-check-monitored-resource-labels/7572/3 "2020-04-15T23:46:45Z")

</div>

Does anyone have any idea on this one?  
I really need to know how to create the inline block, with a variable amount of attributes, such as this (labels):

```auto
  monitored_resource {
    type = "uptime_url"
    labels = {
      project_id = "my-project-name"
      host = "192.168.1.1"
    }
  }

```

---

<div class="post-metadata">

**Author:** ![mwohlin](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/mwohlin/32/5939_2.png) [@mwohlin](https://discuss.hashicorp.com/u/mwohlin)\
**Post date:** [April 28, 2020, 5:35pm UTC](https://discuss.hashicorp.com/t/google-monitoring-uptime-check-monitored-resource-labels/7572/4 "2020-04-28T17:35:22Z")

</div>

This issue is closed.  
The solution can be found here…

> [@Dynamic inline blocks](https://discuss.hashicorp.com/t/dynamic-inline-blocks/8106/2):
>
> Hi @mwohlin, Because of the equals sign after labels it seems like this is an argument expecting a map value, rather than a nested block. That means we can use any Terraform expression to construct a suitable map value to pass to it. One way to get this done would be to build a local data structure that describes all of the possible shapes and then select the one that’s appropriate for the current var.type, like this: locals { monitored\_resource\_labels = { uptime\_url = { project\_i…
