Creating Virtual Machine
Step 1: Open a terminal either Linux Terminal or PowerShell in windows operating system and remember to be in the folder where you created the terraform configuration files.
Step 2: Download the Azure provider for managing resources.
Syntax
terraform init -upgrade
Output
Step 3: Create execution plan. It creates a file determining which actions will be needed for the resources specified in configuration files.
Syntax
terraform plan -out main.tfplan
- This command will create a execution plan and save it in main.tfplan file.
Output
Step 4: Now do apply the actions which are specified in the previous step in main.tfplan file.
Syntax
terraform apply main.tfplan
Output
Step 5: Now your virtual windows machine is created and is ready to be used.
Step 6: To check the IP address of your virtual machine use below commands in your terminal.
Syntax
echo `terraform output -raw public_ip_address`
Syntax
echo $(terraform output -raw public_ip_address)
- You can verify the IP address by visiting that IP in your browser.
Step 7: You can also go to your Azure Portal in Virtual Machine section to check your Windows VM.
How to Create Windows VM in Azure Using Terraform
In this article, we will cover the whole process of creating Windows VM in Azure using Terraform. When you have to create multiple VMs, perhaps even identical ones, or machines with nearly identical configurations, it can be repetitive and time-consuming to go through the manual setup process each time. That’s where Terraform comes in. Think of it as a blueprint for building VMs without the need for manual work, reducing errors and saving you valuable time. Let’s first see what virtual machines, azure, and Terraform are.