The following instructions are divided into two parts:
To run the following steps, first you should:
-
Install Terraform - required to deploy, delete and check the status of current cloud infrastructure from resource files from the command line
-
Install Azure CLI - allows you to log in to your Azure account and retrieve details about deployed instances. Accessed using
az
-
Install jq - a command line JSON processor used by some of the scripts in this project
brew install jq
-
Authenticate with Azure
az login
-
If the login shows that you have access to more than one subscription, run the following command changing
SUBSCRIPTION_ID
with the relevant ID found in the output from the previous command:az account set --subscription="SUBSCRIPTION_ID"
Avoid this step if the target environment already exists
This step is limited to developers who have owner
rights on Azure. If you do not have sufficient privileges, ask a colleague or contact MHRA IT Desk.
-
Change to the relevant environment directory (e.g.
infrastructure/environments/prod
) -
Create an
.env
file, following the example from.env.example
. (Note: Some values are the same for different keys it, e.g.ARM_CLIENT_ID
&TF_VAR_CLIENT_ID
, as one is for Azure CLI and the other one is named so that it can be referenced from within Terraform) -
Create a new storage account to hold the Terraform state for this environment by running the following script
../../scripts/create-storage-account.sh
-
Use the output from this script to populate the corresponding values in your
.env
file -
Create a service principal, replacing
<ServicePrincipalName>
with the name of the account you want to useaz ad sp create-for-rbac --name <ServicePrincipalName>
-
Use the output from this script to populate the corresponding values in your
.env
file
-
Change to the relevant environment directory (e.g.
infrastructure/environments/non-prod
) -
Create an
.env
file. You can either populate the values manually, following the example from.env.example
or, if you have access to the Azure keyvault, you can runmake get-env
to auto-populate them from the saved values.If populating manually, to get the
ARM_
prefixed values:-
Make sure you have logged in to the Azure CLI:
az login
. Theid
field returned by this command is yourARM_SUBSCRIPTION_ID
. -
Create a service principal:
az ad sp create-for-rbac --name "MakeUpSomeName"
. Use the output values from this command for the following environment variables:Environment variable Field ARM_CLIENT_ID
appId
ARM_CLIENT_SECRET
password
ARM_TENANT_ID
tenant
-
-
Source the environment variables
set -a && source .env && set +a
-
Initialize terraform (this ensures providers/modules are installed locally and the backend is initialized)
terraform init
-
Create a plan or apply the infrastructure
terraform plan # optional terraform apply
-
The
terraform apply
will produce some output that looks similar to the following (the keys below have since been removed). You can use these values where required in other.env
files throughout this repoOutputs: cpd_primary_access_key = APtr7/7Z5tADWy6XP/kcnwkqgGoHssWP+16QoURBFoXXQpZp5XxIGSA44my/TvnNsQcPOGDojki6mQo2WNxqFQ== cpd_static_web_url = https://mhracpdnonprod.z33.web.core.windows.net/ products_primary_access_key = ErgFGAmFm3xJhl84jMHESRNZIU3o4nmmGKnHes9qydvlQexD8/4noYMpubeoVBK3fHnH4p2jMj3ObzN79OtfjQ== products_static_web_url = https://mhraproductsnonprod.z33.web.core.windows.net/ search_admin_key = CB28B1A47E29FF4620184BD27B89945E