Skip to content

Commit 75f15b6

Browse files
committed
Merge in main
2 parents 2d8fd9e + 71f73c9 commit 75f15b6

59 files changed

Lines changed: 1158 additions & 264 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/cicd-1-pull-request.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ name: "CI/CD pull request"
33
# The total recommended execution time for the "CI/CD Pull Request" workflow is around 20 minutes.
44

55
on:
6-
push:
7-
branches:
8-
- "**"
96
pull_request:
10-
types: [opened, reopened]
7+
types: [opened, synchronize, reopened]
118

129
jobs:
1310
metadata:
11+
if: github.event.pull_request.draft == false
1412
name: "Set CI/CD metadata"
1513
runs-on: ubuntu-latest
1614
timeout-minutes: 1
@@ -69,6 +67,7 @@ jobs:
6967
make list-variables
7068
commit-stage: # Recommended maximum execution time is 2 minutes
7169
name: "Commit stage"
70+
if: github.event.pull_request.draft == false
7271
needs: [metadata]
7372
uses: ./.github/workflows/stage-1-commit.yaml
7473
with:
@@ -82,6 +81,7 @@ jobs:
8281
secrets: inherit
8382
test-stage: # Recommended maximum execution time is 5 minutes
8483
name: "Test stage"
84+
if: github.event.pull_request.draft == false
8585
needs: [metadata, commit-stage]
8686
uses: ./.github/workflows/stage-2-test.yaml
8787
with:

.github/workflows/cicd-2-publish.yaml

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ on:
99
branches:
1010
- main
1111

12+
concurrency:
13+
group: terraform-dev
14+
cancel-in-progress: false
15+
1216
jobs:
1317
metadata:
1418
name: "Set CI/CD metadata"
@@ -100,10 +104,10 @@ jobs:
100104
# just planning for now for safety and until review
101105
run: |
102106
mkdir -p ./build
103-
echo "Running: make terraform env=$ENVIRONMENT workspace=$WORKSPACE stack=networking tf-command=plan"
104-
make terraform env=$ENVIRONMENT stack=networking tf-command=plan workspace=$WORKSPACE
105-
echo "Running: make terraform env=$ENVIRONMENT workspace=$WORKSPACE stack=api-layer tf-command=plan"
106-
make terraform env=$ENVIRONMENT stack=api-layer tf-command=plan workspace=$WORKSPACE
107+
echo "Running: make terraform env=$ENVIRONMENT workspace=$WORKSPACE stack=networking tf-command=apply"
108+
make terraform env=$ENVIRONMENT stack=networking tf-command=apply workspace=$WORKSPACE
109+
echo "Running: make terraform env=$ENVIRONMENT workspace=$WORKSPACE stack=api-layer tf-command=apply"
110+
make terraform env=$ENVIRONMENT stack=api-layer tf-command=apply workspace=$WORKSPACE
107111
working-directory: ./infrastructure
108112

109113
- name: "Tag the dev deployment"
@@ -136,20 +140,14 @@ jobs:
136140
# asset_path: ./build/lambda.zip
137141
# asset_name: lambda-${{ needs.metadata.outputs.version }}.zip
138142
# asset_content_type: application/zip
139-
success:
140-
name: "Success notification"
141-
runs-on: ubuntu-latest
142-
needs: [publish]
143-
steps:
144-
- name: "Check prerequisites for notification"
145-
id: check
146-
run: echo "secret_exist=${{ secrets.TEAMS_NOTIFICATION_WEBHOOK_URL != '' }}" >> $GITHUB_OUTPUT
147-
- name: "Notify on publishing packages"
148-
if: steps.check.outputs.secret_exist == 'true'
149-
uses: nhs-england-tools/notify-msteams-action@v1.0.0
143+
- name: "Notify Slack on PR merge"
144+
uses: slackapi/slack-github-action@v2.1.0
150145
with:
151-
github-token: ${{ secrets.GITHUB_TOKEN }}
152-
teams-webhook-url: ${{ secrets.TEAMS_NOTIFICATION_WEBHOOK_URL }}
153-
message-title: "Notification title"
154-
message-text: "This is a notification body"
155-
link: ${{ github.event.pull_request.html_url }}
146+
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
147+
webhook-type: webhook-trigger
148+
payload: |
149+
status: "${{ job.status }}"
150+
link: "https://github.com/${{ github.repository }}/commit/${{ github.sha }}"
151+
Author: "${{ github.actor }}"
152+
title: "Pushed to main"
153+
version: "${{ needs.metadata.outputs.version }}"

.github/workflows/cicd-3-deploy.yaml

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
name: "CI/CD deploy"
55

6+
concurrency:
7+
group: terraform-deploy-${{ github.event.inputs.environment }}
8+
cancel-in-progress: false
9+
610
on:
711
workflow_dispatch:
812
inputs:
@@ -18,6 +22,15 @@ on:
1822
- test
1923
- preprod
2024
- prod
25+
release_type:
26+
description: "Version bump type (patch, minor, major)"
27+
required: false
28+
default: "patch"
29+
type: choice
30+
options:
31+
- patch
32+
- minor
33+
- major
2134

