Last active
August 8, 2019 21:31
-
-
Save kzap/14fc4c9428564dbcff16034219d9fae1 to your computer and use it in GitHub Desktop.
Terraform: How to pass map to module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)}" | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" | |
} |
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
Is this not more "how to pass a variable" rather than a "map"? Please do help me understand my confusion.