Skip to content

Commit ded2429

Browse files
authored
[NDR-266] Split jobs on sandbox (#446)
* init * Set branch and main terraform build to separate jobs * Update job names * Add 8 character limit to sandbox name * Move branch check to job level. * Fix terraform version
1 parent 5c22e3c commit ded2429

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

.github/workflows/deploy-sandbox.yml

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
required: true
1111
type: "string"
1212
sandbox_name:
13-
description: "Sandbox name [a-z0-9]{1,9}"
13+
description: "Sandbox name [a-z0-9]{1,8}"
1414
required: true
1515
type: "string"
1616

@@ -20,20 +20,26 @@ permissions:
2020
contents: read # This is required for actions/checkout
2121

2222
jobs:
23-
terraform_process:
23+
validate_inputs:
2424
runs-on: ubuntu-latest
2525
environment: development
2626

2727
steps:
2828
- name: Validate inputs
2929
run: |
30-
if ! [[ "$SANDBOX_NAME" =~ ^[a-z0-9]{1,9}$ ]]; then
31-
echo "Sandbox name must match [a-z0-9]{1,9} (lowercase letters and digits only, 1-9 chars)."
30+
if ! [[ "$SANDBOX_NAME" =~ ^[a-z0-9]{1,8}$ ]]; then
31+
echo "Sandbox name must match [a-z0-9]{1,8} (lowercase letters and digits only, 1-8 chars)."
3232
exit 1
3333
fi
3434
env:
3535
SANDBOX_NAME: ${{ github.event.inputs.sandbox_name }}
3636

37+
terraform_process--main:
38+
runs-on: ubuntu-latest
39+
needs: validate_inputs
40+
environment: development
41+
42+
steps:
3743
# Checkout the repository to the GitHub Actions runner
3844
- name: Checkout main
3945
uses: actions/checkout@v5
@@ -81,41 +87,59 @@ jobs:
8187
run: terraform apply -auto-approve -input=false tf-main.plan
8288
working-directory: ./infrastructure
8389

90+
terraform_process--branch:
91+
if: ${{ github.event.inputs.git_ref != 'main' }}
92+
runs-on: ubuntu-latest
93+
needs: terraform_process--main
94+
environment: development
95+
96+
steps:
97+
- name: Configure AWS Credentials
98+
uses: aws-actions/configure-aws-credentials@v5
99+
with:
100+
role-to-assume: ${{ secrets.AWS_ASSUME_ROLE }}
101+
role-skip-session-tagging: true
102+
aws-region: ${{ vars.AWS_REGION }}
103+
mask-aws-account-id: true
104+
105+
- name: View AWS Role
106+
run: aws sts get-caller-identity
107+
108+
- name: Setup Terraform
109+
uses: hashicorp/setup-terraform@v3
110+
with:
111+
terraform_version: 1.13.3
112+
terraform_wrapper: false
113+
84114
- name: Checkout Branch
85-
if: ${{ github.event.inputs.git_ref != 'main' }}
86115
uses: actions/checkout@v5
87116
with:
88117
ref: ${{ github.event.inputs.git_ref}}
89118

90119
# Checks that all Terraform configuration files adhere to a canonical format.
91120
- name: Terraform Format Branch
92-
if: ${{ github.event.inputs.git_ref != 'main' }}
93121
run: terraform fmt -check
94122
working-directory: ./infrastructure
95123

96124
- name: Terraform Init Branch
97-
if: ${{ github.event.inputs.git_ref != 'main' }}
98125
id: init
99126
run: terraform init -backend-config=backend.conf
100127
working-directory: ./infrastructure
101128
shell: bash
102129

103130
- name: Terraform Set Workspace
104-
if: ${{ github.event.inputs.git_ref != 'main' }}
105131
id: workspace
106132
run: terraform workspace select ${{ github.event.inputs.sandbox_name}}
107133
working-directory: ./infrastructure
108134
shell: bash
109135

110136
- name: Terraform Plan Branch
111-
if: ${{ github.event.inputs.git_ref != 'main' }}
112137
id: plan
113138
run: |
114139
terraform plan -input=false -no-color -var-file="${{vars.TF_VARS_FILE}}" -out tf.plan
115140
working-directory: ./infrastructure
116141
shell: bash
117142

118143
- name: Terraform Apply Branch (over main)
119-
if: ${{ github.event.inputs.git_ref != 'main' }}
120144
run: terraform apply -auto-approve -input=false tf.plan
121145
working-directory: ./infrastructure

0 commit comments

Comments
 (0)