Repository navigation
98 lines (85 loc) · 2.93 KB
/
Copy pathwf-tf-plan.yaml
File metadata and controls
98 lines (85 loc) · 2.93 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
name: wf_tf_plan
run-name: TF Plan
on:
workflow_call:
inputs:
tfDirectory:
description: "Terraform directory to run plan on"
type: string
default: .github/samples-infra
tfPlanFileName:
description: "Terraform plan file name"
type: string
default: tfplan
tfvarWebAppName:
description: "Web Application name"
type: string
required: true
outputs:
tfplanExitCode:
description: "Terraform plan exit code"
value: ${{ jobs.tf-plan.outputs.tfplanExitCode }}
jobs:
tf-plan:
name: Terraform Plan
runs-on: ubuntu-latest
environment: development
env:
ARM_CLIENT_ID: "${{ secrets.AZURE_CLIENT_ID }}"
ARM_SUBSCRIPTION_ID: "${{ secrets.AZURE_SUBSCRIPTION_ID }}"
ARM_TENANT_ID: "${{ secrets.AZURE_TENANT_ID }}"
WORKING_DIRECTORY: ${{ inputs.tfDirectory }}
TFPLAN_FILE_NAME: ${{ inputs.tfPlanFileName }}
defaults:
run:
working-directory: ${{ env.WORKING_DIRECTORY }}
outputs:
tfplanExitCode: ${{ steps.tf-plan.outputs.exitcode }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: ${{ env.WORKING_DIRECTORY }}
sparse-checkout-cone-mode: false
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_wrapper: false
- name: Terraform Init
run: terraform init
- name: Terraform Validate
run: terraform validate
- name: Terraform Plan
id: tf-plan
env:
TF_VAR_web_app_name: ${{ inputs.tfvarWebAppName }}
TF_VAR_ifttt_service_key: ${{ secrets.IFTTT_SERVICE_KEY }}
run: |
export exitcode=0
terraform plan -detailed-exitcode -no-color -out ${{ env.TFPLAN_FILE_NAME }} || export exitcode=$?
echo "exitcode=$exitcode" >> $GITHUB_OUTPUT
if [ $exitcode -eq 1 ]; then
echo Terraform Plan Failed
exit 1
elif [ $exitcode -eq 2 ]; then
echo Infrastructure will be updated
exit 0
else
echo Infrastructure is up-to-date
exit 0
fi
- name: Publish Terraform Plan
uses: actions/upload-artifact@v4
with:
name: ${{ env.TFPLAN_FILE_NAME }}
path: ${{ env.WORKING_DIRECTORY }}/${{ env.TFPLAN_FILE_NAME }}
- name: Publish Terraform Plan Summary
run: |
TERRAFORM_PLAN=$(terraform show -no-color ${{ env.TFPLAN_FILE_NAME }})
echo "## Terraform Plan Output" >> $GITHUB_STEP_SUMMARY
echo "<details><summary>Click to expand</summary>" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```terraform' >> $GITHUB_STEP_SUMMARY
echo "$TERRAFORM_PLAN" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "</details>" >> $GITHUB_STEP_SUMMARY