This repository was archived by the owner on Jun 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
109 lines (100 loc) · 3.13 KB
/
action.yml
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
name: "gfg-tf-drift-action"
description: "Check terraform drift"
inputs:
token:
description: Github token for downloading the repository
required: true
terraform-version:
description: Terraform version
required: true
terraform-api-token:
required: true
terragrunt-version:
description: Terragrunt version
required: true
tf-slack-channel:
description: Terraform slack channel
required: true
tf-slack-user:
description: Terraform slack username
required: true
slack-author:
description: Slack author username
required: true
slack-webhook:
description: Slack webhook
required: true
aws-access-key-id:
description: AWS API Key ID
required: true
aws-secret-key:
description: AWS Secret Key
required: true
runs:
using: "composite"
steps:
- name: 'Checkout'
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: 'Setup Terraform'
uses: hashicorp/setup-terraform@v1
with:
terraform_version: ${{ inputs.terraform-version }}
cli_config_credentials_token: ${{ inputs.terraform-api-token }}
- name: 'Setup Terragrunt'
uses: autero1/[email protected]
with:
terragrunt_version: ${{ inputs.terragrunt-version }}
- name: 'Create AWS credentials file'
run: |
${{ github.action_path }}/create_aws_credentials_file.sh ${{ inputs.aws-access-key-id }} ${{ inputs.aws-secret-key }}
shell: bash
- name: 'Add AWS config file'
run: |
cp ${{ github.action_path }}/config ~/.aws/config
chown ubuntu:ubuntu ~/.aws/config
cp ${{ github.action_path }}/config /root/.aws/config
chown ubuntu:root /root/.aws/config
shell: bash
- name: 'Prepare Git'
env:
GITHUB_TOKEN: ${{ inputs.token }}
GITHUB_USERNAME: "gfg-hue"
run: |
${{ github.action_path }}/git_config.sh
shell: bash
- name: 'Terraform init'
id: init
run: |
cd ${{ matrix.tf_config }}
terragrunt init
shell: bash
- name: 'Terraform plan'
id: plan
run: |
cd ${{ matrix.tf_config }}
terragrunt plan -lock=false -detailed-exitcode
continue-on-error: true
shell: bash
- name: 'Clean AWS creds'
if: always()
run: |
echo "Cleaning up AWS credentials"
rm -rf ~/.aws
rm -rf /root/.aws
shell: bash
- name: 'Slack Notification on failure'
if: steps.plan.outcome == 'failure'
uses: rtCamp/action-slack-notify@v2
env:
SLACK_CHANNEL: ${{ inputs.tf-slack-channel }}
SLACK_USERNAME: ${{ inputs.tf-slack-user }}
SLACK_MSG_AUTHOR: ${{ inputs.slack-author }}
SLACK_COLOR: ${{ job.status }}
SLACK_ICON: https://github.com/github.png?size=48
SLACK_TITLE: 'Terraform infrastructure drift'
SLACK_MESSAGE: 'Drift detected in ${{ matrix.tf_config }} Terraform state'
SLACK_FOOTER: |
'See the link https://github.com/GFG/terraform-ventures-infrastructure/actions/runs/${{ github.run_id }}?check_suite_focus=true'
SLACK_WEBHOOK: ${{ inputs.slack-webhook }}