Skip to content

Commit f774142

Browse files
authored
Merge pull request #20 from wayofdev/develop
feat: added cache folders and variables
2 parents 3ffdb68 + d8de2c6 commit f774142

File tree

7 files changed

+148
-11
lines changed

7 files changed

+148
-11
lines changed

gh-action-terragrunt-apply/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,46 @@ These input values must be the same as any wayofdev/gh-action-terragrunt-plan fo
8989
- Optional
9090
- Default: parallel
9191

92+
* `create_cache_folder_in_workspace`
93+
94+
Set to true to create a cache folder in workspace. It can be reused in other steps, jobs and workflows. By default it created in /tmp folder inside docker container and not available outside.
95+
96+
- Type: boolean
97+
- Optional
98+
- Default: false
99+
100+
* `cache_folder`
101+
102+
Specify custom name for the cache folder which will be created in github workspace. Two additional folders will be created inside `cache_folder`: `tf_plugin_cache_folder` and `tg_cache_folder`
103+
104+
- Type: string
105+
- Optional
106+
- Default: .terragrunt-cache
107+
108+
* `use_tf_plugin_cache_folder`
109+
110+
If set to `true`, the varibale TF_PLUGIN_CACHE_DIR will be enabled. Sometimes there can be problems when using these variable in Terragrunt
111+
112+
- Type: boolean
113+
- Optional
114+
- Default: false
115+
116+
* `tf_plugin_cache_folder`
117+
118+
Specify custom name for the tf_plugin_cache_folder folder which will be created inside `cache_folder`. Variable TF_PLUGIN_CACHE_DIR will be set to `${GITHUB_WORKSPACE}/${cache_folder}/${tf_plugin_cache_folder}`. Only applicable if `use_tf_plugin_cache_folder` is set to true
119+
120+
- Type: string
121+
- Optional
122+
- Default: tf-plugin-cache
123+
124+
* `tg_cache_folder`
125+
126+
Specify custom name for the tg_cache_folder folder which will be created inside `cache_folder`. Terragrunt commands will be executed with option `--terragrunt-download-dir ${GITHUB_WORKSPACE}/${cache_folder}/${tg_cache_folder}`
127+
128+
- Type: string
129+
- Optional
130+
- Default: tg-cache
131+
92132
## Environment Variables
93133

94134
* `GITHUB_TOKEN`

gh-action-terragrunt-apply/action.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,26 @@ inputs:
3535
description: "What strategy to use when applying: parallel or sequential"
3636
required: false
3737
default: "parallel"
38+
create_cache_folder_in_workspace:
39+
description: "Create a cache folder in the workspace"
40+
required: false
41+
default: "false"
42+
cache_folder:
43+
description: "Cache folder name"
44+
required: false
45+
default: ".terragrunt-cache"
46+
use_tf_plugin_cache_folder:
47+
description: "If set to true, the variable TF_PLUGIN_CACHE_DIR will be enabled"
48+
required: false
49+
default: "false"
50+
tf_plugin_cache_folder:
51+
description: "Cache folder name for Terraform plugins. Only applicable if use_tf_plugin_cache_folder is set to true"
52+
required: false
53+
default: "tf-plugin-cache"
54+
tg_cache_folder:
55+
description: "Cache folder name for Terragrunt"
56+
required: false
57+
default: "tg-cache"
3858

3959
runs:
4060
using: docker

gh-action-terragrunt-plan/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,46 @@ Don't use terragrunt_download setting in your terragrunt code and also don't cle
7676
- Optional
7777
- Default: false
7878

79+
* `create_cache_folder_in_workspace`
80+
81+
Set to true to create a cache folder in workspace. It can be reused in other steps, jobs and workflows. By default it created in /tmp folder inside docker container and not available outside.
82+
83+
- Type: boolean
84+
- Optional
85+
- Default: false
86+
87+
* `cache_folder`
88+
89+
Specify custom name for the cache folder which will be created in github workspace. Two additional folders will be created inside `cache_folder`: `tf_plugin_cache_folder` and `tg_cache_folder`
90+
91+
- Type: string
92+
- Optional
93+
- Default: .terragrunt-cache
94+
95+
* `use_tf_plugin_cache_folder`
96+
97+
If set to `true`, the varibale TF_PLUGIN_CACHE_DIR will be enabled. Sometimes there can be problems when using these variable in Terragrunt
98+
99+
- Type: boolean
100+
- Optional
101+
- Default: false
102+
103+
* `tf_plugin_cache_folder`
104+
105+
Specify custom name for the tf_plugin_cache_folder folder which will be created inside `cache_folder`. Variable TF_PLUGIN_CACHE_DIR will be set to `${GITHUB_WORKSPACE}/${cache_folder}/${tf_plugin_cache_folder}`. Only applicable if `use_tf_plugin_cache_folder` is set to true
106+
107+
- Type: string
108+
- Optional
109+
- Default: tf-plugin-cache
110+
111+
* `tg_cache_folder`
112+
113+
Specify custom name for the tg_cache_folder folder which will be created inside `cache_folder`. Terragrunt commands will be executed with option `--terragrunt-download-dir ${GITHUB_WORKSPACE}/${cache_folder}/${tg_cache_folder}`
114+
115+
- Type: string
116+
- Optional
117+
- Default: tg-cache
118+
79119
## Environment Variables
80120

81121
* `GITHUB_TOKEN`

