Created
September 26, 2018 17:36
-
-
Save stepanstipl/9d4af39797bcacdc4ed236af24999835 to your computer and use it in GitHub Desktop.
TF test
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
$ terraform apply (:|✔) 0 | |
Apply complete! Resources: 0 added, 0 changed, 0 destroyed. | |
Outputs: | |
test = { | |
ex1 = I want the project id to be here: my-project | |
ex2 = And one more time: my-project | |
} | |
$ $terraform apply -var 'exclusions={ ex1 = "foo", ex2 = "bar" }' (:|✔) 0 | |
Apply complete! Resources: 0 added, 0 changed, 0 destroyed. | |
Outputs: | |
test = { | |
ex1 = foo | |
ex2 = bar | |
} |
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 "project_id" { | |
default = "my-project" | |
} | |
variable "exclusions" { | |
type = "map" | |
default = {} | |
} | |
locals { | |
default_exclusions = { | |
"ex1" = "I want the project id to be here: ${var.project_id}", | |
"ex2" = "And one more time: ${var.project_id}" | |
} | |
# This is ugly, because TF does not allow to have maps in conditinalsn (Why? :() | |
exclusions_keys = "${length(keys(var.exclusions)) != 0 ? join(",", keys(var.exclusions)) : join(",", keys(local.default_exclusions))}" | |
exclusions_values = "${length(keys(var.exclusions)) != 0 ? join(",", values(var.exclusions)) : join(",", values(local.default_exclusions))}" | |
exclusions = "${zipmap(split(",", local.exclusions_keys), split(",", local.exclusions_values))}" | |
} | |
output "test" { | |
value = "${local.exclusions}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment