title | description | ms.topic | ms.date | ms.custom | author | ms.author | content_well_notification | ai-usage | |
---|---|---|---|---|---|---|---|---|---|
Quickstart: Create a lab in Azure DevTest Labs using Terraform |
In this article, you create a Windows virtual machine in a lab within Azure DevTest Labs using Terraform |
quickstart |
4/14/2023 |
devx-track-terraform, UpdateFrequency2 |
TomArcherMsft |
tarcher |
|
ai-assisted |
This article shows how to use Terraform to create a Windows Server 2019 Datacenter virtual machine in a lab within Azure DevTest Labs using Terraform.
In this article, you learn how to:
[!div class="checklist"]
- Create a random pet name for the Azure resource group name using random_pet
- Create an Azure resource group using azurerm_resource_group
- Create a random password using random_password
- Create a lab within Azure DevTest Labs using azurerm_dev_test_lab
- Create a virtual network within Azure DevTest Labs using azurerm_dev_test_virtual_network
- Create a Windows virtual machine within Azure DevTest Labs using azurerm_dev_test_windows_virtual_machine
Note
The sample code for this article is located in the Azure Terraform GitHub repo. You can view the log file containing the test results from current and previous versions of Terraform.
See more articles and sample code showing how to use Terraform to manage Azure resources
-
Create a directory in which to test and run the sample Terraform code and make it the current directory.
-
Create a file named
main.tf
and insert the following code:[!code-terraformmaster]
-
Create a file named
outputs.tf
and insert the following code:[!code-terraformmaster]
-
Create a file named
providers.tf
and insert the following code:[!code-terraformmaster]
-
Create a file named
variables.tf
and insert the following code:[!code-terraformmaster]
[!INCLUDE terraform-init.md]
[!INCLUDE terraform-plan.md]
[!INCLUDE terraform-apply-plan.md]
-
Get the Azure resource name in which the lab was created.
resource_group_name=$(terraform output -raw resource_group_name)
-
Get the lab name.
lab_name=$(terraform output -raw lab_name)
-
Run az lab vm list to list the virtual machines for the lab you created in this article.
az lab vm list --resource-group $resource_group_name \ --lab-name $lab_name
[!INCLUDE terraform-plan-destroy.md]
Troubleshoot common problems when using Terraform on Azure
[!div class="nextstepaction"] Tutorial: Work with lab VMs