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.

Similar Reads

What Is Azure?

Azure is a cloud computing platform provided by Microsoft and is fully known as Microsoft Azure. Azure provides a lot of computing services through the cloud which are easily available and are cost effective. This platform provides a wide variety of services like storage, Virtual Machines, databases, AI, Machine Learning, Virtual Networks, functions, and the list goes on and on. If you want to learn more about Azure you can visit its official website or visit our GFG Microsoft Azure Tutorial Page....

What Is Terraform?

Terraform is an Infrastructure as Code(IaC) software tool which is open source and is provided by HashiCorp. You need to write code i.e. a configuration file ( written in HashiCorp Configuration Language – HCL ) for what you want to build and Terraform builds that exactly as told....

How To Create Windows VM In Azure Using Terraform? A Step-By-Step Guide

This Whole tutorial is divided into parts so if you have any part already configured then you can skip that part....

Authenticate To Azure : Implementation Guide

For this you need to have Azure CLI installed already....

Create Service Principal : Implementation Guide

We create service principals to use it instead of doing Sign In every time while using automation tools like terraform....

Saving Credentials In Environment

Save the credential in environment variables so that when we’ll write the configuration file then we don’t need to put the credentials explicitly and this will be secure way....

Method 1: Save credentials in Linux

Step 1: Open your terminal....

Method 2: Save Credentials In Windows

Step 1: Open PowerShell....

Create Terraform Configuration Files

All the code provided for the configuration files is provided by Microsoft Azure. So copy and paste code as it is and don’t change it you don’t know what you are doing....

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....

Delete Resources In Azure Using Terraform

When you don’t need the resources which you created using the terraform you can clear them....

Conclusion

So now you know how to create windows Virtual machine using Azure terraform. The steps can be used to create as many virtual machines as you want, and not only for windows but whatever available operating system, you need to specify that in the terraform configuration files. Terraform is a great way for doing stuffs like this and is great tool for DevOps. While there are other options also to create a virtual machine in Azure like manually creating it using Azure Portal....

Creating VM In Azure Using Terraform – FAQ’s

Why Use Terraform To Create Virtual Machine When It Can Created Manually Using Azure Portal?...