如何在 Terraform 中为 Azure 负载均衡器添加具有虚拟机 IP 的后端
How to add a backend with virtual machine IP for Azure Load Balancer in Terraform
我正在创建一个 Azure 负载均衡器,我需要将传入流量路由到由虚拟机组成的后端池。
我正在使用 Terraform 来执行此操作。
到目前为止,我已经创建了以下内容:
- 负载均衡器
- 负载均衡器规则
- 后端地址池
- 健康探测器
但是在后端的 terraform
中,我无法设置虚拟机的 IP 地址。
这是我的代码。我该怎么做?
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
}
根据评论,使用 azurerm_lb_backend_address_pool_address 添加地址。
我正在创建一个 Azure 负载均衡器,我需要将传入流量路由到由虚拟机组成的后端池。
我正在使用 Terraform 来执行此操作。
到目前为止,我已经创建了以下内容:
- 负载均衡器
- 负载均衡器规则
- 后端地址池
- 健康探测器
但是在后端的 terraform
中,我无法设置虚拟机的 IP 地址。
这是我的代码。我该怎么做?
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
}
根据评论,使用 azurerm_lb_backend_address_pool_address 添加地址。