-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathaction.yml
More file actions
244 lines (224 loc) · 8.83 KB
/
action.yml
File metadata and controls
244 lines (224 loc) · 8.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
name: Pipelines Execute
description: Run Pipelines Execute
inputs:
working_directory:
description: "The folder path to run Pipelines Execute in"
required: true
with_ssh_enabled:
description: "Run the build with tmate ssh enabled (https://github.com/marketplace/actions/debugging-with-tmate)"
required: false
terragrunt_command:
description: "The terragrunt command to run"
required: true
default: "plan"
token:
description: "The GitHub token for downloading the Gruntwork Pipelines binary and modules"
required: true
# The following are required to generate a .mise.toml file
generate_mise_toml:
description: "Explicitly force generation of a .mise.toml file for the action"
required: false
default: "false"
tg_version:
description: "Terragrunt version to install. Ignored if generate_mise_toml is false and user has a .mise.toml."
required: false
default: "0.48.1"
tf_version:
description: "OpenTofu or Terraform version to install. Ignored if generate_mise_toml is false and user has a .mise.toml."
required: false
default: "1.6.1"
tf_binary:
description: "Whether to use opentofu or terraform as the binary."
required: false
default: "opentofu"
# These are the valid options, but not enforced by the action
# options:
# - terraform
# - opentofu
# The following are required to run the Pipelines CLI
tg_execution_parallelism_limit:
# https://terragrunt.gruntwork.io/docs/features/execute-terraform-commands-on-multiple-modules-at-once/#limiting-the-module-execution-parallelism
description: "Maximum number of concurrently executed Terraform modules during Terragrunt execution"
required: false
default: "0" # Ignored by pipelines-execute
infra_live_repo:
description: "The name of the infrastructure-live repo to execute in"
required: true
infra_live_directory:
description: "The name of the directory containing the infrastructure-live repo on disk"
required: true
infra_live_repo_branch:
description: "The branch of the infrastructure-live repo to execute in"
required: true
gruntwork_config:
description: "Contents of the Gruntwork config file"
required: false
gruntwork_config_file:
description: "Absolute path to the Gruntwork config file"
required: false
deploy_branch_name:
description: ""
required: false
outputs:
execute_stdout:
description: "The output of the Pipelines Execute command"
value: ${{ steps.execute.outputs.execute_stdout }}
plan_folder:
description: "A folder with plan files (if any)"
value: ${{ steps.execute.outputs.plan_folder }}
formatted_plan_output:
description: "A string, formatted in GitHub Markdown, rendering human readable output of the plan"
value: ${{ steps.parse-plan.outputs.formatted_plan_output }}
runs:
using: "composite"
steps:
- name: Check Pipelines Version Env Var is correctly set
shell: bash
run: |
if [[ -z "$PIPELINES_CLI_VERSION" ]]; then
echo "::error::Missing required environment variable PIPELINES_CLI_VERSION"
exit 1
fi
- name: Check for Minimum Supported Version of the Pipelines CLI
shell: bash
env:
ACTION_PATH: ${{ github.action_path }}
run: $ACTION_PATH/scripts/check-msv.sh
# Enable tmate debugging of manually-triggered workflows if the input option was provided
- name: Enable debugging via ssh
uses: mxschmitt/action-tmate@v3
env:
GH_TOKEN: ${{ inputs.token }}
if: ${{ github.event_name == 'workflow_dispatch' && inputs.with_ssh_enabled }}
with:
detached: true
- name: Determine dynamic .mise.toml generation
id: determine_mise_toml
shell: bash
env:
GENERATE_MISE_TOML: ${{ inputs.generate_mise_toml }}
INFRA_LIVE_DIRECTORY: ${{ inputs.infra_live_directory }}
run: |
if [[ "$GENERATE_MISE_TOML" == "true" ]]; then
echo "generate_mise_toml=true" >> "$GITHUB_OUTPUT"
else
echo 'Confirming user has a `.mise.toml` file already'
if [[ -f "$INFRA_LIVE_DIRECTORY/.mise.toml" ]]; then
echo "generate_mise_toml=false" >> "$GITHUB_OUTPUT"
else
echo 'User does not have a `.mise.toml` file, generating one to avoid failure'
echo "generate_mise_toml=true" >> "$GITHUB_OUTPUT"
fi
fi
- name: Setup Mise Toml
if: ${{ steps.determine_mise_toml.outputs.generate_mise_toml == 'true' }}
id: mise-toml
shell: bash
env:
TF_VERSION: ${{ inputs.tf_version }}
TG_VERSION: ${{ inputs.tg_version }}
TF_BINARY: ${{ inputs.tf_binary }}
run: |
echo 'TOML<<EOF' >> "$GITHUB_OUTPUT"
echo '[tools]' >> "$GITHUB_OUTPUT"
echo "$TF_BINARY = \"$TF_VERSION\"" >> "$GITHUB_OUTPUT"
echo "terragrunt = \"$TG_VERSION\"" >> "$GITHUB_OUTPUT"
echo 'EOF' >> "$GITHUB_OUTPUT"
- uses: jdx/mise-action@v2
if: ${{ steps.determine_mise_toml.outputs.generate_mise_toml == 'true' }}
with:
install: true
cache: true
mise_toml: "${{ steps.mise-toml.outputs.TOML }}"
- uses: jdx/mise-action@v2
if: ${{ steps.determine_mise_toml.outputs.generate_mise_toml == 'false' }}
with:
install: true
cache: true
- name: Test Terraform, OpenTofu and Terragrunt
shell: bash
run: |
terraform --version || true
tofu --version || true
terragrunt --version
- name: Download Pipelines CLI
uses: dsaltares/fetch-gh-release-asset@1.1.2
with:
repo: "gruntwork-io/pipelines-cli"
version: "tags/${{ env.PIPELINES_CLI_VERSION }}"
file: "pipelines_linux_amd64"
target: "/tmp/pipelines"
token: ${{ inputs.token }}
- name: Install Pipelines CLI
shell: bash
run: |
sudo mv /tmp/pipelines /usr/local/bin/pipelines
sudo chmod +x /usr/local/bin/pipelines
- name: Load Machine User Name
id: load_machine_user
env:
GH_TOKEN: ${{ inputs.token }}
shell: bash
run: |
echo "MACHINE_USER_NAME=$(gh api /user | jq .login)" >> "$GITHUB_OUTPUT"
- name: Run Pipelines Execute
id: execute
shell: bash
env:
GH_TOKEN: ${{ inputs.token }}
MACHINE_USER_NAME: ${{ steps.load_machine_user.outputs.MACHINE_USER_NAME }}
INFRA_LIVE_DIRECTORY: ${{ inputs.infra_live_directory }}
TF_BINARY: ${{ inputs.tf_binary }}
WORKING_DIRECTORY: ${{ inputs.working_directory }}
TERRAGRUNT_COMMAND: ${{ inputs.terragrunt_command }}
TG_PARALLELISM_LIMIT: ${{ inputs.tg_execution_parallelism_limit }}
INFRA_LIVE_REPO: ${{ inputs.infra_live_repo }}
INFRA_LIVE_REPO_BRANCH: ${{ inputs.infra_live_repo_branch }}
DEPLOY_BRANCH_NAME: ${{ inputs.deploy_branch_name }}
GRUNTWORK_CONFIG: ${{ inputs.gruntwork_config }}
GRUNTWORK_CONFIG_FILE: ${{ inputs.gruntwork_config_file }}
run: |
# CD Infra-live directory && Run Pipelines-execute
cd "$INFRA_LIVE_DIRECTORY"
if [ "$TF_BINARY" == "terraform" ]
then
export TERRAGRUNT_TFPATH=terraform
else
export TERRAGRUNT_TFPATH=tofu
fi
PLAN_FOLDER="$(mktemp -d)"
pipelines execute terragrunt \
--working-directory "$WORKING_DIRECTORY" \
--command "$TERRAGRUNT_COMMAND" \
--tg-parallelism-limit "$TG_PARALLELISM_LIMIT" \
--infra-live-repo "$INFRA_LIVE_REPO" \
--infra-live-repo-branch "$INFRA_LIVE_REPO_BRANCH" \
--deployment-branch "$DEPLOY_BRANCH_NAME" \
--gruntwork-config "$GRUNTWORK_CONFIG" \
--gruntwork-config-file "$GRUNTWORK_CONFIG_FILE" \
--out-dir="$PLAN_FOLDER" | tee /tmp/pipelines-execute-stdout
echo "execute_stdout<<EOF" >> $GITHUB_OUTPUT
cat /tmp/pipelines-execute-stdout | sed -e "s/\x1b\[.\{1,5\}m//g" >> $GITHUB_OUTPUT
echo >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "plan_folder=$PLAN_FOLDER" >> $GITHUB_OUTPUT
- name: Parse resulting plans
id: parse-plan
shell: bash
env:
TF_BINARY: ${{ inputs.tf_binary }}
WORKING_DIRECTORY: ${{ inputs.working_directory }}
PLAN_FOLDER: ${{ steps.execute.outputs.plan_folder }}
INFRA_LIVE_DIRECTORY: ${{ inputs.infra_live_directory }}
run: |
if [ "$TF_BINARY" == "terraform" ]
then
export TERRAGRUNT_TFPATH=terraform
else
export TERRAGRUNT_TFPATH=tofu
fi
cd "$INFRA_LIVE_DIRECTORY"
OUTPUT="$(pipelines tfplan parse-to-comment --format=github --working-directory "$WORKING_DIRECTORY" "$PLAN_FOLDER")"
echo "formatted_plan_output<<EOF" >> $GITHUB_OUTPUT
echo $OUTPUT >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT