If you are ~40 years old, back to the old days how much time you were used to spend to install a brand new computer and have it ready to go? For sure it was days, weeks, sometimes I would say months, starting with the getting budget to buy a physical machine, until install the OS in it, what a long journey right?! So now, it takes minutes .. if you could tell this to your “young you” would you believe in you ( whaat ???? ?!?!).
In this case with Azure and Terraform is possible to create a virtual machine in minutes, let’s check this out.
Pre requirements to get started with Terraform with Azure
- Azure account ready to go
- Create your Azure free account today | Microsoft Azure
- Terraform CLI installed
- https://learn.hashicorp.com/tutorials/terraform/install-cli
- Clone the repository
git clone https://github.com/carlospcastro/devops.git
cd devops/cloud/Azure/terraform/test02/
Azure login
# To login to Azure
az login
# To find your subscription
az account list -o table
# To set properly your desired subscription
az account set --subscription <id>
Environment variable
You can setup env variables via command line or pass the values through the terraform command line terraform -var
Fill out the env_vars.sh with your values and then run the command below
source env_vars.sh
Terraform
# Run terraform
terraform init
terraform plan
# To apply the changes
terraform apply
Resources created

Login to machine

Clean up
# Run terraform to destroy everything
terraform destroy