Skip to content

Latest commit

 

History

History
118 lines (76 loc) · 4.93 KB

quick-cluster-create-terraform.md

File metadata and controls

118 lines (76 loc) · 4.93 KB
title description author ms.service ms.collection ms.topic ms.date ms.author ms.custom content_well_notification ai-usage
Quickstart: Create a Windows VM cluster in Azure using Terraform
In this article, you learn how to create a Windows VM cluster in Azure using Terraform
tomarchermsft
virtual-machines
windows
quickstart
07/24/2023
tarcher
devx-track-terraform
AI-contribution
ai-assisted

Quickstart: Create a Windows VM cluster in Azure using Terraform

Applies to: ✔️ Windows VMs

This article shows you how to create a Windows VM cluster (containing three Windows VM instances) in Azure using Terraform.

[!div class="checklist"]

Prerequisites

Implement the Terraform code

  1. Create a directory in which to test the sample Terraform code and make it the current directory.

  2. Create a file named providers.tf and insert the following code:

    :::code language="Terraform" source="~/terraform_samples/quickstart/101-vm-cluster-windows/providers.tf":::

  3. Create a file named main.tf and insert the following code:

    :::code language="Terraform" source="~/terraform_samples/quickstart/101-vm-cluster-windows/main.tf":::

  4. Create a file named variables.tf and insert the following code:

    :::code language="Terraform" source="~/terraform_samples/quickstart/101-vm-cluster-windows/variables.tf":::

  5. Create a file named outputs.tf and insert the following code:

    :::code language="Terraform" source="~/terraform_samples/quickstart/101-vm-cluster-windows/outputs.tf":::

Initialize Terraform

[!INCLUDE terraform-init.md]

Create a Terraform execution plan

[!INCLUDE terraform-plan.md]

Apply a Terraform execution plan

[!INCLUDE terraform-apply-plan.md]

Cost information isn't presented during the virtual machine creation process for Terraform like it is for the Azure portal. If you want to learn more about how cost works for virtual machines, see the Cost optimization Overview page.

Verify the results

  1. Get the Azure resource group name.

    resource_group_name=$(terraform output -raw resource_group_name)
  2. Run az vm list with a JMESPath query to display the names of the virtual machines created in the resource group.

    az vm list \
      --resource-group $resource_group_name \
      --query "[].{\"VM Name\":name}" -o table
    
  1. Get the Azure resource group name.

    $resource_group_name=$(terraform output -raw resource_group_name)
  2. Run Get-AzVm to display the names of all the virtual machines in the resource group.

    Get-AzVm -ResourceGroupName $resource_group_name
    

Clean up resources

[!INCLUDE terraform-plan-destroy.md]

Troubleshoot Terraform on Azure

Troubleshoot common problems when using Terraform on Azure

Next steps

[!div class="nextstepaction"] Azure Linux virtual machine tutorials