gh-action-terragrunt-plan/action.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@ inputs:
3131
description: Create a plan to destroy all resources
3232
required: false
3333
default: "false"
34+
create_cache_folder_in_workspace:
35+
description: "Create a cache folder in the workspace"
36+
required: false
37+
default: "false"
38+
cache_folder:
39+
description: "Cache folder name"
40+
required: false
41+
default: ".terragrunt-cache"
42+
use_tf_plugin_cache_folder:
43+
description: "If set to true, the variable TF_PLUGIN_CACHE_DIR will be enabled"
44+
required: false
45+
default: "false"
46+
tf_plugin_cache_folder:
47+
description: "Cache folder name for Terraform plugins. Only applicable if use_tf_plugin_cache_folder is set to true"
48+
required: false
49+
default: "tf-plugin-cache"
50+
tg_cache_folder:
51+
description: "Cache folder name for Terragrunt"
52+
required: false
53+
default: "tg-cache"
3454

3555
runs:
3656
using: docker

image/actions.sh

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ function set_common_plan_args() {
7575
fi
7676
fi
7777
export PLAN_ARGS
78+
export PARALLEL_ARG
7879
}
7980

8081
function plan() {
@@ -198,6 +199,10 @@ function fix_owners() {
198199
chown -R --reference "$GITHUB_WORKSPACE" "$GITHUB_WORKSPACE/.gh-actions-terragrunt" || true
199200
debug_cmd ls -la "$GITHUB_WORKSPACE/.gh-actions-terragrunt"
200201
fi
202+
if [[ -d "$GITHUB_WORKSPACE/$INPUT_CACHE_FOLDER" ]]; then
203+
chown -R --reference "$GITHUB_WORKSPACE" "$GITHUB_WORKSPACE/$INPUT_CACHE_FOLDER" || true
204+
debug_cmd ls -la "$GITHUB_WORKSPACE/$INPUT_CACHE_FOLDER"
205+
fi
201206

202207
debug_cmd ls -la "$HOME"
203208
if [[ -d "$HOME/.gh-actions-terragrunt" ]]; then
@@ -214,10 +219,25 @@ function fix_owners() {
214219
fi
215220
}
216221

217-
# Every file written to disk should use one of these directories
222+
export TF_IN_AUTOMATION=true
223+
224+
if [[ "$INPUT_CREATE_CACHE_FOLDER_IN_WORKSPACE" == "true" ]]; then
225+
CACHE_PATH=${GITHUB_WORKSPACE}
226+
else
227+
CACHE_PATH="/tmp"
228+
fi
229+
230+
if [[ "$INPUT_USE_TF_PLUGIN_CACHE_FOLDER" == "true" ]]; then
231+
TF_PLUGIN_CACHE_DIR="${CACHE_PATH}/${INPUT_CACHE_FOLDER}/${INPUT_TF_PLUGIN_CACHE_FOLDER}"
232+
mkdir -p $TF_PLUGIN_CACHE_DIR
233+
readonly TF_PLUGIN_CACHE_DIR
234+
export TF_PLUGIN_CACHE_DIR
235+
fi
236+
218237
STEP_TMP_DIR="/tmp"
219238
PLAN_OUT_DIR="/tmp/plan"
220-
TG_CACHE_DIR="/tmp/tg_cache_dir"
239+
TG_CACHE_DIR="${CACHE_PATH}/${INPUT_CACHE_FOLDER}/${INPUT_TG_CACHE_FOLDER}"
240+
221241
JOB_TMP_DIR="$HOME/.gh-actions-terragrunt"
222242
WORKSPACE_TMP_DIR=".gh-actions-terragrunt/$(random_string)"
223243
mkdir -p $PLAN_OUT_DIR $TG_CACHE_DIR

image/src/github_actions/inputs.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
class InitInputs(TypedDict):
1111
"""Common input variables for actions the need to initialize terraform"""
1212
INPUT_PATH: str
13-
INPUT_WORKSPACE: str
1413
INPUT_BACKEND_CONFIG: str
1514
INPUT_BACKEND_CONFIG_FILE: str
15+
INPUT_CREATE_CACHE_FOLDER_IN_WORKSPACE: str
16+
INPUT_CACHE_FOLDER: str
17+
INPUT_USE_TF_PLUGIN_CACHE_FOLDER: str
18+
INPUT_TF_PLUGIN_CACHE_FOLDER: str
19+
INPUT_TG_CACHE_FOLDER: str
1620

1721

1822
class PlanInputs(InitInputs):

image/src/github_pr_comment/__main__.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import hashlib
22
import os
3-
import subprocess
43
import re
54
import sys
65
from pathlib import Path
@@ -15,14 +14,8 @@
1514
from github_actions.env import GithubEnv
1615
from github_actions.find_pr import find_pr, WorkflowException
1716
from github_actions.inputs import PlanPrInputs
18-
from github_pr_comment.backend_config import complete_config, partial_config
19-
from github_pr_comment.backend_fingerprint import fingerprint
20-
from github_pr_comment.cmp import plan_cmp, remove_warnings, remove_unchanged_attributes
2117
from github_pr_comment.comment import find_comment, TerraformComment, update_comment, serialize, deserialize
22-
from github_pr_comment.hash import comment_hash, plan_hash
23-
from plan_renderer.variables import render_argument_list, Sensitive
24-
from terraform.module import load_module, get_sensitive_variables
25-
from terraform import hcl
18+
from github_pr_comment.hash import plan_hash
2619

2720
Plan = NewType('Plan', str)
2821
Status = NewType('Status', str)

0 commit comments

Comments
 (0)