Learning Terraform in 20 Hours
Outcome: Create windows & linux vm, sql instance, and app gateway
- Install Terraform in a Docker container
docker build -t terraform .
docker run -it -v ${PWD}:/work terraform
-
Authentication to Azure
Option 1: Azure CLI #FACT: Use
az account show
to see which sub terraform will use.Option 2: Authenticating using a Service Principal
-
Initialize Terraform
terraform init
Commands
terrafrom init
terraform plan
terraform apply
terraform destroy
#use for developing without having to create new dir and copy stuff +100
terraform workspace new $(workspaceName)
#test terraform commands!
terraform console
.terraform.tfvars
variable "admin_password" {
type = string
description = "admin password"
}
manual prompts
terraform apply
terraform -var option
terraform apply -var 'password=<Password>'
terraform variables file
.terraform.tfvars
username = "tfadmin2"
terraform apply -var="admin_password=Password1234!"
You can populate variables by exporting environment variables TF_VAR_$(variableName)
export TF_VAR_admin_password=Password1234!
https://phoenixnap.com/kb/how-to-install-terraform-centos-ubuntu
https://stackoverflow.com/questions/40542297/need-to-create-multile-vms-in-azure-through-terraform
https://www.terraformupandrunning.com/