1
+ name : " Terraform Developer"
2
+
3
+ on :
4
+ push :
5
+ branches :
6
+ - develop
7
+ paths :
8
+ - terraform/**
9
+ pull_request :
10
+ branches :
11
+ - develop
12
+ paths :
13
+ - terraform/**
14
+
15
+ env :
16
+ WORKSPACE : " dev"
17
+ aws-region : " us-east-1"
18
+ destroy : false
19
+
20
+ permissions :
21
+ contents : read
22
+ id-token : write
23
+ pull-requests : write
24
+
25
+ jobs :
26
+ InfraDev :
27
+ runs-on : ubuntu-latest
28
+ defaults :
29
+ run :
30
+ shell : bash
31
+ working-directory : ./terraform
32
+
33
+ steps :
34
+ - name : " Checkout"
35
+ uses : actions/checkout@v4
36
+
37
+ - name : Setup Terraform
38
+ uses : hashicorp/setup-terraform@v3
39
+ with :
40
+ terraform_version : 1.10.5
41
+
42
+ - name : Configure AWS credentials
43
+ uses : aws-actions/configure-aws-credentials@v4
44
+ with :
45
+ role-session-name : GitHub_AWS_OIDC
46
+ aws-region : ${{ env.aws-region }}
47
+ role-to-assume : ${{ vars.AWS_ASSUME_ROLE_ARN }}
48
+
49
+ - name : Terraform fmt
50
+ id : fmt
51
+ run : terraform fmt -check
52
+ continue-on-error : true
53
+
54
+ - name : Terraform Init
55
+ id : init
56
+ run : |
57
+ terraform init -backend-config="./envs/${{ env.WORKSPACE }}/backend.tfvars" -input=false
58
+ terraform workspace select -or-create ${{ env.WORKSPACE }}
59
+ continue-on-error : false
60
+
61
+ - name : Terraform Validate
62
+ id : validate
63
+ run : terraform validate
64
+ continue-on-error : true
65
+
66
+ - name : Terraform Destroy
67
+ if : ${{ env.destroy == true }}
68
+ id : destroy
69
+ run : terraform destroy -var-file="./envs/${{ env.WORKSPACE }}/terraform.tfvars" -auto-approve
70
+
71
+ - name : Terraform Plan
72
+ if : ${{ env.destroy != true && github.event_name == 'pull_request'}}
73
+ id : plan
74
+ run : terraform plan -out plan.tf -var-file="./envs/${{ env.WORKSPACE }}/terraform.tfvars" -no-color
75
+
76
+ - name : Terraform Resources List
77
+ uses : borchero/terraform-plan-comment@v2
78
+ if : github.event_name == 'pull_request'
79
+ with :
80
+ token : ${{ github.token }}
81
+ planfile : plan.tf
82
+ working-directory : ./terraform
83
+
84
+ - name : Terraform Apply
85
+ if : ${{ env.destroy != true && github.event_name == 'push'}}
86
+ id : apply
87
+ run : terraform apply -var-file="./envs/${{ env.WORKSPACE }}/terraform.tfvars" -auto-approve
0 commit comments