Last active
April 26, 2018 19:54
-
-
Save fprimex/016b502438f2fa9fa66d05d6288eeb09 to your computer and use it in GitHub Desktop.
yo dawg
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
example config block { | |
foo = bar | |
${tpl2} | |
} |
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
baz = qux |
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 "add_tpl2" { | |
default = "1" | |
} | |
data "template_file" "tpl1" { | |
template = "${file("${path.module}/1.tpl")}" | |
vars { | |
tpl2 = "${var.add_tpl2 ? data.template_file.tpl2.rendered : ""}" | |
} | |
} | |
data "template_file" "tpl2" { | |
template = "${file("${path.module}/2.tpl")}" | |
} | |
resource "null_resource" "n" { | |
triggers { | |
uuid = "${uuid()}" | |
} | |
provisioner "local-exec" { | |
command = "echo \"${data.template_file.tpl1.rendered}\"" | |
} | |
} | |
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
# | |
# Don't include template 2 | |
# | |
$ terraform apply | |
data.template_file.tpl2: Refreshing state... | |
data.template_file.tpl1: Refreshing state... | |
Terraform will perform the following actions: | |
+ null_resource.n | |
id: <computed> | |
triggers.%: "1" | |
triggers.uuid: "0bb22aed-2f9b-e939-4cd3-2d04b0e5c252" | |
null_resource.n: Creating... | |
null_resource.n (local-exec): Executing: ["/bin/sh" "-c" "echo \"example config block {\n foo = bar\n \n}\n\""] | |
null_resource.n (local-exec): example config block { | |
null_resource.n (local-exec): foo = bar | |
null_resource.n (local-exec): } | |
null_resource.n: Creation complete after 0s (ID: 9171632323409189307) | |
Apply complete! Resources: 1 added, 0 changed, 0 destroyed. | |
# | |
# Include template 2 | |
# | |
$ terraform apply | |
data.template_file.tpl2: Refreshing state... | |
data.template_file.tpl1: Refreshing state... | |
null_resource.n: Refreshing state... (ID: 9171632323409189307) | |
Terraform will perform the following actions: | |
-/+ null_resource.n (new resource required) | |
id: "9171632323409189307" => <computed> (forces new resource) | |
triggers.%: "1" => "1" | |
triggers.uuid: "902927f8-0a25-bcac-43b7-ab19ba741440" => "4568668e-8bf5-b8ca-bb7c-939238c69f52" (forces new resource) | |
null_resource.n: Creating... | |
null_resource.n: Provisioning with 'local-exec'... | |
null_resource.n (local-exec): Executing: ["/bin/sh" "-c" "echo \"example config block {\n foo = bar\n baz = qux\n\n}\n\""] | |
null_resource.n (local-exec): example config block { | |
null_resource.n (local-exec): foo = bar | |
null_resource.n (local-exec): baz = qux | |
null_resource.n (local-exec): } | |
null_resource.n: Creation complete after 0s (ID: 6202997425923817641) | |
Apply complete! Resources: 1 added, 0 changed, 1 destroyed. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment