Skip to content

patkoch/terraform_virtual_machine_windows

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deployment of a Windows virtual machine on Azure using Terraform

This is the manual for the provisioning of a Windows virtual machine on Azure using Terraform.

Prerequisites

Despite of having an Azure subscription, install following:

Sources for the Terraform configuration

I'd like to refer to following to links, which I've used for for that example:

Hashicorp - azurerm - Windows Virtual Machine

Hashicorp - azurerm - public ip

Deploy and destroy the Windows virtual machine with Terraform

I recommend to conduct all commands in VS Code using a new Terminal.

Login in to Azure

Run following command to start the login to Azure:

az login

A new browser session pops up, use the login credentials of your account:

After that, switch back to VS Code, you should see logs similar in the picture shown below:

You can prove whether you are using the right subscription using the following command:

az account show

This shows you the current subscription:

Deploy the virtual machine

The first Terraform command is the "init" command:

terraform init

The logs in the picture below show a successful execution of the command:

As next, run the "format" command, to ensure that all files of your configuration stick to specific language style conventions:

terraform fmt

After that, ensure that your Terraform coniguration is valid by executing:

terraform validate

Create now a Terraform plan file, by running:

terraform plan -out tfplan

This creates a file named "tfplan" in your directory:

Finally, the command can be executed for deploying the virtual machine on Azure - it uses the Terraform plan named "tfplan" as an argument:

terraform apply "tfplan"

The deployment was successful if following log message appears:

Prove the deployment of the virtual machine in the Azure portal:

Destroy the virtual machine

The virtual machine can be destroyed using the following command:

terraform destroy

References

https://developer.hashicorp.com/terraform/tutorials/azure-get-started/azure-build

https://developer.hashicorp.com/terraform/cli/commands