-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (74 loc) · 2.76 KB
/
terraform.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
name: Terraform Deployment 2
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
PROFILE_NAME: 'smg-auto-dev'
defaults:
run:
shell: bash
working-directory: .
jobs:
terraform_plan:
name: 'Terraform Plan'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup GitHub SSH
uses: MrSquaare/ssh-setup-action@v2
with:
host: github.com
private-key: ${{ secrets.SSH_PRIVATE_KEY_GITHUB }}
- name: Clone other private repository
run: |
git clone [email protected]:dyleph/terraform-demo-with-GA.git
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.3.3
- name: Add profile credentials to ~/.aws/credentials
run: |
aws configure set aws_access_key_id ${{ env.AWS_ACCESS_KEY_ID }} --profile ${{ env.PROFILE_NAME }}
aws configure set aws_secret_access_key ${{ env.AWS_SECRET_ACCESS_KEY }} --profile ${{ env.PROFILE_NAME }}
- name: Terraform Init
run: terraform init
- name: Terraform Validate
run: terraform validate
- name: Terraform Plan
id: plan
run: terraform plan -out saved_plan
- name: Terraform Apply
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: terraform apply -auto-approve
- name: Get commit message
id: get-commit-message
run: |
echo "COMMIT_MESSAGE=$(git log -1 --pretty=%s)" >> $GITHUB_OUTPUT
- name: Slack notify successful
id: slack-notify-successful
uses: slackapi/[email protected]
if: github.ref == 'refs/heads/main' && github.event_name == 'push' && success()
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
with:
payload: |
"{\"text\":\":rocket: Deployed ${{ github.event.repository.name }}\n>${{ steps.get-commit-message.outputs.COMMIT_MESSAGE }}\"}"
- name: Slack notify failure
id: slack-notify-failure
uses: slackapi/[email protected]
if: github.ref == 'refs/heads/main' && github.event_name == 'push' && failure()
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
WORKFLOW_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
with:
payload: |
"{\"text\":\":boom: ${{ github.event.repository.name }} failed: ${{ env.WORKFLOW_URL }}\"}"