1
- name : Terraform Deployment
1
+ name : " [PROD] - Terraform Deployment"
2
2
3
3
on :
4
4
push :
5
5
branches :
6
- - develop
7
6
- main
8
7
8
+ permissions :
9
+ id-token : write
10
+ contents : read
11
+
9
12
jobs :
10
13
terraform :
11
14
runs-on : ubuntu-latest
@@ -16,27 +19,27 @@ jobs:
16
19
17
20
steps :
18
21
- name : Checkout code
19
- uses : actions/checkout@v2
22
+ uses : actions/checkout@v4
20
23
21
24
- name : Setup Terraform
22
- uses : hashicorp/setup-terraform@v2
25
+ uses : hashicorp/setup-terraform@v3
23
26
with :
24
27
terraform_version : 1.8.3
25
28
26
29
- name : Configure AWS credentials
27
- uses : aws-actions/configure-aws-credentials@v2
30
+ uses : aws-actions/configure-aws-credentials@v4
28
31
with :
29
- aws-access-key-id : ${{ secrets.AWS_ACCESS_KEY_ID }}
30
- aws-secret-access-key : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
32
+ role-to-assume : arn:aws:iam::179916804929:role/BuildRun-GithubActions-Role # change to reflect your IAM role’s ARN
33
+ role-session-name : GitHub_to_AWS_via_FederatedOIDC
31
34
aws-region : ${{ vars.AWS_REGION }}
32
35
33
36
- name : Read destroy configuration
34
37
id : read-destroy-config
35
38
run : |
36
39
DESTROY_DEV="$(jq -r '.dev' ./infra/destroy_config.json)"
37
40
DESTROY_PROD="$(jq -r '.prod' ./infra/destroy_config.json)"
38
- echo "::set-output name= destroy_dev::$ DESTROY_DEV"
39
- echo "::set-output name= destroy_prod::$ DESTROY_PROD"
41
+ echo "destroy_dev=$(echo $ DESTROY_DEV)" >> $GITHUB_OUTPUT
42
+ echo "destroy_prod=$(echo $ DESTROY_PROD)" >> $GITHUB_OUTPUT
40
43
41
44
- name : Terraform Init
42
45
run : |
49
52
- name : Terraform Validate
50
53
run : terraform validate
51
54
52
- - name : Terraform Destroy for Dev
53
- if : steps.read-destroy-config.outputs.destroy_dev == 'true' && github.ref == 'refs/heads/develop' && github.event_name == 'push'
54
- id : terraform-destroy-dev
55
- run : cd infra &&
56
- terraform workspace select dev || terraform workspace new dev &&
57
- terraform destroy -var-file="./envs/dev/terraform.tfvars" -auto-approve
58
-
59
- - name : Terraform Plan for Dev
60
- if : steps.read-destroy-config.outputs.destroy_dev != 'true' && github.ref == 'refs/heads/develop' && github.event_name == 'push'
61
- id : terraform-plan-dev
62
- run : cd infra &&
63
- terraform workspace select dev || terraform workspace new dev &&
64
- terraform plan -var-file="./envs/dev/terraform.tfvars" -out=dev.plan
65
-
66
- - name : Terraform Apply for Dev
67
- id : terraform-apply-dev
68
- if : steps.read-destroy-config.outputs.destroy_dev != 'true' && github.ref == 'refs/heads/develop' && github.event_name == 'push'
69
- run : cd infra &&
70
- terraform workspace select dev || terraform workspace new dev &&
71
- terraform apply "dev.plan"
72
-
73
55
- name : Terraform Destroy for Prod
74
56
if : steps.read-destroy-config.outputs.destroy_prod == 'true' && github.ref == 'refs/heads/main' && github.event_name == 'push'
75
57
id : terraform-destroy-prod
0 commit comments