-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from nhsuk/ci-terraform-deployments
CI terraform deployments
- Loading branch information
Showing
13 changed files
with
378 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
local.settings.json | ||
node_modules/ | ||
globalConfig.json | ||
terraform/.terraform* | ||
dist/ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
steps: | ||
|
||
# Since this is a deployment stage, we need to checkout the code. Non-deployment stages do this by default | ||
- checkout: self | ||
|
||
- task: AzureCLI@2 | ||
inputs: | ||
azureSubscription: 'nhsuk-user-feedback-${{parameters.environment}}' | ||
scriptType: 'bash' | ||
scriptLocation: 'inlineScript' | ||
addSpnToEnvironment: true # adds $servicePrincipalId, $servicePrincipalKey and $tenantId to the env vars | ||
inlineScript: | | ||
set -e | ||
# Set variables that terraform uses for azure authentication. | ||
# Make these variables available to future jobs. | ||
echo "##vso[task.setvariable variable=ARM_SUBSCRIPTION_ID]$(az account show --query 'id' --output tsv)" | ||
echo "##vso[task.setvariable variable=ARM_TENANT_ID]$tenantId" | ||
echo "##vso[task.setvariable variable=ARM_CLIENT_ID]$servicePrincipalId" | ||
echo "##vso[task.setvariable variable=ARM_CLIENT_SECRET]$servicePrincipalKey" | ||
displayName: 'Get Azure auth variables' | ||
|
||
- task: AzureCLI@2 | ||
inputs: | ||
azureSubscription: 'nhsuk-user-feedback-${{parameters.environment}}' | ||
scriptType: 'bash' | ||
scriptLocation: 'inlineScript' | ||
inlineScript: | | ||
./scripts/deploy.sh \ | ||
--env=${{parameters.environment}} \ | ||
--region=${{parameters.region}} | ||
displayName: 'Run deploy script' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/bin/bash | ||
|
||
for i in "$@" | ||
do | ||
case $i in | ||
--env=*) | ||
ENV="${i#*=}" | ||
shift # past argument=value | ||
;; | ||
--region=*) | ||
REGION="${i#*=}" | ||
shift # past argument=value | ||
;; | ||
*) | ||
# unknown option | ||
;; | ||
esac | ||
done | ||
|
||
if [[ -z "$ENV" ]]; then | ||
echo "--env option must be provided" | ||
exit 1 | ||
fi | ||
if [[ -z "$REGION" ]]; then | ||
echo "--region option must be provided" | ||
exit 1 | ||
fi | ||
|
||
echo "ENV = $ENV" | ||
echo "REGION = $REGION" | ||
|
||
set -e | ||
|
||
|
||
RESOURCE_GROUP_NAME="nhsuk-user-feedback-rg-tfstate-$ENV-$REGION" | ||
STORAGE_ACCOUNT_NAME="nhsukfeedbacktstate$ENV" | ||
CONTAINER_NAME="tstate" | ||
|
||
# This resource group should have been created for you by the infrastructure team | ||
# az group create --name $RESOURCE_GROUP_NAME --location $REGION | ||
|
||
# Create storage account | ||
az storage account create --resource-group $RESOURCE_GROUP_NAME --name $STORAGE_ACCOUNT_NAME --sku Standard_LRS --encryption-services blob | ||
|
||
# Get storage account key | ||
ACCOUNT_KEY=$(az storage account keys list --resource-group $RESOURCE_GROUP_NAME --account-name $STORAGE_ACCOUNT_NAME --query '[0].value' -o tsv) | ||
|
||
# Create blob container | ||
az storage container create --name $CONTAINER_NAME --account-name $STORAGE_ACCOUNT_NAME --account-key $ACCOUNT_KEY | ||
|
||
echo "storage_account_name: $STORAGE_ACCOUNT_NAME" | ||
echo "container_name: $CONTAINER_NAME" | ||
echo "access_key: $ACCOUNT_KEY" |
Oops, something went wrong.