Arbitrary number of dynamic keys/values in terraform module

Viewed 15

I have a tf module that creates GCP managed instances group. Part of this module is an intance template that defines environment variables:

resource "google_compute_instance_template" "main" {
  ...
  metadata = {
    ...
    api-key = "secret value"
  }
  ...
}

When using this module I want to specify an arbitrary key/value pairs to be passed into the metadata block:

module "my_first_app" {
  ...
  source = "./my_module",
  metadata = {
    my-key: 'abc',
    another-key: 'def'
  }
}
module "my_second_app" {
  ...
  source = "./my_module",
  metadata = {
    different-key: 'ert'
  }
}

How do I implement something like that?

0 Answers
Related