Skip to content

Commit c58b6e7

Browse files
committed
[NRL-619] Remove TF_WORKSPACE env var from Makefiles. Update READMEs to detail ENV and TF_WORKSPACE_NAME vars. Remove top-level Makefile deploy target
1 parent 3ea5583 commit c58b6e7

File tree

3 files changed

+41
-26
lines changed

3 files changed

+41
-26
lines changed

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 && \

terraform/infrastructure/Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
ENV ?= dev
3-
TF_WORKSPACE ?= $(shell (whoami || hostname ) | head -c 5)-$(ENV)
3+
TF_WORKSPACE_NAME ?= $(shell (whoami || hostname) | head -c 5)-$(ENV)
44
TF_ARGS ?=
55
ENV_ACCOUNT_NAME ?= $(shell ../../scripts/get-account-name-for-env.sh $(ENV))
66
ENV_ACCOUNT_ID ?= $(shell aws secretsmanager get-secret-value --secret-id nhsd-nrlf--mgmt--$(ENV_ACCOUNT_NAME)-account-id --query SecretString --output text)
@@ -25,8 +25,7 @@ build-artifacts: ## Build the NRLF artifacts to deploy
2525
init: check-warn ## Initialise the Terraform workspace
2626
-(cd ../.. && $(MAKE) ENV=$(ENV) truststore-pull-server)
2727
terraform init
28-
terraform workspace select $(TF_WORKSPACE) \
29-
|| terraform workspace new $(TF_WORKSPACE)
28+
(terraform workspace select $(TF_WORKSPACE_NAME) || terraform workspace new $(TF_WORKSPACE_NAME))
3029

3130
plan: check-warn ## Plan the Terraform changes
3231
terraform plan \

terraform/infrastructure/README.md

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,48 +53,68 @@ $ make build-artifacts
5353

5454
### Init your local workspace
5555

56-
On the first deployment, you will need to initialise and select your workspace. To do this, run:
56+
On the first deployment, you will need to initialise and create your workspace. To create a new ephemeral dev workspace, run:
5757

5858
```shell
5959
$ make init
6060
```
6161

62-
If your Terraform provider config changes, you may need to run `make init` again.
62+
If you want to use an existing workspace, or if you want to use the workspace of a persistent environment, do the following:
63+
64+
```shell
65+
$ make ENV={ENV_NAME} TF_WORKSPACE_NAME={WORKSPACE_NAME} init
66+
```
67+
68+
replacing `{ENV_NAME}` with the environment name (e.g. `dev`, `qa`, `qa-sandbox` etc) and `{WORKSPACE_NAME}` with the name of the workspace you want to use.
69+
70+
So, for example, if you want to use the `qa` environment, you'd do you the following:
71+
72+
```shell
73+
$ make ENV=qa TF_WORKSPACE_NAME=qa init
74+
```
75+
76+
If your Terraform provider config changes, you may need to reinitialise your workspace.
6377

6478
### Create a Terraform plan
6579

66-
To create a Terraform plan:
80+
To create a Terraform plan for a dev workspace:
6781

6882
```shell
6983
$ make plan
7084
```
7185

72-
### Apply the changes with Terraform
73-
74-
To apply your changes:
86+
To create a Terraform plan for a workspace in another environment:
7587

7688
```shell
77-
$ make apply
89+
$ make ENV={ENV_NAME} plan
7890
```
7991

80-
## Tear down infrastructure
92+
replacing `{ENV_NAME}` with the environment name (e.g. `dev`, `qa`, `qa-sandbox` etc).
8193

82-
To tear down the infrastructure, you need to use Terraform to destroy the resources in your Terraform workspace.
94+
### Apply the changes with Terraform
8395

84-
To do this, follow these steps:
96+
To apply your changes to a dev workspace:
8597

86-
### Init your local workspace
98+
```shell
99+
$ make apply
100+
```
87101

88-
On the first deployment, you will need to initialise and select your workspace. To do this, run:
102+
To apply your changes to a workspace in another environment:
89103

90104
```shell
91-
$ make init
105+
$ make ENV={ENV_NAME} apply
92106
```
93107

94-
### Teardown infrastructure
108+
replacing `{ENV_NAME}` with the environment name (e.g. `dev`, `qa`, `qa-sandbox` etc).
109+
110+
## Tear down infrastructure
111+
112+
To tear down the infrastructure, you need to use Terraform to destroy the resources in your Terraform workspace.
95113

96114
To teardown the infrastructure, do the following:
97115

98116
```
99-
$ make destroy
117+
$ make ENV={ENV_NAME} TF_WORKSPACE_NAME={WORKSPACE_NAME} init destroy
100118
```
119+
120+
replacing `{ENV_NAME}` with the environment name (e.g. `dev`, `qa`, `qa-sandbox` etc) and `{WORKSPACE_NAME}` with the name of the workspace you want to destroy.

0 commit comments

Comments
 (0)