2

I am creating an Azure load balancer that I need to route the incoming traffic to backend pool which consist of a virtual machine.

I am using Terraform to do this.

So far, I have created the followings:

  1. Load Balancer
  2. Load Balancer Rule
  3. Backend Address Pool
  4. A health probe

But in the terraform for backend, there's no way I can setup the IP address of the VM.

Here's my code. How can I do this?

resource "azurerm_lb" "example" {
  name                = "TestLoadBalancer"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  sku                 = "Standard"

  frontend_ip_configuration {
    name                          = "classiclb"
    subnet_id                     = azurerm_subnet.vm.id
    private_ip_address_allocation = "Dynamic"
  }
}

resource "azurerm_lb_backend_address_pool" "example" {
  loadbalancer_id = azurerm_lb.example.id
  name            = "classiclb"
}

resource "azurerm_lb_probe" "example" {
  resource_group_name = azurerm_resource_group.example.name
  loadbalancer_id     = azurerm_lb.example.id
  name                = "classiclb"
  port                = 80
  interval_in_seconds = 10
  number_of_probes    = 3
  protocol            = "Http"
  request_path        = "/"
}

resource "azurerm_lb_rule" "example" {
  resource_group_name            = azurerm_resource_group.example.name
  loadbalancer_id                = azurerm_lb.example.id
  name                           = "classiclb"
  protocol                       = "Tcp"
  frontend_port                  = 80
  backend_port                   = 80
  frontend_ip_configuration_name = "classiclb"
  backend_address_pool_id        = azurerm_lb_backend_address_pool.example.id
  probe_id                       = azurerm_lb_probe.example.id
}
Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
Jananath Banuka
  • 2,951
  • 8
  • 57
  • 105
  • 2
    Don't you need to use [azurerm_lb_backend_address_pool_address](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/lb_backend_address_pool_address) as well for that? – Marcin Jul 10 '21 at 10:56
  • Hey exactly what I was looking for. Thank you! – Jananath Banuka Jul 10 '21 at 11:01
  • Hey I get the error: `Invalid resource type │ │ on 12-lb.tf line 43, in resource "azurerm_lb_backend_address_pool_address" "example": │ 43: resource "azurerm_lb_backend_address_pool_address" "example" { │ │ The provider hashicorp/azurerm does not support resource type "azurerm_lb_backend_address_pool_address".` – Jananath Banuka Jul 10 '21 at 11:03
  • This seems to be a new issue, maybe you are using old version of the provider?. If you don't mind I will provide an answer for your original question. – Marcin Jul 10 '21 at 11:08

2 Answers2

3

Based on the comments, the addresses are added using azurerm_lb_backend_address_pool_address.

Marcin
  • 215,873
  • 14
  • 235
  • 294
  • Hi I am getting the error `The provider hashicorp/azurerm does not support resource type │ "azurerm_lb_backend_address_pool_address".` – Jananath Banuka Jul 10 '21 at 11:10
  • 1
    By upgrading the provider to the newest version (`2.67.0`) fixed this. Thank you! – Jananath Banuka Jul 10 '21 at 11:15
  • how did you able to find this resource? I searched literally everywhere but couldn't find it. – Jananath Banuka Jul 10 '21 at 11:26
  • @JananathBanuka Its listed in azurem docs. Maybe you look at old version of docs as well? – Marcin Jul 10 '21 at 23:10
  • Excuse me but that does not seem to reference a VM either. The documentation for `ip_address` says “The Static IP Address which should be *allocated to this Backend Address Pool*”, and it's *optional*. It also says it can only be added to sku=Standard LB, but sku=Basic LBs are supposed to work, aren't they? – Jan Hudec Jun 14 '23 at 17:12
0

I think the correct way to add a network interface into the backend address pool is using network_interface_backend_address_pool_association.

Jan Hudec
  • 73,652
  • 13
  • 125
  • 172