Skip to content

TF_PLUGIN_CACHE_DIR is not present in custom steps #5583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
leonnicolas opened this issue May 15, 2025 · 4 comments
Open

TF_PLUGIN_CACHE_DIR is not present in custom steps #5583

leonnicolas opened this issue May 15, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@leonnicolas
Copy link

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. :((

@leonnicolas leonnicolas added the bug Something isn't working label May 15, 2025
Copy link

dosubot bot commented May 15, 2025

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

@leonnicolas
Copy link
Author

leonnicolas commented May 15, 2025

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

@grimm26
Copy link
Contributor

grimm26 commented May 15, 2025

@leonnicolas If you are writing a custom workflow, why aren't you just setting the TF_PLUGIN_CACHE_DIR environment variable?

@leonnicolas
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants