Skip to content

Commit bee9169

Browse files
CCM-10922 supplier api bc (#48)
* CCM-10922 adding initial resources * CCM-10922 Adding Suppliers API starting point * CCM-10922 Adding Suppliers API starting point * CCM-10922 Adding Suppliers API starting point * CCM-10922 Adding Suppliers API starting point * CCM-10922 fixing npm lock
1 parent fb71052 commit bee9169

29 files changed

Lines changed: 4489 additions & 4773 deletions

.github/workflows/pr_closed.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: PR Closed
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
types: [closed]
7+
branches:
8+
- main
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: false
13+
14+
jobs:
15+
check-merge-or-workflow-dispatch:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
deploy: ${{ steps.check.outputs.deploy }}
19+
steps:
20+
- name: Check if PR was merged or workflow is triggered by workflow_dispatch
21+
id: check
22+
run: |
23+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
24+
echo "deploy=true" >> $GITHUB_OUTPUT
25+
echo "Job triggered by workflow_dispatch - running 'deploy-main'"
26+
elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.merged }}" == "true" ]]; then
27+
echo "deploy=true" >> $GITHUB_OUTPUT
28+
echo "Job triggered by Merged PR - running 'deploy-main'"
29+
else
30+
echo "deploy=false" >> $GITHUB_OUTPUT
31+
echo "Job not triggered by workflow_dispatch or Merged PR - Skipping 'deploy-main'"
32+
fi
33+
34+
deploy-main:
35+
needs: check-merge-or-workflow-dispatch
36+
name: Deploy changes to main in dev AWS account
37+
if: needs.check-merge-or-workflow-dispatch.outputs.deploy == 'true'
38+
39+
permissions:
40+
id-token: write
41+
contents: read
42+
43+
strategy:
44+
max-parallel: 1
45+
matrix:
46+
component: [api]
47+
48+
uses: ./.github/workflows/reusable_internal_repo_build.yaml
49+
secrets: inherit
50+
with:
51+
releaseVersion: main
52+
targetWorkflow: "dispatch-deploy-static-notify-web-supplier-api-env.yaml"
53+
targetEnvironment: "main"
54+
targetAccountGroup: "nhs-notify-supplier-api-dev"
55+
targetComponent: ${{ matrix.component }}
56+
terraformAction: "apply"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: PR Create Environment
2+
3+
on:
4+
pull_request:
5+
types: [labeled, opened, synchronize, reopened, unlabeled, edited]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: false
10+
11+
jobs:
12+
create-dynamic-environment:
13+
name: Create Dynamic Environment
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Trigger nhs-notify-internal dynamic environment workflow
18+
shell: bash
19+
run: |
20+
set -x
21+
this_repo_name=$(echo ${{ github.repository }} | cut -d'/' -f2)
22+
23+
DISPATCH_EVENT=$(jq -ncM \
24+
--arg infraRepoName "${this_repo_name}" \
25+
--arg releaseVersion "${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" \
26+
--arg targetEnvironment "pr${{ github.event.number }}" \
27+
--arg targetAccountGroup "nhs-notify-supplier-api-dev" \
28+
--arg targetComponent "branch" \
29+
--arg terraformAction "apply" \
30+
--arg overrides "branch_name=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" \
31+
'{ "ref": "main",
32+
"inputs": {
33+
"infraRepoName": $infraRepoName,
34+
"releaseVersion", $releaseVersion,
35+
"targetEnvironment", $targetEnvironment,
36+
"targetAccountGroup", $targetAccountGroup,
37+
"targetComponent", $targetComponent,
38+
"terraformAction", $terraformAction,
39+
"overrides", $overrides,
40+
}
41+
}')
42+
43+
curl --fail -L \
44+
-X POST \
45+
-H "Accept: application/vnd.github+json" \
46+
-H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
47+
-H "X-GitHub-Api-Version: 2022-11-28" \
48+
https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/workflows/dispatch-deploy-dynamic-env.yaml/dispatches \
49+
-d "${DISPATCH_EVENT}"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
- name: Trigger nhs-notify-internal dynamic environment destruction
18+
shell: bash
19+
run: |
20+
set -x
21+
this_repo_name=$(echo ${{ github.repository }} | cut -d'/' -f2)
22+
23+
DISPATCH_EVENT=$(jq -ncM \
24+
--arg infraRepoName "${this_repo_name}" \
25+
--arg releaseVersion "main" \
26+
--arg targetEnvironment "pr${{ github.event.number }}" \
27+
--arg targetAccountGroup "nhs-notify-supplier-api-dev" \
28+
--arg targetComponent "branch" \
29+
--arg terraformAction "destroy" \
30+
'{ "ref": "main",
31+
"inputs": {
32+
"infraRepoName": $infraRepoName,
33+
"releaseVersion", $releaseVersion,
34+
"targetEnvironment", $targetEnvironment,
35+
"targetAccountGroup", $targetAccountGroup,
36+
"targetComponent", $targetComponent,
37+
"terraformAction", $terraformAction,
38+
}
39+
}')
40+
41+
curl --fail -L \
42+
-X POST \
43+
-H "Accept: application/vnd.github+json" \
44+
-H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
45+
-H "X-GitHub-Api-Version: 2022-11-28" \
46+
https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/workflows/dispatch-deploy-dynamic-env.yaml/dispatches \
47+
-d "${DISPATCH_EVENT}"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Github Release Created
2+
3+
on:
4+
release:
5+
types: ["published"] # Inherits all input defaults
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: false
10+
11+
jobs:
12+
deploy-main:
13+
name: Deploy changes to main in nonprod AWS Account
14+
15+
permissions:
16+
id-token: write
17+
contents: read
18+
19+
strategy:
20+
max-parallel: 1
21+
matrix:
22+
component: [api]
23+
24+
uses: ./.github/workflows/reusable_internal_repo_build.yaml
25+
secrets: inherit
26+
with:
27+
releaseVersion: ${{ github.event.release.tag_name }}
28+
targetWorkflow: "dispatch-deploy-static-notify-supliers-api-env.yaml"
29+
targetEnvironment: "main"
30+
targetAccountGroup: "nhs-notify-supliers-api-nonprod"
31+
targetComponent: ${{ matrix.component }}
32+
terraformAction: "apply"
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
name: Call Notify Internal Infrastructure Deployment
2+
## Sub workflow which plans and deploys Notify components as part of the workflow.
3+
## Review Gates may be required to proceed on triggered builds.
4+
5+
on:
6+
workflow_call:
7+
inputs:
8+
releaseVersion:
9+
type: string
10+
description: The Github release version, commit, or tag.
11+
default: main
12+
targetWorkflow:
13+
type: string
14+
description: The name of the github workflow to call.
15+
default: main
16+
targetEnvironment:
17+
type: string
18+
description: The Terraform environment to deploy
19+
default: main
20+
targetComponent:
21+
type: string
22+
description: The Terraform component to deploy
23+
required: true
24+
targetAccountGroup:
25+
type: string
26+
description: The Terraform group to deploy
27+
required: true
28+
terraformAction:
29+
type: string
30+
description: The Terraform component to deploy
31+
default: plan
32+
33+
concurrency:
34+
group: ${{ inputs.targetEnvironment }}-${{ inputs.targetAccountGroup }}-${{ inputs.targetComponent }}-${{ inputs.terraformAction }}
35+
36+
jobs:
37+
trigger:
38+
runs-on: ubuntu-latest
39+
40+
permissions:
41+
id-token: write
42+
contents: read
43+
44+
steps:
45+
- uses: actions/checkout@v4
46+
47+
- name: Trigger nhs-notify-internal static environment workflow deployment
48+
shell: bash
49+
run: |
50+
set -x
51+
52+
DISPATCH_EVENT=$(jq -ncM \
53+
--arg releaseVersion ${{ inputs.releaseVersion }} \
54+
--arg targetEnvironment ${{ inputs.targetEnvironment }} \
55+
--arg targetAccountGroup ${{ inputs.targetAccountGroup }} \
56+
--arg targetComponent ${{ inputs.targetComponent }} \
57+
--arg terraformAction ${{ inputs.terraformAction }} \
58+
'{ "ref": "main",
59+
"inputs": {
60+
"releaseVersion", $releaseVersion,
61+
"targetEnvironment", $targetEnvironment,
62+
"targetAccountGroup", $targetAccountGroup,
63+
"targetComponent", $targetComponent,
64+
"terraformAction", $terraformAction
65+
}
66+
}')
67+
68+
# Trigger The workflow
69+
curl -L \
70+
--fail \
71+
--silent \
72+
-X POST \
73+
-H "Accept: application/vnd.github+json" \
74+
-H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
75+
-H "X-GitHub-Api-Version: 2022-11-28" \
76+
"https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/workflows/${{ inputs.targetWorkflow }}/dispatches" \
77+
-d "${DISPATCH_EVENT}"
78+
79+
echo "Workflow triggered successfully. HTTP response. Waiting for the workflow to complete.."
80+
81+
# Poll GitHub API to check the workflow status
82+
run_id=""
83+
for i in {1..12}; do
84+
in_progress=$(curl -s \
85+
-H "Accept: application/vnd.github+json" \
86+
-H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
87+
-H "X-GitHub-Api-Version: 2022-11-28" \
88+
"https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/runs?event=workflow_dispatch&status=in_progress")
89+
90+
run_id=$(echo "$in_progress" | jq -r \
91+
--arg env "${{ inputs.targetEnvironment }}" \
92+
--arg component "${{ inputs.targetComponent }}" \
93+
--arg group "${{ inputs.targetAccountGroup }}" \
94+
--arg releaseVersion "${{ inputs.releaseVersion }}" \
95+
'.workflow_runs[]
96+
| select(.name | contains($env) and contains($component) and contains($group) and contains($releaseVersion))
97+
| .id' | head -n 1)
98+
99+
if [[ -n "$run_id" && "$run_id" != null ]]; then
100+
echo "Found workflow run with ID: $run_id"
101+
break
102+
fi
103+
104+
echo "Waiting for workflow to start..."
105+
sleep 10
106+
done
107+
108+
if [[ -z "$run_id" || "$run_id" == null ]]; then
109+
echo "Failed to get the workflow run ID. Exiting."
110+
exit 1
111+
fi
112+
113+
# Wait for workflow completion
114+
while true; do
115+
sleep 10
116+
status=$(curl -s \
117+
-H "Accept: application/vnd.github+json" \
118+
-H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
119+
-H "X-GitHub-Api-Version: 2022-11-28" \
120+
"https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/runs/$run_id" \
121+
| jq -r '.status')
122+
123+
conclusion=$(curl -s \
124+
-H "Accept: application/vnd.github+json" \
125+
-H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
126+
-H "X-GitHub-Api-Version: 2022-11-28" \
127+
"https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/runs/$run_id" \
128+
| jq -r '.conclusion')
129+
130+
if [ "$status" == "completed" ]; then
131+
if [ "$conclusion" == "success" ]; then
132+
echo "Workflow completed successfully."
133+
exit 0
134+
else
135+
echo "Workflow failed with conclusion: $conclusion"
136+
exit 1
137+
fi
138+
fi
139+
140+
echo "Workflow still running..."
141+
sleep 20
142+
done

.tool-versions

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
act 0.2.64
2-
editorconfig-checker 3.3.0
32
gitleaks 8.24.0
43
jq 1.6
5-
markdownlint-cli2 0.18.1
64
nodejs 22.11.0
75
pnpm 10.4.1
86
pre-commit 3.6.0

infrastructure/terraform/bin/terraform.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ readonly component_name=$(basename ${component_path});
403403
# verify terraform version matches .tool-versions
404404
echo ${PWD}
405405
tool_version=$(grep "terraform " .tool-versions | cut -d ' ' -f 2)
406-
asdf plugin-add terraform && asdf install terraform "${tool_version}"
406+
asdf plugin add terraform && asdf install terraform "${tool_version}"
407407
current_version=$(terraform --version | head -n 1 | cut -d 'v' -f 2)
408408

409409
if [ -z "${current_version}" ] || [ "${current_version}" != "${tool_version}" ]; then

infrastructure/terraform/components/examplecomponent/.tool-versions renamed to infrastructure/terraform/components/api/.tool-versions

File renamed without changes.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ 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 |
13+
| <a name="input_component"></a> [component](#input\_component) | The variable encapsulating the name of this component | `string` | `"supapi"` | no |
1414
| <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 |
1515
| <a name="input_environment"></a> [environment](#input\_environment) | The name of the tfscaffold environment | `string` | n/a | yes |
1616
| <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 |

infrastructure/terraform/components/examplecomponent/locals_remote_state.tf renamed to infrastructure/terraform/components/api/locals_remote_state.tf

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
locals {
22
bootstrap = data.terraform_remote_state.bootstrap.outputs
3-
acct = data.terraform_remote_state.acct.outputs
43
}
54

65
data "terraform_remote_state" "bootstrap" {
@@ -21,20 +20,3 @@ data "terraform_remote_state" "bootstrap" {
2120
}
2221
}
2322

24-
data "terraform_remote_state" "acct" {
25-
backend = "s3"
26-
27-
config = {
28-
bucket = local.terraform_state_bucket
29-
30-
key = format(
31-
"%s/%s/%s/%s/acct.tfstate",
32-
var.project,
33-
var.aws_account_id,
34-
"eu-west-2",
35-
var.parent_acct_environment
36-
)
37-
38-
region = "eu-west-2"
39-
}
40-
}

0 commit comments

Comments
 (0)