Skip to content

Instantly share code, notes, and snippets.

@kzap
Last active August 8, 2019 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kzap/14fc4c9428564dbcff16034219d9fae1 to your computer and use it in GitHub Desktop.
Save kzap/14fc4c9428564dbcff16034219d9fae1 to your computer and use it in GitHub Desktop.
Terraform: How to pass map to module
variable "region" {
default = "tr2"
description = "The region of openstack, for image/flavor/network lookups."
}
variable "image" {
default = {
tr2 = "eee08821-c95a-448f-9292-73908c794661"
tr2-1 = ""
RegionOne = "WRONG VALUE"
}
}
output "image_id" {
value = "${lookup(var.image, var.region)}"
}
module "test" {
source = "./module"
region = "${var.region}"
image = "${var.image}"
}
variable "region" {
default = "RegionOne"
description = "The region of openstack, for image/flavor/network lookups."
}
variable "image" {
default = {
RegionOne = "CORRECT VALUE"
RegionOne-1 = ""
}
}
resource "template_file" "example" {
template = "${region}: ${image_id} ${image}"
vars {
region = "${var.region}"
image_id = "${module.test.image_id}"
image = "${var.image}"
}
}
output "rendered" {
value = "${template_file.example.rendered}"
}
@k7faq
Copy link

k7faq commented Aug 8, 2019

Is this not more "how to pass a variable" rather than a "map"? Please do help me understand my confusion.

@kzap
Copy link
Author

kzap commented Aug 8, 2019

Hi @k7faq, when I made this in 2016 it seemed it was not possible to send your own MAP to override a MAP used in a module, only string interpolation was possible.

This was trying to send

{
         RegionOne = "CORRECT VALUE"
         RegionOne-1 = ""
    }

This may have changed by now in Terraform 0.12 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment