Skip to content

Commit 034b6c7

Browse files
Merge pull request #615 from NHSDigital/feature/made14-NRL-619-new-qa-env
[NRL-619] Add new AWS environments for qa and qa-sandbox
2 parents ca20f72 + 4415504 commit 034b6c7

File tree

25 files changed

+295
-100
lines changed

25 files changed

+295
-100
lines changed

.github/workflows/pr-env-deploy.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ jobs:
217217
role-session-name: github-actions-ci-${{ needs.set-environment-id.outputs.environment_id }}
218218

219219
- name: Run Integration Tests
220-
run: make test-features-integration TF_WORKSPACE=${{ needs.set-environment-id.outputs.environment_id }}
220+
run: make test-features-integration TF_WORKSPACE_NAME=${{ needs.set-environment-id.outputs.environment_id }}
221221

222222
performance-test:
223223
name: Run Performance Tests
@@ -266,7 +266,7 @@ jobs:
266266
role-session-name: github-actions-ci-${{ needs.set-environment-id.outputs.environment_id }}
267267

268268
- name: Setup Environment Test Data
269-
run: make test-performance-prepare TF_WORKSPACE=${{ needs.set-environment-id.outputs.environment_id }}
269+
run: make test-performance-prepare TF_WORKSPACE_NAME=${{ needs.set-environment-id.outputs.environment_id }}
270270

271271
- name: Run Performance Test - Baseline
272272
run: make test-performance-baseline HOST=${{ needs.set-environment-id.outputs.environment_id }}.api.record-locator.dev.national.nhs.uk ENV_TYPE=dev
@@ -284,4 +284,4 @@ jobs:
284284
path: dist/*.png
285285

286286
- name: Cleanup Environment Test Data
287-
run: make test-performance-cleanup TF_WORKSPACE=${{ needs.set-environment-id.outputs.environment_id }}
287+
run: make test-performance-cleanup TF_WORKSPACE_NAME=${{ needs.set-environment-id.outputs.environment_id }}

Makefile

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ SHELL := /bin/bash
1010
DIST_PATH ?= ./dist
1111
TEST_ARGS ?= --cov --cov-report=term-missing
1212
FEATURE_TEST_ARGS ?= ./tests/features --format progress2
13-
TF_WORKSPACE ?= $(shell terraform -chdir=terraform/infrastructure workspace show)
13+
TF_WORKSPACE_NAME ?= $(shell terraform -chdir=terraform/infrastructure workspace show)
1414
ENV ?= dev
1515
APP_ALIAS ?= default
1616

@@ -76,11 +76,11 @@ test: check-warn ## Run the unit tests
7676

7777
test-features-integration: check-warn ## Run the BDD feature tests in the integration environment
7878
@echo "Running feature tests in the integration environment"
79-
behave --define="integration_test=true" --define="env=$(TF_WORKSPACE)" $(FEATURE_TEST_ARGS)
79+
behave --define="integration_test=true" --define="env=$(TF_WORKSPACE_NAME)" $(FEATURE_TEST_ARGS)
8080

8181
test-performance-prepare:
8282
mkdir -p $(DIST_PATH)
83-
poetry run python tests/performance/environment.py setup $(TF_WORKSPACE)
83+
poetry run python tests/performance/environment.py setup $(TF_WORKSPACE_NAME)
8484

8585
test-performance: check-warn test-performance-baseline test-performance-stress ## Run the performance tests
8686

@@ -102,15 +102,11 @@ test-performance-output: ## Process outputs from the performance tests
102102
poetry run python tests/performance/process_results.py stress $(DIST_PATH)/consumer-stress.csv
103103

104104
test-performance-cleanup:
105-
poetry run python tests/performance/environment.py cleanup $(TF_WORKSPACE)
106-
105+
poetry run python tests/performance/environment.py cleanup $(TF_WORKSPACE_NAME)
107106

108107
lint: check-warn ## Lint the project
109108
SKIP="no-commit-to-branch" pre-commit run --all-files
110109

111-
deploy: check-deploy-warn ## Deploy the project
112-
cd terraform/infrastructure && $(MAKE) ENV=$(ENV) TF_WORKSPACE=$(TF_WORKSPACE) apply
113-
114110
clean: ## Remove all generated and temporary files
115111
[ -n "$(DIST_PATH)" ] && \
116112
rm -rf $(DIST_PATH)/*.zip && \

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,11 @@ The `records` property is derived by first deploying to a specific environment,
423423

424424
## Sandbox
425425

426-
The public-facing sandbox is an additional persistent workspace (`int-sandbox`) deployed in our UAT (`int` / `test`) environment, alongside the persistent workspace named `ref`. It is identical to our live API, except it is open to the world via Apigee (which implements rate limiting on our behalf).
426+
The public-facing sandbox is an additional persistent workspace (`int-sandbox`) deployed in our INT (`int` / `test`) environment, alongside the persistent workspace named `ref`. It is identical to our live API, except it is open to the world via Apigee (which implements rate limiting on our behalf).
427427

428428
### Sandbox deployment
429429

430-
In order to deploy to a sandbox environment (`dev-sandbox`, `ref-sandbox`, `int-sandbox`, `production-sandbox`) you should use the GitHub Action for persistent environments, where you should select the option to deploy to the sandbox workspace.
430+
In order to deploy to a sandbox environment (`dev-sandbox`, `qa-sandbox`, `int-sandbox`) you should use the GitHub Action for persistent environments, where you should select the option to deploy to the sandbox workspace.
431431

432432
### Sandbox database clear and reseed
433433

scripts/check-deploy-environment.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set -o errexit -o pipefail -o nounset
55

66
: "${SHOULD_WARN_ONLY:="false"}"
77
: "${ENV:="dev"}"
8+
: "${ENV_ACCOUNT_NAME:="dev"}"
89

910
function success() {
1011
[ "${SHOULD_WARN_ONLY}" == "true" ] && return
@@ -41,24 +42,28 @@ done
4142

4243
# Check the mgmt account has the environments account id
4344
set +e
44-
env_account_id="$(aws secretsmanager get-secret-value --secret-id nhsd-nrlf--mgmt--${ENV}-account-id --query SecretString --output text)"
45+
env_account_id="$(aws secretsmanager get-secret-value --secret-id nhsd-nrlf--mgmt--${ENV_ACCOUNT_NAME}-account-id --query SecretString --output text)"
4546
set -e
4647
if [ -n "${env_account_id}" ]
4748
then
48-
success "${ENV} account id found in mgmt account"
49+
success "${ENV_ACCOUNT_NAME} account id found in mgmt account"
4950
else
50-
warning "${ENV} account id not found in mgmt account. Check you are logged into the NRLF mgmt account."
51+
warning "${ENV_ACCOUNT_NAME} account id not found in mgmt account. Check you are logged into the NRLF mgmt account."
5152
fi
5253

5354
# Check the Terraform workspace is set
5455
set +e
5556
tf_workspace="$(cd terraform/infrastructure && terraform workspace show)"
5657
set -e
5758
case "${tf_workspace}" in
58-
dev|int|ref|prod)
59+
dev|qa|int|ref|prod)
5960
warning "Terraform workspace set to persistent environment '${tf_workspace}'"
61+
if [ "${tf_workspace}" != "${ENV}" ]
62+
then
63+
warning "Terraform workspace '${tf_workspace}' does not match deployment environment '${ENV}'"
64+
fi
6065
;;
61-
dev-sandbox|ref-sandbox|int-sandbox)
66+
dev-sandbox|qa-sandbox|int-sandbox)
6267
warning "Terraform workspace set to sandbox environment '${tf_workspace}'"
6368
;;
6469
account_wide|default)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
# Get the account name for the provided NRLF environment
3+
set -o errexit -o nounset -o pipefail
4+
5+
if [ $# -ne 1 ]; then
6+
echo "Usage: get-account-name-for-env.sh <env>"
7+
exit 1
8+
fi
9+
10+
env="$1"
11+
12+
case "${env}" in
13+
dev|dev-sandbox)
14+
echo "dev"
15+
;;
16+
qa|qa-sandbox|ref|int|int-sandbox)
17+
echo "test"
18+
;;
19+
prod)
20+
echo "prod"
21+
;;
22+
*)
23+
echo "Unknown"
24+
exit 1
25+
esac
26+
27+
exit 0

scripts/truststore.sh

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
#!/bin/bash
2+
# Script to manage the NRLF truststore files
3+
set -o errexit -o pipefail -o nounset
4+
15
BUCKET="nhsd-nrlf--truststore"
26

37
function _truststore_help() {
48
echo
5-
echo "nrlf truststore <command> [options]"
9+
echo "$0 <command> [options]"
610
echo
711
echo "commands:"
812
echo " help - this help screen"
913
echo " build-ca <name> <fqdn> - Build a single CA cert"
10-
echo " build-client <name> <ca> <fqdn> - Build a single client cert + private key"
14+
echo " build-cert <name> <ca> <fqdn> - Build a single client cert + private key"
1115
echo " build-all - Build the standard trust store certs"
1216
echo " pull-ca <ca> - Pull the certificate authority"
1317
echo " pull-client <env> - pull the files needed for a client connection"
@@ -32,7 +36,7 @@ EOF
3236
# build a certificate authority
3337
function _truststore_build_ca() {
3438
if [ $# -ne 2 ]; then
35-
echo "Usage nrlf truststore ca <name> <fqdn>"
39+
echo "Usage: $0 build-ca <name> <fqdn>"
3640
exit 1
3741
fi
3842

@@ -61,14 +65,14 @@ function _truststore_build_ca() {
6165
# buld a certificate
6266
function _truststore_build_cert() {
6367
if [ $# -ne 3 ]; then
64-
echo "Usage nrlf truststore client <name> <ca> <fqdn>"
68+
echo "Usage: $0 build-cert <name> <ca> <fqdn>"
6569
exit 1;
6670
fi
6771

6872
client=$1
6973
ca=$2
7074
fqdn=$3
71-
serial=$("$DATE" +%s%3N)
75+
serial=$(date +%s%3N)
7276

7377
substitute_env_in_file ./truststore/config/client.conf /tmp/client.conf
7478

@@ -108,11 +112,13 @@ function _truststore_build_all() {
108112
_truststore_build_ca "prod" "record-locator.national.nhs.uk"
109113
_truststore_build_ca "int" "record-locator.int.national.nhs.uk"
110114
_truststore_build_ca "ref" "record-locator.ref.national.nhs.uk"
115+
_truststore_build_ca "qa" "qa.record-locator.national.nhs.uk"
111116
_truststore_build_ca "dev" "record-locator.dev.national.nhs.uk"
112117

113118
_truststore_build_cert "prod" "prod" "api.record-locator.national.nhs.uk"
114119
_truststore_build_cert "int" "int" "int.api.record-locator.int.national.nhs.uk"
115120
_truststore_build_cert "ref" "ref" "ref.api.record-locator.ref.national.nhs.uk"
121+
_truststore_build_cert "qa" "qa" "api.qa.record-locator.national.nhs.uk"
116122
_truststore_build_cert "dev" "dev" "dev.api.record-locator.dev.national.nhs.uk"
117123
}
118124

@@ -141,13 +147,13 @@ function _truststore_pull_all() {
141147
}
142148

143149
function _truststore() {
144-
local command=$1
145-
local args=(${@:2})
150+
local command=$1; shift
151+
local args=$@
146152

147153
case $command in
148154
"build-all") _truststore_build_all $args ;;
149155
"build-ca") _truststore_build_ca $args ;;
150-
"build-client") _truststore_build_cert $args ;;
156+
"build-cert") _truststore_build_cert $args ;;
151157
"pull-all") _truststore_pull_all $args ;;
152158
"pull-server") _truststore_pull_server $args ;;
153159
"pull-client") _truststore_pull_client $args ;;
@@ -156,4 +162,4 @@ function _truststore() {
156162
esac
157163
}
158164

159-
_truststore "${@:1}"
165+
_truststore $@

terraform/account-wide-infrastructure/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ Then, initialise your terraform workspace with:
2929
```shell
3030
$ cd ACCOUNT_NAME
3131
$ terraform init && ( \
32-
terraform workspace new account_wide || \
33-
terraform workspace select account_wide )
32+
terraform workspace new ACCOUNT_NAME || \
33+
terraform workspace select ACCOUNT_NAME )
3434
```
3535
3636
Replacing ACCOUNT_NAME with the name of your account, e.g `dev`, `test` etc.
@@ -68,8 +68,8 @@ Then, initialise your terraform workspace with:
6868
```shell
6969
$ cd ACCOUNT_NAME
7070
$ terraform init && ( \
71-
terraform workspace new account_wide || \
72-
terraform workspace select account_wide )
71+
terraform workspace new ACCOUNT_NAME || \
72+
terraform workspace select ACCOUNT_NAME )
7373
```
7474
7575
And then, to tear down:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
resource "aws_route53_zone" "dev-ns" {
22
name = "api.record-locator.dev.national.nhs.uk"
33
}
4+
5+
resource "aws_route53_zone" "NEW_dev-ns" {
6+
name = "dev.record-locator.national.nhs.uk"
7+
}

terraform/account-wide-infrastructure/mgmt/iam__developer-role.tf

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ module "developer_policy" {
4545
Effect = "Deny"
4646
Resource = [
4747
"${data.aws_s3_bucket.terraform_state.arn}/${local.project}/prod/*",
48-
"${data.aws_s3_bucket.terraform_state.arn}/${local.project}/test/*",
49-
"${data.aws_s3_bucket.terraform_state.arn}/${local.project}/ref/*",
5048
"${data.aws_s3_bucket.terraform_state.arn}/${local.project}/mgmt/*",
51-
"${data.aws_s3_bucket.terraform_state.arn}/${local.project}/dev/terraform-state-infrastructure"
5249
]
5350
},
5451
{

terraform/account-wide-infrastructure/mgmt/route53.tf

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,67 @@ resource "aws_route53_record" "dev_zone" {
8181
ttl = 300
8282
type = "NS"
8383
}
84+
85+
/**
86+
* NEW DNS Zone (all under record-locator.national.nhs.uk)
87+
*/
88+
resource "aws_route53_record" "NEW_ref_zone_delegation" {
89+
zone_id = aws_route53_zone.prod_zone.zone_id
90+
name = "ref.record-locator.national.nhs.uk"
91+
records = [
92+
"ns-1654.awsdns-14.co.uk.",
93+
"ns-1328.awsdns-38.org.",
94+
"ns-47.awsdns-05.com.",
95+
"ns-834.awsdns-40.net."
96+
]
97+
ttl = 300
98+
type = "NS"
99+
}
100+
101+
resource "aws_route53_record" "NEW_int_zone_delegation" {
102+
zone_id = aws_route53_zone.prod_zone.zone_id
103+
name = "int.record-locator.national.nhs.uk"
104+
records = [
105+
"ns-1064.awsdns-05.org.",
106+
"ns-609.awsdns-12.net.",
107+
"ns-2014.awsdns-59.co.uk.",
108+
"ns-386.awsdns-48.com."
109+
]
110+
ttl = 300
111+
type = "NS"
112+
}
113+
114+
resource "aws_route53_record" "NEW_dev_zone_delegation" {
115+
zone_id = aws_route53_zone.prod_zone.zone_id
116+
name = "dev.record-locator.national.nhs.uk"
117+
records = [
118+
"ns-1331.awsdns-38.org.",
119+
"ns-160.awsdns-20.com.",
120+
"ns-1900.awsdns-45.co.uk.",
121+
"ns-962.awsdns-56.net."
122+
]
123+
ttl = 300
124+
type = "NS"
125+
}
126+
127+
// TODO-NOW - Get these QA zone changes reflected in mgmt account (w/ Tom or Kate)
128+
resource "aws_route53_zone" "qa_zone" {
129+
name = "qa.record-locator.national.nhs.uk"
130+
131+
tags = {
132+
Environment = terraform.workspace
133+
}
134+
}
135+
136+
resource "aws_route53_record" "qa_zone_delegation" {
137+
zone_id = aws_route53_zone.prod_zone.zone_id
138+
name = "qa.record-locator.national.nhs.uk"
139+
records = [
140+
"ns-1821.awsdns-35.co.uk.",
141+
"ns-1449.awsdns-53.org.",
142+
"ns-933.awsdns-52.net.",
143+
"ns-500.awsdns-62.com."
144+
]
145+
ttl = 300
146+
type = "NS"
147+
}

0 commit comments

Comments
 (0)