Skip to content

Commit 70f69b7

Browse files
authored
Merge pull request #246035 from TomArcherMsft/move-vm-cluster-articles
Moving VM articles to VM repo
2 parents 9a3fedb + b3ecb7d commit 70f69b7

File tree

3 files changed

+255
-4
lines changed

3 files changed

+255
-4
lines changed

articles/virtual-machines/TOC.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
- name: PowerShell
1616
href: ./linux/quick-create-powershell.md
1717
- name: Terraform
18-
displayName: Terraform
19-
href: ./linux/quick-create-terraform.md
18+
items:
19+
- name: Terraform VM
20+
href: ./linux/quick-create-terraform.md
21+
- name: Terraform VM cluster
22+
href: ./linux/quick-cluster-create-terraform.md
2023
- name: Bicep
2124
displayName: ARM, Resource Manager, Template
2225
href: ./linux/quick-create-bicep.md
@@ -32,8 +35,11 @@
3235
- name: PowerShell
3336
href: ./windows/quick-create-powershell.md
3437
- name: Terraform
35-
displayName: Terraform
36-
href: ./windows/quick-create-terraform.md
38+
items:
39+
- name: Terraform VM
40+
href: ./windows/quick-create-terraform.md
41+
- name: Terraform VM cluster
42+
href: ./windows/quick-cluster-create-terraform.md
3743
- name: Bicep
3844
displayName: ARM, Resource Manager, Template
3945
href: ./windows/quick-create-bicep.md
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
---
2+
title: 'Quickstart: Create a Linux VM cluster in Azure using Terraform'
3+
description: In this article, you learn how to create a Linux VM cluster in Azure using Terraform
4+
author: tomarchermsft
5+
ms.service: virtual-machines
6+
ms.collection: linux
7+
ms.topic: quickstart
8+
ms.workload: infrastructure
9+
ms.date: 07/24/2023
10+
ms.author: tarcher
11+
ms.custom: devx-track-terraform
12+
content_well_notification:
13+
- AI-contribution
14+
---
15+
16+
# Quickstart: Create a Linux VM cluster in Azure using Terraform
17+
18+
**Applies to:** :heavy_check_mark: Linux VMs
19+
20+
This article shows you how to create a Linux VM cluster (containing two Linux VM instances) in Azure using Terraform.
21+
22+
In this article, you learn how to:
23+
24+
> [!div class="checklist"]
25+
> * Create a random value for the Azure resource group name using [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet).
26+
> * Create an Azure resource group using [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group).
27+
> * Create a virtual network using [azurerm_virtual_network](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network)
28+
> * Create a subnet using [azurerm_subnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet)
29+
> * Create a public IP using [azurerm_public_ip](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/public_ip)
30+
> * Create a load balancer using [azurerm_lb](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/lb)
31+
> * Create a load balancer address pool using [azurerm_lb_backend_address_pool](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/lb_backend_address_pool)
32+
> * Create a network interface using [azurerm_network_interface](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface)
33+
> * Create a managed disk using [azurerm_managed_disk](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/managed_disk)
34+
> * Create a availability set using [azurerm_availability_set](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/availability_set)
35+
> * Create a Linux virtual machine using [azurerm_linux_virtual_machine](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_virtual_machine)
36+
> * Create an AzAPI resource [azapi_resource](https://registry.terraform.io/providers/Azure/azapi/latest/docs/resources/azapi_resource).
37+
> * Create an AzAPI resource to generate an SSH key pair using [azapi_resource_action](https://registry.terraform.io/providers/Azure/azapi/latest/docs/resources/azapi_resource_action).
38+
39+
## Prerequisites
40+
41+
- [Install and configure Terraform](/azure/developer/terraform/quickstart-configure)
42+
43+
## Implement the Terraform code
44+
45+
> [!NOTE]
46+
> The sample code for this article is located in the [Azure Terraform GitHub repo](https://github.com/Azure/terraform/tree/master/quickstart/101-vm-cluster-linux). You can view the log file containing the [test results from current and previous versions of Terraform](https://github.com/Azure/terraform/tree/master/quickstart/101-vm-cluster-linux/TestRecord.md).
47+
>
48+
> See more [articles and sample code showing how to use Terraform to manage Azure resources](/azure/terraform)
49+
50+
1. Create a directory in which to test the sample Terraform code and make it the current directory.
51+
52+
1. Create a file named `providers.tf` and insert the following code:
53+
54+
:::code language="Terraform" source="~/terraform_samples/quickstart/101-vm-cluster-linux/providers.tf":::
55+
56+
1. Create a file named `ssh.tf` and insert the following code:
57+
58+
:::code language="Terraform" source="~/terraform_samples/quickstart/101-vm-cluster-linux/ssh.tf":::
59+
60+
1. Create a file named `main.tf` and insert the following code:
61+
62+
:::code language="Terraform" source="~/terraform_samples/quickstart/101-vm-cluster-linux/main.tf":::
63+
64+
1. Create a file named `variables.tf` and insert the following code:
65+
66+
:::code language="Terraform" source="~/terraform_samples/quickstart/101-vm-cluster-linux/variables.tf":::
67+
68+
1. Create a file named `outputs.tf` and insert the following code:
69+
70+
:::code language="Terraform" source="~/terraform_samples/quickstart/101-vm-cluster-linux/outputs.tf":::
71+
72+
## Initialize Terraform
73+
74+
[!INCLUDE [terraform-init.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-init.md)]
75+
76+
## Create a Terraform execution plan
77+
78+
[!INCLUDE [terraform-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan.md)]
79+
80+
## Apply a Terraform execution plan
81+
82+
[!INCLUDE [terraform-apply-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-apply-plan.md)]
83+
84+
## Verify the results
85+
86+
#### [Azure CLI](#tab/azure-cli)
87+
88+
1. Get the Azure resource group name.
89+
90+
```console
91+
resource_group_name=$(terraform output -raw resource_group_name)
92+
```
93+
94+
1. Run [az vm list](/cli/azure/vm#az-vm-list) with a [JMESPath](/cli/azure/query-azure-cli) query to display the names of the virtual machines created in the resource group.
95+
96+
```azurecli
97+
az vm list \
98+
--resource-group $resource_group_name \
99+
--query "[].{\"VM Name\":name}" -o table
100+
```
101+
102+
#### [Azure PowerShell](#tab/azure-powershell)
103+
104+
1. Get the Azure resource group name.
105+
106+
```console
107+
$resource_group_name=$(terraform output -raw resource_group_name)
108+
```
109+
110+
1. Run [Get-AzVm](/powershell/module/az.compute/get-azvm) to display the names of all the virtual machines in the resource group.
111+
112+
```azurepowershell
113+
Get-AzVm -ResourceGroupName $resource_group_name
114+
```
115+
116+
---
117+
118+
## Clean up resources
119+
120+
[!INCLUDE [terraform-plan-destroy.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan-destroy.md)]
121+
122+
## Troubleshoot Terraform on Azure
123+
124+
[Troubleshoot common problems when using Terraform on Azure](/azure/developer/terraform/troubleshoot)
125+
126+
## Next steps
127+
128+
> [!div class="nextstepaction"]
129+
> [Azure Linux virtual machine tutorials](./tutorial-manage-vm.md)
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
---
2+
title: 'Quickstart: Create a Windows VM cluster in Azure using Terraform'
3+
description: In this article, you learn how to create a Windows VM cluster in Azure using Terraform
4+
author: tomarchermsft
5+
ms.service: virtual-machines
6+
ms.collection: windows
7+
ms.topic: quickstart
8+
ms.workload: infrastructure
9+
ms.date: 07/24/2023
10+
ms.author: tarcher
11+
ms.custom: devx-track-terraform
12+
content_well_notification:
13+
- AI-contribution
14+
---
15+
16+
# Quickstart: Create a Windows VM cluster in Azure using Terraform
17+
18+
**Applies to:** :heavy_check_mark: Windows VMs
19+
20+
This article shows you how to create a Windows VM cluster (containing three Windows VM instances) in Azure using Terraform.
21+
22+
> [!div class="checklist"]
23+
> * Create a random value for the Azure resource group name using [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet).
24+
> * Create an Azure resource group using [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group).
25+
> * Create a random value for the Windows VM host name [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string).
26+
> * Create a random password for the Windows VMs using [random_password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password).
27+
> * Create a Windows VM using the [compute module](https://registry.terraform.io/modules/Azure/compute/azurerm).
28+
> * Create a virtual network along with subnet using the [network module](https://registry.terraform.io/modules/Azure/network/azurerm).
29+
30+
## Prerequisites
31+
32+
- [Install and configure Terraform](/azure/developer/terraform/quickstart-configure)
33+
34+
## Implement the Terraform code
35+
36+
> [!NOTE]
37+
> The sample code for this article is located in the [Azure Terraform GitHub repo](https://github.com/Azure/terraform/tree/UserStory89540/quickstart/101-vm-cluster-windows). You can view the log file containing the [test results from current and previous versions of Terraform](https://github.com/Azure/terraform/tree/UserStory89540/quickstart/101-vm-cluster-windows/TestRecord.md).
38+
>
39+
> See more [articles and sample code showing how to use Terraform to manage Azure resources](/azure/terraform)
40+
41+
1. Create a directory in which to test the sample Terraform code and make it the current directory.
42+
43+
1. Create a file named `providers.tf` and insert the following code:
44+
45+
:::code language="Terraform" source="~/terraform_samples/quickstart/101-vm-cluster-windows/providers.tf":::
46+
47+
1. Create a file named `main.tf` and insert the following code:
48+
49+
:::code language="Terraform" source="~/terraform_samples/quickstart/101-vm-cluster-windows/main.tf":::
50+
51+
1. Create a file named `variables.tf` and insert the following code:
52+
53+
:::code language="Terraform" source="~/terraform_samples/quickstart/101-vm-cluster-windows/variables.tf":::
54+
55+
1. Create a file named `outputs.tf` and insert the following code:
56+
57+
:::code language="Terraform" source="~/terraform_samples/quickstart/101-vm-cluster-windows/outputs.tf":::
58+
59+
## Initialize Terraform
60+
61+
[!INCLUDE [terraform-init.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-init.md)]
62+
63+
## Create a Terraform execution plan
64+
65+
[!INCLUDE [terraform-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan.md)]
66+
67+
## Apply a Terraform execution plan
68+
69+
[!INCLUDE [terraform-apply-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-apply-plan.md)]
70+
71+
## Verify the results
72+
73+
#### [Azure CLI](#tab/azure-cli)
74+
75+
1. Get the Azure resource group name.
76+
77+
```console
78+
resource_group_name=$(terraform output -raw resource_group_name)
79+
```
80+
81+
1. Run [az vm list](/cli/azure/vm#az-vm-list) with a [JMESPath](/cli/azure/query-azure-cli) query to display the names of the virtual machines created in the resource group.
82+
83+
```azurecli
84+
az vm list \
85+
--resource-group $resource_group_name \
86+
--query "[].{\"VM Name\":name}" -o table
87+
```
88+
89+
#### [Azure PowerShell](#tab/azure-powershell)
90+
91+
1. Get the Azure resource group name.
92+
93+
```console
94+
$resource_group_name=$(terraform output -raw resource_group_name)
95+
```
96+
97+
1. Run [Get-AzVm](/powershell/module/az.compute/get-azvm) to display the names of all the virtual machines in the resource group.
98+
99+
```azurepowershell
100+
Get-AzVm -ResourceGroupName $resource_group_name
101+
```
102+
103+
---
104+
105+
## Clean up resources
106+
107+
[!INCLUDE [terraform-plan-destroy.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan-destroy.md)]
108+
109+
## Troubleshoot Terraform on Azure
110+
111+
[Troubleshoot common problems when using Terraform on Azure](/azure/developer/terraform/troubleshoot)
112+
113+
## Next steps
114+
115+
> [!div class="nextstepaction"]
116+
> [Azure Linux virtual machine tutorials](./tutorial-manage-vm.md)

0 commit comments

Comments
 (0)