@@ -21,19 +21,11 @@ inputs:
2121runs :
2222 using : composite
2323 steps :
24- # ################################################
25- # Setup GitHub IAM user permissions in AWS first
26- # ################################################
27-
28- # Rationale:
29- # - why? given we reuse preprod for R1.0 and R2.0, when IAM permission change across releases, then deployment fails
30- # - constraint? make sure R2.0 IAM permissions are a superset of R1.0 IAM permissions
31- # - what? deploy IAM from R2.0 as it is a superset and then R1.0 deployments will succeed as well
32- - name : " Checkout main branch"
24+ - name : " Checkout target code"
3325 uses : actions/checkout@v5
3426 with :
35- ref : ' main '
36- path : " code-for-iam "
27+ ref : ${{ inputs.tag_or_sha_to_deploy }}
28+ path : " code-for-app "
3729
3830 - name : " Configure AWS credentials"
3931 uses : aws-actions/configure-aws-credentials@v5
@@ -42,50 +34,26 @@ runs:
4234 role-to-assume : ${{ inputs.secret_aws_iam_role }}
4335 aws-region : eu-west-2
4436
37+ # ################################################
38+ # Set up Terraform
39+ # ################################################
40+
4541 - name : " Identify Terraform version"
4642 shell : bash
47- working-directory : " ./code-for-iam "
48- id : identify-terraform-version-main
43+ id : identify-terraform-version
44+ working-directory : " ./code-for-app "
4945 run : |
5046 echo "terraform_version=$(grep "^terraform" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
5147
5248 - name : " Install Terraform version"
5349 uses : hashicorp/setup-terraform@v3
5450 with :
55- terraform_version : " ${{ steps.identify-terraform-version-main.outputs.terraform_version }}"
56-
57- - name : " Set terraform environment vars"
58- shell : bash
59- run : |
60- echo "TF_VAR_is_github_action=true" >> $GITHUB_ENV
61- echo "TF_VAR_alarms_slack_channel_id=${{ inputs.secret_aws_slack_channel_id }}" >> $GITHUB_ENV
62- echo "TF_VAR_app_version=${{ inputs.tag_or_sha_to_deploy }}" >> $GITHUB_ENV
63-
64- - name : " Terraform init (iam)"
65- shell : bash
66- working-directory : " ./code-for-iam"
67- run : TF_ENV=${{ inputs.environment }}/iam make terraform-init
68-
69- - name : " Terraform plan (iam)"
70- shell : bash
71- working-directory : " ./code-for-iam"
72- run : TF_ENV=${{ inputs.environment }}/iam make terraform-plan opts="-out=terraform-iam.tfplan"
73-
74- - name : " Terraform apply (iam)"
75- shell : bash
76- working-directory : " ./code-for-iam"
77- run : TF_ENV=${{ inputs.environment }}/iam make terraform-apply opts="-auto-approve" opts="terraform-iam.tfplan"
51+ terraform_version : " ${{ steps.identify-terraform-version.outputs.terraform_version }}"
7852
7953 # ################################################
8054 # Download the required artefacts from AWS
8155 # ################################################
8256
83- - name : " Checkout target code"
84- uses : actions/checkout@v5
85- with :
86- ref : ${{ inputs.tag_or_sha_to_deploy }}
87- path : " code-for-app"
88-
8957 - name : " Download artefacts from S3 bucket"
9058 shell : bash
9159 working-directory : " ./code-for-app"
@@ -109,21 +77,35 @@ runs:
10977 unzip open-next.zip
11078 rm -rf open-next.zip
11179
80+ - name : " Set terraform environment vars"
81+ shell : bash
82+ run : |
83+ echo "TF_VAR_is_github_action=true" >> $GITHUB_ENV
84+ echo "TF_VAR_alarms_slack_channel_id=${{ inputs.secret_aws_slack_channel_id }}" >> $GITHUB_ENV
85+ echo "TF_VAR_app_version=${{ inputs.tag_or_sha_to_deploy }}" >> $GITHUB_ENV
86+
11287 # ################################################
113- # Deploy the artefacts to AWS
88+ # Deploy IAM permissions to AWS
11489 # ################################################
11590
116- - name : " Identify Terraform version "
91+ - name : " Terraform init (iam) "
11792 shell : bash
118- id : identify-terraform-version-tag
11993 working-directory : " ./code-for-app"
120- run : |
121- echo "terraform_version=$(grep "^terraform" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
94+ run : TF_ENV=${{ inputs.environment }}/iam make terraform-init
12295
123- - name : " Install Terraform version"
124- uses : hashicorp/setup-terraform@v3
125- with :
126- terraform_version : " ${{ steps.identify-terraform-version-tag.outputs.terraform_version }}"
96+ - name : " Terraform plan (iam)"
97+ shell : bash
98+ working-directory : " ./code-for-app"
99+ run : TF_ENV=${{ inputs.environment }}/iam make terraform-plan opts="-out=terraform-iam.tfplan"
100+
101+ - name : " Terraform apply (iam)"
102+ shell : bash
103+ working-directory : " ./code-for-app"
104+ run : TF_ENV=${{ inputs.environment }}/iam make terraform-apply opts="-auto-approve" opts="terraform-iam.tfplan"
105+
106+ # ################################################
107+ # Deploy the artefacts to AWS
108+ # ################################################
127109
128110 - name : " Terraform init (app)"
129111 shell : bash
0 commit comments