TF_PLUGIN_CACHE_DIR is not present in custom steps
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Searching for pre-existing feature requests helps us consolidate datapoints for identical requirements into a single place, thank you!
- Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
- If you are interested in working on this issue or have submitted a pull request, please leave a comment.
Overview of the Issue
Not sure if this is intended or not, but it seems that most environment variables are propagated from the caller (atlantis) to the callee (custom step), except TF_PLUGIN_CACHE_DIR because this variable is never in the environ.
If this is indeed not intended, I am happy to "fix" it. Otherwise it would be nice to add some note in the documentation.
Reproduction Steps
Don't disable the plugin cache (default behavior). Override the init step with a custom run:
- run: terraform$ATLANTIS_TERRAFORM_VERSION init -input=false
TF_PLUGIN_CACHE_DIR is not in the process's environ. :((
Hello @leonnicolas! I'm Dosu, here to help you tackle bugs, answer questions, and support your journey as a contributor. I'm standing by while you wait for a human maintainer!
The TF_PLUGIN_CACHE_DIR environment variable is indeed propagated to custom steps when the plugin cache is enabled. This is confirmed by the test case in the Atlantis codebase, where TF_PLUGIN_CACHE_DIR is set to a temporary directory and expected to be part of the output [1]. Additionally, the DefaultClient struct includes a field usePluginCache that determines whether TF_PLUGIN_CACHE_DIR is set, further confirming its propagation when enabled [2].
If TF_PLUGIN_CACHE_DIR is not appearing in your custom steps, it might be worth checking if the plugin cache is enabled in your configuration. If you find that it is enabled and the variable is still not present, there might be an issue with how the environment is being set up for custom steps.
To continue talking to Dosu, mention @dosu.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other
Hi Dosu, you are right, that the DefaultClient propagates the TF_PLUGIN_CACHE_DIR. However when using a custom step, the atlantis TerraformExec is not used and its RunCommandWithVersion does the injection of the TF_PLUGIN_CACHE_DIR.
I mean the fix is easy by providing an extra EnvStepRunner, to manually inject the TF_PLUGIN_CACHE_DIR variable. I just think it is not very intuitive that almost all environment variables are propagated expect the TF_PLUGIN_CACHE_DIR and I had to go through the code base to understand what is going on.
EDIT @dosu
@leonnicolas If you are writing a custom workflow, why aren't you just setting the TF_PLUGIN_CACHE_DIR environment variable?
I mean the fix is easy by providing an extra EnvStepRunner
I solved it in a similar way. I opened the issue not because it is not possible, but either
- the documentation should be more clear on the fact that the plugin-cache flag (atlantis config) is only used for default steps or
- that this flag should also be injected into the custom steps. I mean a bunch of variables are provided, but not the
TF_PLUGIN_CACHE.