Demonstrates using Terraform on Azure using basic concepts like variables, functions, third party modules and custom modules
Use the included setup.sh script to create all the prerequisites for this sample, you can run it in the Azure Cloud Shell after you have changed its permissions, like:
chmod 700 setup.sh
./setup.sh
Use the service principal details to log into Azure, az login --service-principal -u <service_principal_name> -p "<service_principal_password>" --tenant "<service_principal_tenant>"
Replace both the storage_account_name & access_key properties in the main.tf file with the output from the setup.sh script
Let's now run the terraform commands:
cd templates/basics/
terraform init -reconfigure
terraform plan -var-file="local.tfvars" -var "environment=dev" -out=plan
terraform apply plan
terraform destroy -var-file="local.tfvars" -var "environment=dev"
This sample showcases the following Terraform concepts:
- Azure Blob Storage for state management
- Input Variables via automatic load, file provided and cli provided
- Usage of the join built-in function
- Usage of the Azure Provider
- Usage of public module Terraform Azure RM Module for Network
- Custom database module using existing module Terraform Azure RM Module for Database
This sample was built using the following references:
- https://docs.microsoft.com/en-us/azure/developer/terraform/getting-started-cloud-shell
- https://docs.microsoft.com/en-us/azure/developer/terraform/store-state-in-azure-storage
- https://github.com/terraform-providers/terraform-provider-azurerm/tree/master/examples
- https://www.terraform.io/docs/index.html