Skip to content

Instantly share code, notes, and snippets.

@ptdorf
Forked from arnobroekhof/example_local_file.tf
Created November 2, 2019 20:28
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 ptdorf/de7bdcff0a2c986e8bc2522df8a9d93b to your computer and use it in GitHub Desktop.
Save ptdorf/de7bdcff0a2c986e8bc2522df8a9d93b to your computer and use it in GitHub Desktop.
Terraform 0.11.x loop through a map and create files with content based on a maps --> key, value
variable "object_list" {
type = "map"
default = {
content1 = "this is example content 1",
content2 = "this is example content 2"
}
}
resource "local_file" "local_files" {
count = "${length(var.object_list)}" # perform this action based on the amount of items in the map
filename = "${element(keys(var.object_list), count.index)}" # lookup the key name based on the current count index.
content = "${lookup(var.object_list, "${element(keys(var.object_list), count.index)}")}" # lookup the key's value based on a double interpolation.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment