Skip to content

Commit 829d3f8

Browse files
authored
document caching strategies in digger (#2098)
* document caching strategies in digger
1 parent ad03d4d commit 829d3f8

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

docs/ce/howto/caching-strategies.mdx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: "Caching providers"
3+
---
4+
5+
In order to speed up your terraform runs it is great to cache providers so that each workflow run does not have to download the provider again. Digger provides
6+
an easy way to cache providers with a single argument as follows:
7+
8+
```
9+
- uses: diggerhq/digger@vLatest
10+
with:
11+
cache-dependencies: true
12+
```
13+
14+
This will do the following:
15+
16+
- When each job starts: it will attempt to restore cache from the github cache
17+
- After terraform runs it will download all the necessary providers into a cache directory
18+
- Once it is done it will store the cache back into github cache -- using the hash of the directory appended to the key
19+
20+
The hashing of directories ensures that the cache is only saved if the contents of the directory has changed. Note that github
21+
cache is immutable so new caches will be new entries in the cache. Digger currently does not prune older caches so you may need
22+
to clean up older caches using a certain cycle.
23+
24+
## Self-hosted runners and volumes caching
25+
26+
If you are using self-hosted runners with github it might be overkill on your bandwidth to load and restore from cache. In this case it might be better to mount
27+
a common volume for all the runners to read and write to. Digger provides an argument to control the location for the terraform (or terragrunt) provider cache directory:
28+
29+
```
30+
- uses: diggerhq/digger@vLatest
31+
with:
32+
terraform-cache-dir: /home/myuser/mnt/terraform-cache
33+
```
34+
35+
Where this path points to the location of a mounted volume that all the runners can read and write to. With this configuration in place, all runners will update the provider cache in place
36+
which means there is no need to re-download providers or upload them back to github cache each time.
37+
38+
<Note>
39+
We are currently looking into cases where there might be conflicts between [different runners](https://terragrunt.gruntwork.io/docs/features/provider-cache-server/#why-opentofuterraforms-built-in-provider-caching-doesnt-work)
40+
writing to the same cache directory. It seems that recent versions of opentofu and terraform have improved their cache handling to avoid this issue. But it is an area we hope to document better for digger in the near future.
41+
</Note>

docs/mint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"pages": [
8383
"ce/howto/managing-state",
8484
"ce/howto/specify-terraform-version",
85+
"ce/howto/caching-strategies",
8586
"ce/howto/apply-on-merge",
8687
"ce/howto/apply-requirements",
8788
"ce/howto/auto-merge",

0 commit comments

Comments
 (0)