|
1 | | -# immunisation-fhir-api Terraform |
| 1 | +# About |
| 2 | +The terraform from this folder runs in each PR and sets up lambdas associated with the PR. Once the PR is merged, it will be used by the release pipeline to deploy to INT and REF. This is also run by the prod release pipeline to deploy the lambdas to the prod blue and green sub environments. |
2 | 3 |
|
3 | | -## Setup for local dev |
| 4 | +## Environments Structure |
4 | 5 |
|
5 | | -Add your workspace name to the env file. This is usually your shortcode. |
| 6 | +Terraform is executed via a `Makefile`. |
| 7 | +The environment-specific configuration is structured as follows: |
6 | 8 |
|
7 | | -```shell |
8 | | -echo environment=your-shortcode >> .env |
9 | | -make init |
10 | | -make workspace |
11 | | -make apply |
| 9 | + environments/ |
| 10 | + └── <ENVIRONMENT>/ # e.g. dev, int, prod (AWS account name) |
| 11 | + └── <SUB_ENVIRONMENT_DIR> / # e.g. pr, internal-dev |
| 12 | + └── variables.tfvars |
| 13 | + |
| 14 | +The `Makefile` automatically reads the `.env` file to determine the correct `variables.tfvars` file to use, allowing customization of infrastructure for each sub-environment. |
| 15 | + |
| 16 | +## Run locally |
| 17 | +1. Create a `.env` file with the following values: |
| 18 | +```dotenv |
| 19 | +ENVIRONMENT=dev # Target AWS account (e.g., dev, int, prod) |
| 20 | +SUB_ENVIRONMENT=pr-123 # Sub-environment (e.g., pr-57, internal-dev) |
| 21 | +AWS_REGION=eu-west-2 |
| 22 | +AWS_PROFILE=your-aws-profile |
12 | 23 | ``` |
| 24 | +2. Run `make init` to download provisioners and dependencies |
| 25 | +3. Run `make plan` to output plan with the changes that terraform will perform |
| 26 | +4. **WARNING**: Run `make apply` only after thoroughly reviewing the plan as this might destroy or modify existing infrastructure |
13 | 27 |
|
14 | | -See the Makefile for other commands. |
| 28 | +Note: If you switch environment configuration in .env ensure that you run `make init-reconfigure` to reconfigure the backend to prevent migrating the existing state to the new backend. |
15 | 29 |
|
16 | | -If you want to apply Terraform to a workspace created by a PR you can set the above environment to the PR number. |
| 30 | +If you want to apply Terraform to a workspace created by a PR you can set the above SUB_ENVIRONMENT to the `PR-number` and ENVIRONMENT set to `dev`. |
17 | 31 | E.g. `pr-57`. You can use this to test out changes when tests fail in CI. |
0 commit comments