|
| 1 | +# Create an environment |
| 2 | + |
| 3 | +This is the initial manual process to create a new environment like review, dev, production... |
| 4 | + |
| 5 | +## Hub |
| 6 | + |
| 7 | +The environment requires a shared Azure front door profile created in the hub. The service name must be declared in [the hub configuration](https://github.com/NHSDigital/dtos-hub/tree/main/infrastructure/environments). And run the Azure devops pipeline for the corresponding hub (non-live or live). |
| 8 | + |
| 9 | +## Image Gallery |
| 10 | + |
| 11 | +- create a new gallery in the Azure compute galleries with name nonlive_lungcs_compute_gallery |
| 12 | +- create a resource group with name rg_hub_nonlive_lungcs_compute_gallery |
| 13 | + |
| 14 | +## Code |
| 15 | + |
| 16 | +- Create the configuration files in `infrastructure/environments/[environment]` |
| 17 | +- Add the `[environment]:` target in `scripts/terraform/terraform.mk` |
| 18 | +- Add [environment] to the list of environments in `deploy-stage` step of `cicd-2-main-branch.yaml`. For the review environment, there is a single item in `cicd-1-pull-request.yaml`. |
| 19 | +- Set the `fetch_secrets_from_app_key_vault` terraform variable to `false`. This is to let terraform create the key vault and prevent reading before it is ready. |
| 20 | + |
| 21 | +## Entra ID |
| 22 | + |
| 23 | +- Create Entra ID groups in `Digital screening` Administrative Unit: |
| 24 | + - `postgres_lungcs_[environment]_uks_admin` |
| 25 | + - `screening_lungcs_[environment]` |
| 26 | +- Ask CCOE to assign role: |
| 27 | + - [Form for PIM](https://nhsdigitallive.service-now.com/nhs_digital?id=sc_cat_item&sys_id=28f3ab4f1bf3ca1078ac4337b04bcb78&sysparm_category=114fced51bdae1502eee65b9bd4bcbdc) |
| 28 | + - Approver: Add someone from the infrastructure team |
| 29 | + - Role Name: `Group.Read.All` |
| 30 | + - Application Name: `mi-lungcs-[environment]-adotoaz-uks` |
| 31 | + - Application ID: [client.id] (would be of `mi-lungcs-[environment]-ghtoado-uks`) |
| 32 | + - Managed identity: `mi-lungcs-[environment]-adotoaz-uks` |
| 33 | + - Description: - Managed identity: `mi-lungcs-[environment]-adotoaz-uks` - Role: permanent on Directory |
| 34 | + |
| 35 | +## Bicep |
| 36 | + |
| 37 | +> [!IMPORTANT] |
| 38 | +> **Required permissions**: Owner role on both the hub and resource subscriptions |
| 39 | +
|
| 40 | +- From AVD: |
| 41 | + - Login with Microsoft Graph scope: `az login --scope https://graph.microsoft.com//.default -t HSCIC365.onmicrosoft.com` |
| 42 | + - Run bicep: `make [environment] resource-group-init` |
| 43 | + |
| 44 | +## Infra secrets |
| 45 | + |
| 46 | +Add the infrastructure secrets to the _inf_ key vault `kv-lungcs-[environment]-inf`: |
| 47 | + |
| 48 | +- For entra ID authentication (when `enable_entra_id_authentication` is true): aad-client-audiences, aad-client-id, aad-client-secret |
| 49 | +- `monitoring-email-address`: email distribution list to receive alerts |
| 50 | + |
| 51 | +## Azure devops |
| 52 | + |
| 53 | +- Create ADO group |
| 54 | + - Name: `Run pipeline - [environment]` |
| 55 | + - Members: `mi-lungcs-[environment]-ghtoado-uks`. There may be more than 1 in the list. Check client id printed below the name. |
| 56 | + - Permissions: |
| 57 | + - View project-level information |
| 58 | +- Create new pipeline: |
| 59 | + - Name: `Deploy to Azure - [environment]` |
| 60 | + - Pipeline yaml: `.azuredevops/pipelines/deploy.yml` |
| 61 | +- Manage pipeline security: |
| 62 | + - Add group: `Run pipeline - [environment]` |
| 63 | + - Permissions: |
| 64 | + - Edit queue build configuration |
| 65 | + - Queue builds |
| 66 | + - View build pipeline |
| 67 | + - View builds |
| 68 | +- Create service connection (ADO) |
| 69 | + - Connection type: `Azure Resource Manager` |
| 70 | + - Identity type: `Managed identity` |
| 71 | + - Subscription for managed identity: `Lung Cancer Risk Check - Non-live hub` or `Lung Cancer Risk Check - Live hub` for prod. |
| 72 | + - Resource group for managed identity: `rg-mi-[environment]-uks` |
| 73 | + - Managed identity: `mi-lungcs-[environment]-adotoaz-uks` |
| 74 | + - Scope level: `Subscription` |
| 75 | + - Subscription: `Digital Screening DToS - Core Services Dev` |
| 76 | + - Resource group for Service connection: leave blank |
| 77 | + - Service Connection Name: `lungcs-[environment]` |
| 78 | + - Do NOT tick: Grant access permission to all pipelines |
| 79 | + - Security: allow `Deploy to Azure - [environment]` pipeline |
| 80 | +- Create ADO environment: [environment] |
| 81 | + - Set: exclusive lock (except for review) |
| 82 | + - Add pipeline permission for `Deploy to Azure - [environment]` pipeline |
| 83 | + |
| 84 | +## GitHub |
| 85 | + |
| 86 | +- Create GitHub environment [environment] |
| 87 | +- Add the protection rule (except in review): |
| 88 | + - Deselect `Allow administrators to bypass configured protection rules` |
| 89 | + - In `Deployment branches and tags` choose `Selected branches and tags` from the drop-down menu |
| 90 | + - Click `Add deployment branch or tag rule` and enter "main" |
| 91 | +- Add environment secrets, from `mi-lungcs-[environment]-ghtoado-uks` in GitHub |
| 92 | + - _AZURE_CLIENT_ID_ |
| 93 | + - _AZURE_SUBSCRIPTION_ID_ |
| 94 | + |
| 95 | +## First run |
| 96 | + |
| 97 | +- Test running terraform manually from the AVD (Optional) |
| 98 | +- Raise a pull request, review and merge to trigger the pipeline |
| 99 | +- Check ADO pipeline. You may be prompted to authorise: |
| 100 | + - Pipeline: service connection |
| 101 | + - Environment: service connection and agent pool |
| 102 | + |
| 103 | +## App secrets |
| 104 | + |
| 105 | +- Add the application secrets to the _app_ key vault `kv-lungcs-[environment]-app` |
| 106 | +- Set `fetch_secrets_from_app_key_vault` terraform variable to `true` |
| 107 | +- Test running terraform manually from the AVD (Optional) |
| 108 | +- Raise a pull request, review and merge to trigger the pipeline |
0 commit comments