{"id":19853864,"url":"https://github.com/magnetikonline/terraform-github-action-cache-example","last_synced_at":"2025-07-12T20:35:25.126Z","repository":{"id":37922179,"uuid":"369798662","full_name":"magnetikonline/terraform-github-action-cache-example","owner":"magnetikonline","description":"Caching Terraform providers within a GitHub Actions Workflow run to improve execution times.","archived":false,"fork":false,"pushed_at":"2024-03-22T01:18:54.000Z","size":15,"stargazers_count":52,"open_issues_count":0,"forks_count":6,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-06T20:24:50.699Z","etag":null,"topics":["caching","github-workflow","terraform"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/magnetikonline.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-05-22T12:09:05.000Z","updated_at":"2025-03-15T14:03:23.000Z","dependencies_parsed_at":"2024-03-08T00:21:00.678Z","dependency_job_id":"f82c1ed3-16be-459d-a9ca-b6ee3acdfa1a","html_url":"https://github.com/magnetikonline/terraform-github-action-cache-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magnetikonline%2Fterraform-github-action-cache-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magnetikonline%2Fterraform-github-action-cache-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magnetikonline%2Fterraform-github-action-cache-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magnetikonline%2Fterraform-github-action-cache-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/magnetikonline","download_url":"https://codeload.github.com/magnetikonline/terraform-github-action-cache-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251969230,"owners_count":21673180,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["caching","github-workflow","terraform"],"created_at":"2024-11-12T14:07:53.126Z","updated_at":"2025-05-02T01:30:23.560Z","avatar_url":"https://github.com/magnetikonline.png","language":"HCL","readme":"# Terraform GitHub Actions caching example\n\n[![Terraform provider cache example](https://github.com/magnetikonline/terraform-github-action-cache-example/actions/workflows/example.yaml/badge.svg)](https://github.com/magnetikonline/terraform-github-action-cache-example/actions/workflows/example.yaml)\n\n## Summary\n\nAn implementation of caching [Terraform providers](https://developer.hashicorp.com/terraform/language/providers) via [`actions/cache`](https://github.com/actions/cache) within a workflow run in an attempt to improve `terraform init|plan|apply` execution times.\n\nWhy?\n\n- Providers are external to Terraform itself and require download during `terraform init` operations.\n- Common use providers can often be very large in size. For example, the [AWS Provider](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) at time of writing weighs in around `360MB` uncompressed.\n- By caching these provider binaries between GitHub Action runs, we hope to have required configuration providers available to `terraform` sooner!\n\n## Example\n\nSee: [`.github/workflows/example.yaml`](.github/workflows/example.yaml)\n\nBreakdown of the key workflow steps:\n\n- Git source is fetched and Terraform setup via [`actions/checkout`](https://github.com/actions/checkout) and [`hashicorp/setup-terraform`](https://github.com/hashicorp/setup-terraform) respectively.\n- Terraform plugin (provider) cache path is configured:\n\t- By default Terraform downloads providers to individual `.terraform/` directories alongside a configuration. By enabling a system wide cache, `terraform` downloads each provider _once_ to a central location and symlink back into each `.terraform/` directory - avoiding repeated downloads. [More details here](https://developer.hashicorp.com/terraform/cli/config/config-file#provider-plugin-cache).\n\t- The plugin cache path is set via the [`TF_PLUGIN_CACHE_DIR`](https://developer.hashicorp.com/terraform/cli/config/environment-variables#tf_plugin_cache_dir) environment variable.\n\t- With a global plugin cache location enabled, we've now got the perfect candidate for workflow run caching.\n- Finally, [`actions/cache`](https://github.com/actions/cache) is setup to save/restore the plugin cache location we've set at `~/.terraform.d/plugin-cache`. The cache key is composed using a hash of dependency lock files (`.terraform.lock.hcl`), introduced in [Terraform 0.14](https://developer.hashicorp.com/terraform/language/files/dependency-lock).\n\n\tConfiguration lock file can be created/updated via the following:\n\n\t```sh\n\t$ terraform providers lock -platform=darwin_amd64 -platform=darwin_arm64 -platform=linux_amd64\n\t```\n\n- Finally a `terraform init` is run, which sets up a trivial Terraform configuration of [`main.tf`](main.tf).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagnetikonline%2Fterraform-github-action-cache-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmagnetikonline%2Fterraform-github-action-cache-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagnetikonline%2Fterraform-github-action-cache-example/lists"}