- Create a storage account that will contain the Terraform state.
- Create a container called 'tfstate'.
- Save the name name and access key of this storage account for later.
- Create an app registration.
- You will need the client id later.
- Create a client secret and save this for later.
- In the subscription you want to deploy resources in, make sure the app registration has at least 'Contributor' rights.
- Open a powershell to the root of this repo.
- Set-up environment variables to authenticate:
$env:ARM_TENANT_ID = "<tenant id of the subscription to deploy resources into>"
$env:ARM_SUBSCRIPTION_ID = "<subscription id of the subscription to deploy resources into>"
$env:ARM_ACCESS_KEY = "<storage account access key>"
$env:ARM_CLIENT_ID = "<app registration client id>"
$env:ARM_CLIENT_SECRET = "<app registration client secret>"
$env:TF_VAR_site_name= "<some unique name indicating your project/customer>"
- Run
terraform init -backend-config="storage_account_name=<storage account name>"
. This should result in 'Terraform has been successfully initialized'. - Run
terraform workspace new dev
to switch to the dev environment state. - Run
terraform plan --var-file .\variables_dev.tfvars.json -out changes
. Terraform will use the variables of this specific DTAP environment, and the current state of the resources, to calculate what needs to change. This is saved in a 'changes' file. - Run
terraform apply "changes"
. This will apply the proposed changes.
To roll out a tst environment, simply run:
terraform workspace new tst
, to switch to a clean state (prevents terraform wanting to destroy the dev environment to replace it)terraform plan --var-file .\variables_tst.tfvars.json -out changes
terraform apply "changes"