This demo repo is the source code for my blogpost Terraform all the Things with VSTS.
In order to work with this repo, clone it and then do the following:
- Create the backend storage account.
- Open
state\state.tfand comment out thebackendblock. - Update the variables in
variables.tf(or you can override them on the command line). - Run
terraform apply. This creates a storage account and outputs theaccess_key. - Uncomment the
backendblock in thestate.tffile, using values you supplied for theterraform applycommand. - Run
terraform init, and enteryesto copy your local state.
- Open
- Add
backend.tfvarsandsecrets.tfvarsto the root folder (these are ignored in the.gitignorefile). Format of these files is listed below. Copy theaccess_keyoutput from the stateterraform applycommand into thebackend.tfvarsfile. - Enter secrets for the database passwords into
secrets.tfvars. - For each stack (folder):
- Create a workspace (environment).
terraform workspace new devto create adevworkspace. If it already exists, then just select it usingterraform workspace select dev. - Run
terraform init- this should sync to the backend state. - Run
terraform apply
- Create a workspace (environment).
release.tfvarsis a template file for variables during release. If you add additional variables, remember to add the tokenized values in this file. For more info, see the blog post.
access_key = "long_key_from_azure_storage_acc"
secrets = {
dev = {
sql_admin_password = "ThisIsASuperL0ngP@sswordThatShouldBeSecure1"
}
uat = {
sql_admin_password = "ThisIsASuperL0ngUATP@sswordThatShouldBeSecure1"
}
}