You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: "Quickstart: Create a public load balancer - Terraform"
2
+
title: 'Quickstart: Create a public load balancer - Terraform'
3
3
titleSuffix: Azure Load Balancer
4
4
description: This quickstart shows how to create a load balancer by using Terraform.
5
5
services: load-balancer
6
6
author: mbender-ms
7
7
manager: kumudD
8
8
ms.service: azure-load-balancer
9
9
ms.topic: quickstart
10
-
ms.date: 01/10/2025
10
+
ms.date: 04/01/2025
11
11
ms.author: mbender
12
12
ms.custom: devx-track-terraform
13
13
#Customer intent: I want to create a load balancer by using Terraform so that I can load balance internet traffic to VMs.
@@ -31,316 +31,34 @@ This quickstart shows you how to deploy a standard load balancer to load balance
31
31
> * Create an Azure Virtual Machine Extension using [azurerm_virtual_machine_extension](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_machine_extension)
32
32
33
33
## Prerequisites
34
+
- Create an Azure account with an active subscription. You can [create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
34
35
35
36
-[Install and configure Terraform](/azure/developer/terraform/quickstart-configure)
36
37
37
38
## Implement the Terraform code
38
39
39
-
> [!NOTE]
40
-
> See more [articles and sample code showing how to use Terraform to manage Azure resources](/azure/terraform)
40
+
The sample code for this article is located in the [Azure Terraform GitHub repo](https://github.com/Azure/terraform/tree/master/quickstart/101-azure-load-balancer-public). 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-azure-load-balancer-public/TestRecord.md). See more [articles and sample code showing how to use Terraform to manage Azure resources](/azure/terraform)
41
41
42
-
1. Create a directory in which to test the sample Terraform code and make it the current directory.
42
+
1. Create a directory in which to test and run the sample Terraform code, and make it the current directory.
43
43
44
-
1. Create a file named `providers.tf` and insert the following code:
44
+
1. Create a file named `providers.tf` and insert the following code.
description = "The username for the local account that will be created on the new VM."
268
-
}
269
-
270
-
variable "password" {
271
-
type = string
272
-
default = "Microsoft@123"
273
-
description = "The password for the local account that will be created on the new VM."
274
-
}
275
-
276
-
variable "virtual_network_name" {
277
-
type = string
278
-
default = "test-vnet"
279
-
description = "Name of the Virtual Network."
280
-
}
281
-
282
-
variable "subnet_name" {
283
-
type = string
284
-
default = "test-subnet"
285
-
description = "Name of the subnet."
286
-
}
287
-
288
-
variable public_ip_name {
289
-
type = string
290
-
default = "test-public-ip"
291
-
description = "Name of the Public IP."
292
-
}
293
-
294
-
variable network_security_group_name {
295
-
type = string
296
-
default = "test-nsg"
297
-
description = "Name of the Network Security Group."
298
-
}
299
-
300
-
variable "network_interface_name" {
301
-
type = string
302
-
default = "test-nic"
303
-
description = "Name of the Network Interface."
304
-
}
305
-
306
-
variable "virtual_machine_name" {
307
-
type = string
308
-
default = "test-vm"
309
-
description = "Name of the Virtual Machine."
310
-
}
311
-
312
-
variable "virtual_machine_size" {
313
-
type = string
314
-
default = "Standard_B2s"
315
-
description = "Size or SKU of the Virtual Machine."
316
-
}
317
-
318
-
variable "disk_name" {
319
-
type = string
320
-
default = "test-disk"
321
-
description = "Name of the OS disk of the Virtual Machine."
322
-
}
323
-
324
-
variable "redundancy_type" {
325
-
type = string
326
-
default = "Standard_LRS"
327
-
description = "Storage redundancy type of the OS disk."
328
-
}
329
-
330
-
variable "load_balancer_name" {
331
-
type = string
332
-
default = "test-lb"
333
-
description = "Name of the Load Balancer."
334
-
}
335
-
```
336
-
337
-
1. Create a file named `outputs.tf` and insert the following code:
338
-
339
-
```
340
-
output "public_ip_address" {
341
-
value = "http://${azurerm_public_ip.my_public_ip.ip_address}"
342
-
}
343
-
```
56
+
> [!IMPORTANT]
57
+
> If you're using the 4.x azurerm provider, you must [explicitly specify the Azure subscription ID](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/4.0-upgrade-guide#specifying-subscription-id-is-now-mandatory) to authenticate to Azure before running the Terraform commands.
58
+
>
59
+
> One way to specify the Azure subscription ID without putting it in the `providers` block is to specify the subscription ID in an environment variable named `ARM_SUBSCRIPTION_ID`.
60
+
>
61
+
> For more information, see the [Azure provider reference documentation](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs#argument-reference).
344
62
345
63
## Initialize Terraform
346
64
@@ -356,10 +74,22 @@ This quickstart shows you how to deploy a standard load balancer to load balance
356
74
357
75
## Verify the results
358
76
359
-
1. When you apply the execution plan, Terraform displays the frontend public IP address. If you've cleared the screen, you can retrieve that value with the following Terraform command:
77
+
1.Display the Azure resource group name.
360
78
361
79
```console
362
-
echo $(terraform output -raw public_ip_address)
80
+
terraform output -raw resource_group_name
81
+
```
82
+
83
+
1. Optionally, display the VM (virtual machine) password.
84
+
85
+
```console
86
+
terraform output -raw vm_password
87
+
```
88
+
89
+
1. Display the public IP address.
90
+
91
+
```console
92
+
terraform output -raw public_ip_address
363
93
```
364
94
365
95
1. Paste the public IP address into the address bar of your web browser. The custom VM page of the Nginx web server is displayed in the browser.
@@ -374,12 +104,6 @@ This quickstart shows you how to deploy a standard load balancer to load balance
374
104
375
105
## Next steps
376
106
377
-
In this quickstart, you:
378
-
379
-
* Created an Azure Load Balancer
380
-
* Attached 2 VMs to the load balancer
381
-
* Tested the load balancer
382
-
383
-
To learn more about Azure Load Balancer, continue to:
384
107
> [!div class="nextstepaction"]
385
108
> [What is Azure Load Balancer?](load-balancer-overview.md)
0 commit comments