-
Notifications
You must be signed in to change notification settings - Fork 3
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 #5 from LaurentLesle/deployment-scripts-to-support…
…-multiple-developers Deployment scripts to support multiple developers
- Loading branch information
Showing
11 changed files
with
127 additions
and
43 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,6 @@ | ||
**/.terraform | ||
**/*.tfstate | ||
.DS_Store | ||
**/terraform.tfstate.d | ||
**/terraform.tfstate.backup | ||
**/.terraform.tfstate.lock.info |
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,38 @@ | ||
|
||
Deployment steps | ||
|
||
Initialise the Terraform remote state on Azure blob storage by running | ||
|
||
./deploy.sh | ||
|
||
When the state has been initialized, you can plan the blueprint | ||
|
||
|
||
./deploy.sh step1-aks plan | ||
|
||
Apply changes with | ||
|
||
./deploy.sh step1-aks apply | ||
|
||
|
||
To allow multiple deployments in the same subscription | ||
|
||
One of the goal of this template is to support multiple developers working in parallel in the same azure subscription. | ||
|
||
To achieve that the template is using a prefix to used to identify the resource groups: | ||
|
||
zlra-TERRAFORM-STATE\ | ||
zlra-AKS-CLUSTER1-NETWORKING | ||
|
||
This is very convenient as multiple developers will have different prefixes and does not impact each others. | ||
|
||
The other benefit is for bug fixing. Sometimes with Terraform fixing a bug breaks the current deployed infrastructure. As you are working towards a stable version of your blueprint you mays want to create a branch and work against a different tfstate file. | ||
|
||
You can achieve that with the terraform workspaces who are isolating your different tfstates. | ||
|
||
You can map the terraform workspace with the branch name \ | ||
|
||
terraform workspace list\ | ||
default\ | ||
"* master | ||
|
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,65 @@ | ||
#!/bin/bash | ||
|
||
# To run the deployment: | ||
# Initialise the remote state first with ./deploy.sh | ||
# ./deploy.sh step1-aks [plan|apply|destroy] | ||
|
||
# capture the current path | ||
current_path=$(pwd) | ||
path=$1 | ||
tf_command=$2 | ||
|
||
|
||
function initialize_state { | ||
cd tfstate | ||
terraform init | ||
terraform apply -auto-approve | ||
cd "${current_path}" | ||
} | ||
|
||
function deploy_blueprint { | ||
cd tfstate | ||
storage_account_name=$(terraform output storage_account_name) | ||
echo ${storage_account_name} | ||
access_key=$(terraform output access_key) | ||
container=$(terraform output container) | ||
prefix=$(terraform output prefix) | ||
tf_name="${prefix}.tfstate" | ||
|
||
cd "../${path}" | ||
pwd | ||
|
||
terraform init \ | ||
-reconfigure \ | ||
-backend=true \ | ||
-lock=false \ | ||
-backend-config storage_account_name=${storage_account_name} \ | ||
-backend-config container_name=${container} \ | ||
-backend-config access_key=${access_key} \ | ||
-backend-config key=${tf_name} | ||
|
||
terraform ${tf_command} \ | ||
-var prefix=${prefix} | ||
|
||
cd "${current_path}" | ||
} | ||
|
||
|
||
# Initialise storage account to store remote terraform state | ||
if [[ -z "${path}" && -z "$2" ]]; then | ||
initialize_state | ||
fi | ||
|
||
if [[ -n "${path}" && -n "${tf_command}" ]]; then | ||
echo '' | ||
echo "Deploying blueprint '${path}' with terraform command '${tf_command}'" | ||
echo '' | ||
deploy_blueprint | ||
else | ||
echo '' | ||
echo 'You have to run at least once ./deploy.sh with no parameters to setup the remote state.' | ||
echo 'To deploy a bluepring you have to specify the sub-folder name and the terraform command [plan|apply|destroy]' | ||
echo './deploy.sh step1-aks plan' | ||
echo '' | ||
echo 'Note: the script does the terraform init for you.' | ||
fi |
This file was deleted.
Oops, something went wrong.
Empty file.
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,17 +1,9 @@ | ||
|
||
provider "azurerm" { | ||
version = "~>1.25" | ||
version = "~>1.27.1" | ||
} | ||
|
||
terraform { | ||
backend "azurerm" {} | ||
} | ||
|
||
|
||
# Used to make sure delete / re-create generate brand new names and reduce risk of being throttled during dev activities | ||
resource "random_string" "prefix" { | ||
length = 4 | ||
special = false | ||
upper = false | ||
number = false | ||
} |
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
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,8 @@ | ||
# Used to make sure delete / re-create generate brand new names and reduce risk of being throttled during dev activities | ||
# used to enable multiple developers to work against the same subscription | ||
resource "random_string" "prefix" { | ||
length = 4 | ||
special = false | ||
upper = false | ||
number = false | ||
} |
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