It seems to me like you're over-complicating things. What, exactly, are you trying to achieve? With all things Terraform it's usually better to ask how can I achieve so and so?
than how can I get my Terraform code to work?
.
Is the following what you're after?
data "external" "hello" {
program = ["bash", "-c", "echo 'Hello World!' > helloworld.txt; echo -n '{"hello":"world!"}'"]
}
resource "null_resource" "world" {
provisioner "local-exec" {
command = "echo '${data.external.hello.result["hello"]}'"
}
}
As you can see from the timestamps in the following output, helloworld.txt
is being generated five times, once every time Terraform
plan is invoked:
jdsalaro$ for i in {1..5} ;do terraform plan; ls -lah --full-time helloworld.txt ;done
| grep helloworld.txt | cut -d ' ' -f 7,9
00:04:18.610304219 helloworld.txt
00:04:19.902246088 helloworld.txt
00:04:21.226186506 helloworld.txt
00:04:22.574125835 helloworld.txt
00:04:23.886066774 helloworld.txt
I uploaded the whole example here just in case.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…