Skip to content

Commit 4e99e84

Browse files
CCM-12722 Digital Letters initial workflows and infra (#70)
* CCM-12722 Digital Letters initial workflows and infra * CCM-12722 Drop example lambda * CCM-12722 Drop example lambda * CCM-12722 Digital Letters initial workflows and infra * CCM-12722 Digital Letters initial workflows and infra * CCM-12722 Digital Letters initial workflows and infra
1 parent f2b16a5 commit 4e99e84

36 files changed

Lines changed: 480 additions & 196 deletions

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ on:
1111
branches:
1212
- main
1313

14+
permissions:
15+
id-token: write
16+
contents: write
17+
1418
jobs:
1519
metadata:
1620
name: "Set CI/CD metadata"
@@ -27,6 +31,7 @@ jobs:
2731
version: ${{ steps.variables.outputs.version }}
2832
is_version_prerelease: ${{ steps.variables.outputs.is_version_prerelease }}
2933
does_pull_request_exist: ${{ steps.pr_exists.outputs.does_pull_request_exist }}
34+
pr_number: ${{ steps.pr_exists.outputs.pr_number }}
3035
steps:
3136
- name: "Checkout code"
3237
uses: actions/checkout@v5
@@ -53,13 +58,20 @@ jobs:
5358
run: |
5459
branch_name=${GITHUB_HEAD_REF:-$(echo $GITHUB_REF | sed 's#refs/heads/##')}
5560
echo "Current branch is '$branch_name'"
56-
if gh pr list --head $branch_name | grep -q .; then
57-
echo "Pull request exists"
61+
62+
pr_json=$(gh pr list --head "$branch_name" --state open --json number --limit 1)
63+
pr_number=$(echo "$pr_json" | jq -r '.[0].number // empty')
64+
65+
if [[ -n "$pr_number" ]]; then
66+
echo "Pull request exists: #$pr_number"
5867
echo "does_pull_request_exist=true" >> $GITHUB_OUTPUT
68+
echo "pr_number=$pr_number" >> $GITHUB_OUTPUT
5969
else
6070
echo "Pull request doesn't exist"
6171
echo "does_pull_request_exist=false" >> $GITHUB_OUTPUT
72+
echo "pr_number=" >> $GITHUB_OUTPUT
6273
fi
74+
6375
- name: "List variables"
6476
run: |
6577
export BUILD_DATETIME_LONDON="${{ steps.variables.outputs.build_datetime_london }}"
@@ -113,6 +125,29 @@ jobs:
113125
terraform_version: "${{ needs.metadata.outputs.terraform_version }}"
114126
version: "${{ needs.metadata.outputs.version }}"
115127
secrets: inherit
128+
pr-create-dynamic-environment:
129+
name: Trigger dynamic environment creation
130+
needs: [metadata, build-stage]
131+
runs-on: ubuntu-latest
132+
if: needs.metadata.outputs.does_pull_request_exist == 'true' || (github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened'))
133+
steps:
134+
- uses: actions/checkout@v5.0.0
135+
- name: Trigger dynamic environment creation
136+
env:
137+
PR_TRIGGER_PAT: ${{ secrets.PR_TRIGGER_PAT }}
138+
shell: bash
139+
run: |
140+
.github/scripts/dispatch_internal_repo_workflow.sh \
141+
--infraRepoName "$(echo ${{ github.repository }} | cut -d'/' -f2)" \
142+
--releaseVersion "${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" \
143+
--targetWorkflow "dispatch-deploy-dynamic-env.yaml" \
144+
--targetEnvironment "pr${{ needs.metadata.outputs.pr_number }}" \
145+
--targetComponent "dl" \
146+
--targetAccountGroup "nhs-notify-digital-letters-dev" \
147+
--terraformAction "apply" \
148+
--overrideProjectName "nhs" \
149+
--overrideRoleName "nhs-main-acct-digital-letters-github-deploy" \
150+
--overrides "branch_name=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
116151
acceptance-stage: # Recommended maximum execution time is 10 minutes
117152
name: "Acceptance stage"
118153
needs: [metadata, build-stage]
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
## This workflow is DISABLED.
2-
## To enable, rename from .disabled to .yaml and replace any references as per the comments.
31
name: PR Closed
42

53
on:
@@ -46,7 +44,7 @@ jobs:
4644
strategy:
4745
max-parallel: 1
4846
matrix:
49-
component: [acct, app]
47+
component: [dl]
5048

5149
steps:
5250
- name: Checkout repository
@@ -58,8 +56,8 @@ jobs:
5856
run: |
5957
bash .github/scripts/dispatch_internal_repo_workflow.sh \
6058
--releaseVersion "main" \
61-
--targetWorkflow "dispatch-deploy-static-notify-bounded-context-env.yaml" ## Replace with correct targetWorkflow \
59+
--targetWorkflow "dispatch-deploy-static-notify-digital-letters-env.yaml" \
6260
--targetEnvironment "main" \
63-
--targetAccountGroup "nhs-notify-bounded-context-dev" ## Replace with correct targetAccountGroup \
61+
--targetAccountGroup "nhs-notify-digital-letters-dev" \
6462
--targetComponent "${{ matrix.component }}" \
6563
--terraformAction "apply"

.github/workflows/pr_create_dynamic_env.disabled

Lines changed: 0 additions & 51 deletions
This file was deleted.

.github/workflows/pr_destroy_dynamic_env.disabled

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: PR Destroy Environment
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: false
10+
11+
jobs:
12+
create-dynamic-environment:
13+
name: Destroy Dynamic Environment
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v5.0.0
18+
- name: Trigger dynamic environment creation
19+
env:
20+
PR_TRIGGER_PAT: ${{ secrets.PR_TRIGGER_PAT }}
21+
shell: bash
22+
run: |
23+
.github/scripts/dispatch_internal_repo_workflow.sh \
24+
--infraRepoName "$(echo ${{ github.repository }} | cut -d'/' -f2)" \
25+
--releaseVersion "${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" \
26+
--targetWorkflow "dispatch-deploy-dynamic-env.yaml" \
27+
--targetEnvironment "pr${{ github.event.number }}" \
28+
--targetComponent "dl" \
29+
--targetAccountGroup "nhs-notify-digital-letters-dev" \
30+
--terraformAction "destroy" \
31+
--overrideProjectName "nhs" \
32+
--overrideRoleName "nhs-main-acct-digital-letters-github-deploy" \
33+
--overrides "branch_name=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"

.github/workflows/release_created.disabled renamed to .github/workflows/release_created.yaml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
## This workflow is DISABLED.
2-
## To enable, rename from .disabled to .yaml and replace any references as per the comments.
31
name: Github Release Created
42

53
on:
@@ -22,20 +20,30 @@ jobs:
2220
strategy:
2321
max-parallel: 1
2422
matrix:
25-
component: [component1, component2] ## Replace with correct components
23+
component: [dl]
2624

2725
steps:
2826
- name: Checkout repository
2927
uses: actions/checkout@v5.0.0
3028

31-
- name: Updating Main Environment
29+
- name: Deploy Nonprod Environment
3230
env:
3331
PR_TRIGGER_PAT: ${{ secrets.PR_TRIGGER_PAT }}
3432
run: |
3533
bash .github/scripts/dispatch_internal_repo_workflow.sh \
3634
--releaseVersion "${{ github.event.release.tag_name }}" \
37-
--targetWorkflow "dispatch-deploy-static-notify-bounded-context-env.yaml" ## Replace with correct targetWorkflow \
35+
--targetWorkflow "dispatch-deploy-static-notify-digital-letters-env.yaml" \
3836
--targetEnvironment "main" \
39-
--targetAccountGroup "nhs-notify-bounded-context-nonprod" ## Replace with correct targetAccountGroup \
37+
--targetAccountGroup "nhs-notify-digital-letters-nonprod" \
4038
--targetComponent "${{ matrix.component }}" \
4139
--terraformAction "apply"
40+
41+
acceptance-stage:
42+
name: "Acceptance stage"
43+
needs: [deploy-main]
44+
uses: ./.github/workflows/stage-4-acceptance.yaml
45+
secrets:
46+
PR_TRIGGER_PAT: ${{ secrets.PR_TRIGGER_PAT }}
47+
with:
48+
target_environment: "main"
49+
target_account_group: nhs-notify-digital-letters-nonprod
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
terraform 1.10.1

infrastructure/terraform/components/examplecomponent/README.md renamed to infrastructure/terraform/components/dl/README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,24 @@ No requirements.
1010
| Name | Description | Type | Default | Required |
1111
|------|-------------|------|---------|:--------:|
1212
| <a name="input_aws_account_id"></a> [aws\_account\_id](#input\_aws\_account\_id) | The AWS Account ID (numeric) | `string` | n/a | yes |
13-
| <a name="input_component"></a> [component](#input\_component) | The variable encapsulating the name of this component | `string` | `"examplecomponent"` | no |
1413
| <a name="input_default_tags"></a> [default\_tags](#input\_default\_tags) | A map of default tags to apply to all taggable resources within the component | `map(string)` | `{}` | no |
1514
| <a name="input_environment"></a> [environment](#input\_environment) | The name of the tfscaffold environment | `string` | n/a | yes |
1615
| <a name="input_force_lambda_code_deploy"></a> [force\_lambda\_code\_deploy](#input\_force\_lambda\_code\_deploy) | If the lambda package in s3 has the same commit id tag as the terraform build branch, the lambda will not update automatically. Set to True if making changes to Lambda code from on the same commit for example during development | `bool` | `false` | no |
1716
| <a name="input_group"></a> [group](#input\_group) | The group variables are being inherited from (often synonmous with account short-name) | `string` | n/a | yes |
17+
| <a name="input_kms_deletion_window"></a> [kms\_deletion\_window](#input\_kms\_deletion\_window) | When a kms key is deleted, how long should it wait in the pending deletion state? | `string` | `"30"` | no |
18+
| <a name="input_log_level"></a> [log\_level](#input\_log\_level) | The log level to be used in lambda functions within the component. Any log with a lower severity than the configured value will not be logged: https://docs.python.org/3/library/logging.html#levels | `string` | `"INFO"` | no |
1819
| <a name="input_log_retention_in_days"></a> [log\_retention\_in\_days](#input\_log\_retention\_in\_days) | The retention period in days for the Cloudwatch Logs events to be retained, default of 0 is indefinite | `number` | `0` | no |
20+
| <a name="input_mesh_poll_schedule"></a> [mesh\_poll\_schedule](#input\_mesh\_poll\_schedule) | Schedule to poll MESH for messages | `string` | `"cron(0,30 8-16 ? * MON-FRI *)"` | no |
21+
| <a name="input_parent_acct_environment"></a> [parent\_acct\_environment](#input\_parent\_acct\_environment) | Name of the environment responsible for the acct resources used, affects things like DNS zone. Useful for named dev environments | `string` | `"main"` | no |
1922
| <a name="input_project"></a> [project](#input\_project) | The name of the tfscaffold project | `string` | n/a | yes |
2023
| <a name="input_region"></a> [region](#input\_region) | The AWS Region | `string` | n/a | yes |
2124
## Modules
2225

23-
No modules.
26+
| Name | Source | Version |
27+
|------|--------|---------|
28+
| <a name="module_kms"></a> [kms](#module\_kms) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-kms.zip | n/a |
29+
| <a name="module_mesh_poll"></a> [mesh\_poll](#module\_mesh\_poll) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip | n/a |
30+
| <a name="module_s3bucket_letters"></a> [s3bucket\_letters](#module\_s3bucket\_letters) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-s3bucket.zip | n/a |
2431
## Outputs
2532

2633
No outputs.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
resource "aws_cloudwatch_event_bus" "main" {
2+
name = "${local.csi}"
3+
4+
kms_key_identifier = module.kms.key_id
5+
6+
log_config {
7+
include_detail = "FULL"
8+
level = "TRACE"
9+
}
10+
}
11+
12+
# CloudWatch Log Delivery Sources for INFO, ERROR, and TRACE logs
13+
resource "aws_cloudwatch_log_delivery_source" "main_info_logs" {
14+
name = "EventBusSource-${aws_cloudwatch_event_bus.main.name}-INFO_LOGS"
15+
log_type = "INFO_LOGS"
16+
resource_arn = aws_cloudwatch_event_bus.main.arn
17+
}
18+
19+
resource "aws_cloudwatch_log_delivery_source" "main_error_logs" {
20+
name = "EventBusSource-${aws_cloudwatch_event_bus.main.name}-ERROR_LOGS"
21+
log_type = "ERROR_LOGS"
22+
resource_arn = aws_cloudwatch_event_bus.main.arn
23+
}
24+
25+
resource "aws_cloudwatch_log_delivery_source" "main_trace_logs" {
26+
name = "EventBusSource-${aws_cloudwatch_event_bus.main.name}-TRACE_LOGS"
27+
log_type = "TRACE_LOGS"
28+
resource_arn = aws_cloudwatch_event_bus.main.arn
29+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
resource "aws_cloudwatch_log_delivery_destination" "event_bus" {
2+
name = "EventsDeliveryDestination-${aws_cloudwatch_event_bus.main.name}"
3+
4+
delivery_destination_configuration {
5+
destination_resource_arn = aws_cloudwatch_log_group.event_bus.arn
6+
}
7+
}
8+
9+
resource "aws_cloudwatch_log_delivery" "events_info_logs" {
10+
delivery_destination_arn = aws_cloudwatch_log_delivery_destination.event_bus.arn
11+
delivery_source_name = aws_cloudwatch_log_delivery_source.main_info_logs.name
12+
}
13+
14+
resource "aws_cloudwatch_log_delivery" "events_error_logs" {
15+
delivery_destination_arn = aws_cloudwatch_log_delivery_destination.event_bus.arn
16+
delivery_source_name = aws_cloudwatch_log_delivery_source.main_error_logs.name
17+
depends_on = [
18+
aws_cloudwatch_log_delivery.events_info_logs
19+
]
20+
}
21+
22+
resource "aws_cloudwatch_log_delivery" "events_trace_logs" {
23+
delivery_destination_arn = aws_cloudwatch_log_delivery_destination.event_bus.arn
24+
delivery_source_name = aws_cloudwatch_log_delivery_source.main_trace_logs.name
25+
depends_on = [
26+
aws_cloudwatch_log_delivery.events_error_logs
27+
]
28+
}

0 commit comments

Comments
 (0)