-
Notifications
You must be signed in to change notification settings - Fork 0
54 lines (42 loc) · 1.43 KB
/
terraform-ci-cd.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
name: Terraform - Infra Cluster AWS EKS
on:
push:
branches:
- main
jobs:
terraform:
runs-on: ubuntu-latest
steps:
- name: Check out the code
uses: actions/checkout@v2
- name: Set up Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 1.3
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Read config.json
id: read-config
run: |
ENABLED="$(jq -r '.enabled' ./config.json)"
echo "enabled=$(echo $ENABLED)" >> $GITHUB_OUTPUT
- name: Terraform Init
run: terraform init
- name: Terraform Fmt
run: terraform fmt
- name: Terraform Validate
run: terraform validate
- name: Terraform Destroy
if: steps.read-config.outputs.enabled == 'false'
run: terraform destroy -auto-approve -lock=false
- name: Terraform Plan
if: steps.read-config.outputs.enabled == 'true'
run: terraform plan -lock=false
- name: Terraform Apply
if: steps.read-config.outputs.enabled == 'true'
run: terraform apply -auto-approve -lock=false