Skip to content

Commit 44ce666

Browse files
authored
[NDR-198] Manage AWS lambda layers after lambda has been destroyed (#391)
* Add core workspace to VPC and SG * Add reports layer * Print test * Add imports for layers * Remove imports * Add import script into workflow * Check the terraform state * Add import layers to all envs * add aws_caller_identity to lambda_layers * Terraform docs * move import
1 parent 2ea83a6 commit 44ce666

13 files changed

+355
-254
lines changed

.github/workflows/terraform-deploy-feature-to-sandbox.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ jobs:
9898
working-directory: ./infrastructure
9999
shell: bash
100100

101+
- name: Lambda Layer Imports
102+
id: lambda_layer_import
103+
run: ./import_lambda_layers.sh ${{ github.event.inputs.sandboxWorkspace }} ${{ vars.TF_VARS_FILE }}
104+
working-directory: ./scripts
105+
shell: bash
106+
101107
- name: Terraform Plan
102108
id: plan
103109
run: |
Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# .github/workflows/terraform-dev
2-
name: 'Deploy Feature Branch to Perf'
2+
name: "Deploy Feature Branch to Perf"
33

44
on:
55
workflow_dispatch:
@@ -12,64 +12,68 @@ on:
1212
permissions:
1313
pull-requests: write
1414
id-token: write # This is required for requesting the JWT
15-
contents: read # This is required for actions/checkout
16-
15+
contents: read # This is required for actions/checkout
16+
1717
jobs:
1818
terraform_process:
1919
runs-on: ubuntu-latest
2020
environment: perf
2121

2222
steps:
23-
# Checkout the repository to the GitHub Actions runner
24-
- name: Checkout
25-
uses: actions/checkout@v5
26-
with:
27-
ref: ${{ github.event.inputs.buildBranch}}
28-
fetch-depth: '0'
23+
# Checkout the repository to the GitHub Actions runner
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
with:
27+
ref: ${{ github.event.inputs.buildBranch}}
28+
fetch-depth: "0"
29+
30+
- name: Configure AWS Credentials
31+
uses: aws-actions/configure-aws-credentials@v4
32+
with:
33+
role-to-assume: ${{ secrets.AWS_ASSUME_ROLE }}
34+
role-skip-session-tagging: true
35+
aws-region: ${{ vars.AWS_REGION }}
36+
mask-aws-account-id: true
37+
38+
- name: View AWS Role
39+
run: aws sts get-caller-identity
40+
41+
# Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
42+
- name: Setup Terraform
43+
uses: hashicorp/setup-terraform@v3
44+
with:
45+
terraform_version: 1.11.4
46+
terraform_wrapper: false
47+
48+
- name: Terraform Init
49+
id: init
50+
run: terraform init -backend-config=backend.conf
51+
working-directory: ./infrastructure
52+
shell: bash
2953

30-
- name: Configure AWS Credentials
31-
uses: aws-actions/configure-aws-credentials@v4
32-
with:
33-
role-to-assume: ${{ secrets.AWS_ASSUME_ROLE }}
34-
role-skip-session-tagging: true
35-
aws-region: ${{ vars.AWS_REGION }}
36-
mask-aws-account-id: true
37-
38-
- name: View AWS Role
39-
run: aws sts get-caller-identity
54+
- name: Terraform Set Workspace
55+
id: workspace
56+
run: terraform workspace select ${{ secrets.AWS_WORKSPACE }}
57+
working-directory: ./infrastructure
58+
shell: bash
4059

41-
# Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
42-
- name: Setup Terraform
43-
uses: hashicorp/setup-terraform@v3
44-
with:
45-
terraform_version: 1.11.4
46-
terraform_wrapper: false
47-
48-
- name: Terraform Init
49-
id: init
50-
run: terraform init -backend-config=backend.conf
51-
working-directory: ./infrastructure
52-
shell: bash
60+
- name: Lambda Layer Imports
61+
id: lambda_layer_import
62+
run: ./import_lambda_layers.sh ${{ secrets.AWS_WORKSPACE }} ${{ vars.TF_VARS_FILE }}
63+
working-directory: ./scripts
64+
shell: bash
5365

54-
- name: Terraform Set Workspace
55-
id: workspace
56-
run: terraform workspace select ${{ secrets.AWS_WORKSPACE }}
57-
working-directory: ./infrastructure
58-
shell: bash
59-
60-
# Checks that all Terraform configuration files adhere to a canonical format
61-
- name: Terraform Format
62-
run: terraform fmt -check
66+
# Checks that all Terraform configuration files adhere to a canonical format
67+
- name: Terraform Format
68+
run: terraform fmt -check
6369

64-
- name: Terraform Plan
65-
id: plan
66-
run: |
67-
terraform plan -input=false -no-color -var-file="${{vars.TF_VARS_FILE}}" -out tf.plan
68-
working-directory: ./infrastructure
69-
shell: bash
70+
- name: Terraform Plan
71+
id: plan
72+
run: |
73+
terraform plan -input=false -no-color -var-file="${{vars.TF_VARS_FILE}}" -out tf.plan
74+
working-directory: ./infrastructure
75+
shell: bash
7076

71-
- name: Terraform Apply
72-
run: terraform apply -auto-approve -input=false tf.plan
73-
working-directory: ./infrastructure
74-
75-
77+
- name: Terraform Apply
78+
run: terraform apply -auto-approve -input=false tf.plan
79+
working-directory: ./infrastructure
Lines changed: 75 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 'Deploy to Pre-Prod'
1+
name: "Deploy to Pre-Prod"
22

33
on:
44
workflow_dispatch:
@@ -12,8 +12,8 @@ on:
1212
permissions:
1313
pull-requests: write
1414
id-token: write # This is required for requesting the JWT
15-
contents: read # This is required for actions/checkout
16-
15+
contents: read # This is required for actions/checkout
16+
1717
jobs:
1818
tag_and_release:
1919
runs-on: ubuntu-latest
@@ -22,75 +22,81 @@ jobs:
2222
permissions: write-all
2323

2424
steps:
25-
- name: Checkout main
26-
if: ${{ github.event.inputs.branch_or_tag == 'main' }}
27-
uses: actions/checkout@v5
28-
with:
29-
ref: main
30-
fetch-depth: '0'
31-
32-
- name: Bump version and push tag
33-
if: ${{ github.event.inputs.branch_or_tag == 'main' }}
34-
id: versioning
35-
uses: anothrNick/[email protected]
36-
env:
37-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38-
WITH_V: false
39-
DEFAULT_BUMP: patch
40-
41-
- name: View outputs
42-
run: |
43-
echo Deploying branch or tagged version to pre-prod: ${{ steps.versioning.outputs.tag || github.event.inputs.branch_or_tag }}
25+
- name: Checkout main
26+
if: ${{ github.event.inputs.branch_or_tag == 'main' }}
27+
uses: actions/checkout@v4
28+
with:
29+
ref: main
30+
fetch-depth: "0"
31+
32+
- name: Bump version and push tag
33+
if: ${{ github.event.inputs.branch_or_tag == 'main' }}
34+
id: versioning
35+
uses: anothrNick/[email protected]
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
WITH_V: false
39+
DEFAULT_BUMP: patch
40+
41+
- name: View outputs
42+
run: |
43+
echo Deploying branch or tagged version to pre-prod: ${{ steps.versioning.outputs.tag || github.event.inputs.branch_or_tag }}
4444
4545
terraform_process:
4646
runs-on: ubuntu-latest
47-
needs: ['tag_and_release']
47+
needs: ["tag_and_release"]
4848
environment: pre-prod
4949

5050
steps:
51-
- name: Checkout
52-
uses: actions/checkout@v5
53-
with:
54-
ref: ${{needs.tag_and_release.outputs.version}}
55-
fetch-depth: '0'
56-
57-
- name: Configure AWS Credentials
58-
uses: aws-actions/configure-aws-credentials@v4
59-
with:
60-
role-to-assume: ${{ secrets.AWS_ASSUME_ROLE }}
61-
role-skip-session-tagging: true
62-
aws-region: ${{ vars.AWS_REGION }}
63-
mask-aws-account-id: true
64-
65-
- name: Setup Terraform
66-
uses: hashicorp/setup-terraform@v3
67-
with:
68-
terraform_version: 1.11.4
69-
terraform_wrapper: false
70-
71-
- name: Terraform Init
72-
id: init
73-
run: terraform init -backend-config=backend-pre-prod.conf
74-
working-directory: ./infrastructure
75-
shell: bash
76-
77-
- name: Terraform Set Workspace
78-
id: workspace
79-
run: terraform workspace select ${{ secrets.AWS_WORKSPACE }}
80-
working-directory: ./infrastructure
81-
shell: bash
82-
83-
- name: Terraform Format
84-
run: terraform fmt -check
85-
working-directory: ./infrastructure
86-
87-
- name: Terraform Plan
88-
id: plan
89-
run: |
90-
terraform plan -input=false -no-color -var-file="${{vars.TF_VARS_FILE}}" -out tf.plan
91-
working-directory: ./infrastructure
92-
shell: bash
93-
94-
- name: Terraform Apply
95-
run: terraform apply -auto-approve -input=false tf.plan
96-
working-directory: ./infrastructure
51+
- name: Checkout
52+
uses: actions/checkout@v4
53+
with:
54+
ref: ${{needs.tag_and_release.outputs.version}}
55+
fetch-depth: "0"
56+
57+
- name: Configure AWS Credentials
58+
uses: aws-actions/configure-aws-credentials@v4
59+
with:
60+
role-to-assume: ${{ secrets.AWS_ASSUME_ROLE }}
61+
role-skip-session-tagging: true
62+
aws-region: ${{ vars.AWS_REGION }}
63+
mask-aws-account-id: true
64+
65+
- name: Setup Terraform
66+
uses: hashicorp/setup-terraform@v3
67+
with:
68+
terraform_version: 1.11.4
69+
terraform_wrapper: false
70+
71+
- name: Terraform Init
72+
id: init
73+
run: terraform init -backend-config=backend-pre-prod.conf
74+
working-directory: ./infrastructure
75+
shell: bash
76+
77+
- name: Terraform Set Workspace
78+
id: workspace
79+
run: terraform workspace select ${{ secrets.AWS_WORKSPACE }}
80+
working-directory: ./infrastructure
81+
shell: bash
82+
83+
- name: Lambda Layer Imports
84+
id: lambda_layer_import
85+
run: ./import_lambda_layers.sh ${{ secrets.AWS_WORKSPACE }} ${{ vars.TF_VARS_FILE }}
86+
working-directory: ./scripts
87+
shell: bash
88+
89+
- name: Terraform Format
90+
run: terraform fmt -check
91+
working-directory: ./infrastructure
92+
93+
- name: Terraform Plan
94+
id: plan
95+
run: |
96+
terraform plan -input=false -no-color -var-file="${{vars.TF_VARS_FILE}}" -out tf.plan
97+
working-directory: ./infrastructure
98+
shell: bash
99+
100+
- name: Terraform Apply
101+
run: terraform apply -auto-approve -input=false tf.plan
102+
working-directory: ./infrastructure

0 commit comments

Comments
 (0)