Last active
August 28, 2019 00:48
-
-
Save sl1pm4t/d9ca17fda47c3fe266d07d3afd49799b to your computer and use it in GitHub Desktop.
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 "env" { | |
default = ["dev", "test", "stage", "prod"] | |
} | |
locals { | |
env = toset(var.env) | |
} | |
resource "template_file" "list_toset" { | |
for_each = local.env | |
template = "key = $${key}, value = $${value}" | |
vars = { | |
key = each.key | |
value = each.value | |
} | |
} | |
resource "local_file" "list_toset" { | |
for_each = template_file.list_toset | |
filename = "list_toset-${each.value.vars.value}-${each.key}" | |
content = <<EOF | |
each.key = ${jsonencode(each.key)} | |
each.value = ${jsonencode(each.value)} | |
EOF | |
} | |
############### | |
variable "envmap" { | |
default = { | |
dev = "dev" | |
test = "test" | |
stage = "stage" | |
prod = "prod" | |
} | |
} | |
resource "template_file" "mapped" { | |
for_each = local.env | |
template = "key = $${key}, value = $${value}" | |
vars = { | |
key = each.key | |
value = each.value | |
} | |
} | |
resource "local_file" "mapped" { | |
for_each = template_file.mapped | |
filename = "mapped-${each.value.vars.value}-${each.key}" | |
content = <<EOF | |
each.key = ${jsonencode(each.key)} | |
each.value = ${jsonencode(each.value)} | |
EOF | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment