Terraform: Feature request - null_resource + local_exec + get output as variable

Created on 11 Aug 2016  ยท  5Comments  ยท  Source: hashicorp/terraform

See some discussion here: #6830

The basic idea is to have a way (possibly, a "data source") that can execute a local provisioner command and receive the output (stdout, stderr) as a variable that can be referenced by downstream dependencies in the DAG.

I have tried to work around this by redirecting a null_resource's local_exec output to file. We then reference this file using the file(..) interpolation syntax.

However, in our system we don't want to check this (transient) file into source control as all our remote state is externalized (via the S3 feature). This means that the first time terraform plan is executed, the transient file does not exist and in turn, terraform fails to plan.

It's a similar case for destroy - if the file doesn't exist then destroy fails.

I think using variables/dynamically wiring the graph would be better than hackery with files, but as said, I don't think this is supported yet.

Most helpful comment

External data sources get run every time - if you just want to get output once, I made a module for this https://github.com/matti/terraform-shell-resource

All 5 comments

Sorry I didn't spot this issue before I started writing my own... I have a proposal over in #8144 that I think speaks to what you're describing here, though perhaps in a more elaborate way than what you were proposing.

@apparentlymart Your proposal is indeed great! Would work for all our use cases and I agree it's much more elegant than local_exec (which is definitely a workaround for missing higher-level abstractions). Love it!

External data sources get run every time - if you just want to get output once, I made a module for this https://github.com/matti/terraform-shell-resource

https://github.com/matti/terraform-shell-resource has been updated so that it updates the outputs if command changes and does not run on every apply

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shanmugakarna picture shanmugakarna  ยท  3Comments

rnowosielski picture rnowosielski  ยท  3Comments

rkulagowski picture rkulagowski  ยท  3Comments

pawelsawicz picture pawelsawicz  ยท  3Comments

ketzacoatl picture ketzacoatl  ยท  3Comments