hashicorp / hashicorp/setup-terraform
Enabling Plugin Cache Directory
- Dominant language
- JavaScript
- Stars
- 1.6k
- Forks
- 288
- Avg merge
- 23h 21m
- Merged PRs (30d)
- 3
Description
## Description
We have a use case that requires running Terraform in a GitHub Action across multiple, separate configurations in the same repository. Since Terraform prefers to maintain its own plugin directory per directory, this leads to re-downloading (mostly the same) plugins for each separate directory. It would be great if there was the option to enable the [plugin cache directory](https://www.terraform.io/docs/configuration/providers.html#provider-plugin-cache), which can be handled in the Terraform CLI configuration file via the `plugin_cache_dir` option, e.g. from the documentation:
```
plugin_cache_dir = "$HOME/.terraform.d/plugin-cache"
```
Seems like it could be either a boolean where the GitHub Action maintains the directory location itself (`enable_plugin_cache_dir: true`) or allow configurations to provide it directly (`plugin_cache_dir: /wherever/whenever`), which might be useful for managed runners at the expense of being more complex. It seems like in either case, the GitHub Action would should try to create the directory, skipping errors for existing ones, as its prior existence is required.
## Potential Workarounds
```yaml
env:
TF_PLUGIN_CACHE_DIR: ${{ github.workspace }}/.terraform.d/plugin-cache
jobs:
terraform:
runs-on: ubuntu-latest
steps:
# alternatively: run: mkdir -p $TF_PLUGIN_CACHE_DIR
- uses: actions/cache@v1
with:
key: ${{ runner.os }}-terraform-plugin-cache
path: ${{ env.TF_PLUGIN_CACHE_DIR }}
- uses: actions/checkout@v2
- uses: hashicorp/setup-terraform@v1
- name: terraform
run: |
for DIR in $(find ./examples -type d); do
pushd $DIR
terraform init
terraform fmt -check
terraform validate
popd
done
```
## References
- https://github.com/terraform-providers/terraform-provider-aws/issues/12861
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.