Skip to content

Commit 086f519

Browse files
VIA-598 AJ/DB WIP shuffling steps around to match terraform version to deploy
1 parent 32a2900 commit 086f519

File tree

1 file changed

+49
-37
lines changed

1 file changed

+49
-37
lines changed

.github/actions/deploy/action.yml

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,26 @@ inputs:
2121
runs:
2222
using: composite
2323
steps:
24-
- name: "Show inputs"
25-
shell: bash
26-
run: |
27-
echo "Deploying to ( ${{ inputs.environment }} ) environment"
28-
echo "Deploying tag/sha ${{ inputs.tag_or_sha_to_deploy }}"
24+
#################################################
25+
# Setup GitHub IAM user permissions in AWS first
26+
#################################################
2927

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
3032
- name: "Checkout code"
3133
uses: actions/checkout@v5
3234
with:
33-
ref: ${{ inputs.tag_or_sha_to_deploy }}
35+
fetch-depth: 0
36+
ref: 'main'
37+
38+
- name: "Configure AWS credentials"
39+
uses: aws-actions/configure-aws-credentials@v5
40+
with:
41+
role-session-name: GitHubActionsSession
42+
role-to-assume: ${{ inputs.secret_aws_iam_role }}
43+
aws-region: eu-west-2
3444

3545
- name: "Identify Terraform version"
3646
shell: bash
@@ -43,12 +53,28 @@ runs:
4353
with:
4454
terraform_version: "${{ steps.identify-terraform-version.outputs.terraform_version }}"
4555

46-
- name: "Configure AWS credentials"
47-
uses: aws-actions/configure-aws-credentials@v5
48-
with:
49-
role-session-name: GitHubActionsSession
50-
role-to-assume: ${{ inputs.secret_aws_iam_role }}
51-
aws-region: eu-west-2
56+
- name: "Set terraform environment vars"
57+
shell: bash
58+
run: |
59+
echo "TF_VAR_is_github_action=true" >> $GITHUB_ENV
60+
echo "TF_VAR_alarms_slack_channel_id=${{ inputs.secret_aws_slack_channel_id }}" >> $GITHUB_ENV
61+
echo "TF_VAR_app_version=${{ inputs.tag_or_sha_to_deploy }}" >> $GITHUB_ENV
62+
63+
- name: "Terraform init (iam)"
64+
shell: bash
65+
run: TF_ENV=${{ inputs.environment }}/iam make terraform-init
66+
67+
- name: "Terraform plan (iam)"
68+
shell: bash
69+
run: TF_ENV=${{ inputs.environment }}/iam make terraform-plan opts="-out=terraform-iam.tfplan"
70+
71+
- name: "Terraform apply (iam)"
72+
shell: bash
73+
run: TF_ENV=${{ inputs.environment }}/iam make terraform-apply opts="-auto-approve" opts="terraform-iam.tfplan"
74+
75+
#################################################
76+
# Download the required artefacts from AWS
77+
#################################################
5278

5379
- name: "Download artefacts from S3 bucket"
5480
shell: bash
@@ -71,39 +97,25 @@ runs:
7197
unzip open-next.zip
7298
rm -rf open-next.zip
7399
74-
- name: "Set terraform environment vars"
75-
shell: bash
76-
run: |
77-
echo "TF_VAR_is_github_action=true" >> $GITHUB_ENV
78-
echo "TF_VAR_alarms_slack_channel_id=${{ inputs.secret_aws_slack_channel_id }}" >> $GITHUB_ENV
79-
echo "TF_VAR_app_version=${{ inputs.tag_or_sha_to_deploy }}" >> $GITHUB_ENV
100+
#################################################
101+
# Deploy the artefacts to AWS
102+
#################################################
80103

81-
# Rationale:
82-
# - why? given we reuse preprod for R1.0 and R2.0, when IAM permission change across releases, then deployment fails
83-
# - constraint? make sure IAM permissions in R2.0 is a superset of R1.0
84-
# - what? deploy IAM from R2.0 as it is a superset and will succeed R1.0 deployments as well
85104
- name: "Checkout code"
86105
uses: actions/checkout@v5
87106
with:
88-
fetch-depth: 0
89-
ref: 'main'
90-
91-
- name: "Terraform init (iam)"
92-
shell: bash
93-
run: TF_ENV=${{ inputs.environment }}/iam make terraform-init
94-
95-
- name: "Terraform plan (iam)"
96-
shell: bash
97-
run: TF_ENV=${{ inputs.environment }}/iam make terraform-plan opts="-out=terraform-iam.tfplan"
107+
ref: ${{ inputs.tag_or_sha_to_deploy }}
98108

99-
- name: "Terraform apply (iam)"
109+
- name: "Identify Terraform version"
100110
shell: bash
101-
run: TF_ENV=${{ inputs.environment }}/iam make terraform-apply opts="-auto-approve" opts="terraform-iam.tfplan"
111+
id: identify-terraform-version
112+
run: |
113+
echo "terraform_version=$(grep "^terraform" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
102114
103-
- name: "Checkout code"
104-
uses: actions/checkout@v5
115+
- name: "Install Terraform version"
116+
uses: hashicorp/setup-terraform@v3
105117
with:
106-
ref: ${{ inputs.tag_or_sha_to_deploy }}
118+
terraform_version: "${{ steps.identify-terraform-version.outputs.terraform_version }}"
107119

108120
- name: "Terraform init (app)"
109121
shell: bash

0 commit comments

Comments
 (0)