-
Notifications
You must be signed in to change notification settings - Fork 0
95 lines (84 loc) · 3.08 KB
/
terraform.yaml
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
name: "Terraform plan and apply"
on: # yamllint disable-line rule:truthy
pull_request:
branches:
- main
types:
- opened
- synchronize
- reopened
- labeled
- closed
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
permissions: {}
jobs:
terraform:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
timeout-minutes: 10
if: contains(github.event.pull_request.labels.*.name, 'terraform-deps')
env:
TF_CLOUD_WORKSPACE: ${{ vars.TF_CLOUD_WORKSPACE }}
TERRAGRUNT_PATH: ${{ github.workspace }}/.github/scripts/tfwrapper.sh
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
# just use to login to terraform cloud
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
with:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
- uses: aquaproj/aqua-installer@f13c5d2f0357708d85477aabe50fd3f725528745 # v3.1.0
with:
aqua_version: v2.40.0
aqua_opts: ""
- name: init
run: |
terragrunt run-all init --terragrunt-non-interactive
env:
TF_CLOUD_ORGANIZATION: ${{ secrets.TF_CLOUD_ORGANIZATION }}
- name: validate
run: |
terragrunt run-all validate --terragrunt-non-interactive
env:
TF_CLOUD_ORGANIZATION: ${{ secrets.TF_CLOUD_ORGANIZATION }}
GITHUB_APP_ID: ${{ secrets.GH_APP_ID }}
GITHUB_APP_INSTALLATION_ID: ${{ secrets.GH_APP_INSTALLATION_ID }}
GITHUB_APP_PEM_FILE: ${{ secrets.GH_APP_PEM_FILE }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: plan
run: |
terragrunt run-all plan --terragrunt-non-interactive
env:
TF_CLOUD_ORGANIZATION: ${{ secrets.TF_CLOUD_ORGANIZATION }}
GITHUB_APP_ID: ${{ secrets.GH_APP_ID }}
GITHUB_APP_INSTALLATION_ID: ${{ secrets.GH_APP_INSTALLATION_ID }}
GITHUB_APP_PEM_FILE: ${{ secrets.GH_APP_PEM_FILE }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: apply
if: github.event.pull_request.merged == true
run: |
terragrunt run-all apply --terragrunt-non-interactive
env:
TF_CLOUD_ORGANIZATION: ${{ secrets.TF_CLOUD_ORGANIZATION }}
GITHUB_APP_ID: ${{ secrets.GH_APP_ID }}
GITHUB_APP_INSTALLATION_ID: ${{ secrets.GH_APP_INSTALLATION_ID }}
GITHUB_APP_PEM_FILE: ${{ secrets.GH_APP_PEM_FILE }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
check-tf-result:
needs: terraform
runs-on: ubuntu-latest
timeout-minutes: 5
if: always()
steps:
- name: check results
run: |
FAILURE_JOBS=$(echo "${NEEDS_JSON}" | jq -r 'to_entries | map(select(.value.result == "failure")) | map(.key + " " + .value.result) | join("\n")')
if [ -n "${FAILURE_JOBS}" ]; then
echo "The following jobs failed: ${FAILURE_JOBS}"
exit 1
fi
env:
NEEDS_JSON: ${{ toJSON(needs) }}