2235
jobs:
2336
metadata:
@@ -70,7 +83,7 @@ jobs:
7083
timeout-minutes: 10
7184
permissions:
7285
id-token: write
73-
contents: read
86+
contents: write
7487
steps:
7588
- name: "Setup Terraform"
7689
uses: hashicorp/setup-terraform@v3
@@ -124,7 +137,21 @@ jobs:
124137
else
125138
# Extract the version numbers
126139
IFS='.' read -r major minor patch <<< "${latest_tag#v}"
127-
patch=$((patch + 1))
140+
case "${{ github.event.inputs.release_type }}" in
141+
major)
142+
major=$((major + 1))
143+
minor=0
144+
patch=0
145+
;;
146+
minor)
147+
minor=$((minor + 1))
148+
patch=0
149+
;;
150+
patch|*)
151+
patch=$((patch + 1))
152+
;;
153+
esac
154+
128155
next_tag="v${major}.${minor}.${patch}"
129156
fi
130157
@@ -136,8 +163,8 @@ jobs:
136163
env:
137164
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
138165
with:
139-
tag_name: ${{ steps.next_tag.outputs.next_tag }}
140-
release_name: Release ${{ steps.next_tag.outputs.next_tag }}
166+
tag_name: ${{ steps.next_tag.outputs.tag }}
167+
release_name: Release ${{ steps.next_tag.outputs.tag }}
141168
body: |
142169
Auto-release created during deployment.
143170
draft: false

.github/workflows/stage-1-commit.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,14 @@ jobs:
9797
uses: bridgecrewio/checkov-action@v12
9898
with:
9999
directory: infrastructure/
100-
soft_fail: true
100+
soft_fail: false
101101
output_format: sarif
102102
output_file_path: checkov-report.sarif
103+
- name: Upload Checkov results to GitHub Security tab
104+
uses: actions/upload-artifact@v4
105+
with:
106+
name: checkov_results
107+
path: checkov-report.sarif
103108
count-lines-of-code:
104109
name: "Count lines of code"
105110
runs-on: ubuntu-latest

infrastructure/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ terraform-workspace-delete: guard-env guard-stack
3535

3636
# Runs a specified Terraform command (e.g., plan, apply) for the stack and environment.
3737
terraform: guard-env guard-stack guard-tf-command terraform-init terraform-workspace
38-
terraform -chdir=./stacks/$(stack) $(tf-command) $(args) $(if $(filter $(tf-command),init),,--parallelism=30)
38+
terraform -chdir=./stacks/$(stack) $(tf-command) $(args) \
39+
$(if $(filter init,$(tf-command)),,--parallelism=30) \
40+
$(if $(filter apply,$(tf-command)),-auto-approve)
3941
rm -f ./terraform_outputs_$(stack).json || true
4042
mkdir -p ./build
4143
terraform -chdir=./stacks/$(stack) output -json > ./build/terraform_outputs_$(stack).json

infrastructure/modules/api_gateway/cloudwatch.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
resource "aws_cloudwatch_log_group" "api_gateway" {
22
name = "/aws/apigateway/${var.workspace}-${var.api_gateway_name}"
3-
retention_in_days = 14
3+
retention_in_days = 365
44
tags = var.tags
55
kms_key_id = aws_kms_key.api_gateway.arn
66

infrastructure/modules/api_gateway/iam.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ data "aws_iam_policy_document" "api_gateway_logging" {
2727
"logs:GetLogEvents",
2828
"logs:FilterLogEvents"
2929
]
30-
resources = ["*"]
30+
resources = [aws_cloudwatch_log_group.api_gateway.arn]
3131
}
3232
}
3333

infrastructure/modules/api_gateway/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ output "logging_policy_attachment" {
2525
output "iam_role_name" {
2626
value = aws_iam_role.api_gateway.name
2727
}
28+
29+
output "kms_key_arn" {
30+
value = aws_kms_key.api_gateway.arn
31+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data "aws_caller_identity" "current" {}

infrastructure/modules/bootstrap/tfstate/kms.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,21 @@ resource "aws_kms_alias" "terraform_state_bucket_cmk" {
1010
name = "alias/${var.project_name}-tfstate_bucket_cmk"
1111
target_key_id = aws_kms_key.terraform_state_bucket_cmk.key_id
1212
}
13+
14+
resource "aws_kms_key_policy" "terraform_state_bucket_cmk" {
15+
key_id = aws_kms_key.terraform_state_bucket_cmk.id
16+
policy = data.aws_iam_policy_document.terraform_state_bucket_cmk.json
17+
}
18+
19+
data "aws_iam_policy_document" "terraform_state_bucket_cmk" {
20+
statement {
21+
sid = "Enable IAM User Permissions for s3 buckets"
22+
effect = "Allow"
23+
principals {
24+
type = "AWS"
25+
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"]
26+
}
27+
actions = ["kms:*"]
28+
resources = [aws_kms_key.terraform_state_bucket_cmk.arn]
29+
}
30+
}

0 commit comments

Comments
 (0)