简体   繁体   English

如何在 Terraform 中为 Azure 负载均衡器添加具有虚拟机 IP 的后端

[英]How to add a backend with virtual machine IP for Azure Load Balancer in Terraform

I am creating an Azure load balancer that I need to route the incoming traffic to backend pool which consist of a virtual machine.我正在创建一个 Azure 负载均衡器,我需要将传入流量路由到由虚拟机组成的后端池。

I am using Terraform to do this.我正在使用 Terraform 来做到这一点。

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.但是在后端的terraform中,我无法设置 VM 的 IP 地址。

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
}

根据注释,使用azurerm_lb_backend_address_pool_address添加地址。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 azure 中的虚拟机 ping 负载均衡器 ip 地址 - How to ping the load balancer ip address from Virtual machine in azure 使用Terraform将Azure可用性集添加到Load Balancer(后端池) - Add Azure Availability Set to Load Balancer (backend pool) to with Terraform 使用没有负载平衡器的 terraform 设置虚拟机规模? - virtual machine scale set using terraform without load balancer? 如何在 terraform 中的 AKS 群集资源创建的虚拟机规模集或负载均衡器上启用诊断日志? - How to enable diagnostic logs on Virtual Machine Scale Set or Load Balancer created by AKS cluster resource in terraform? Azure负载平衡器我无法选择目标虚拟机 - Azure load balancer I can't select the target virtual machine Azure负载平衡器(资源管理器)-如何将公共IP用于后端池 - Azure Load Balancer (Resource Manager) - How to use public IP for backend pool 在现有v-net中创建Azure负载均衡器时会担心“负载均衡器未引用所有后端IP配置” - Create Azure Load Balancer in existing v-net fears to “Not all Backend IP Configurations referenced by the Load Balancer” Terraform 销毁 azure 负载均衡器 - Terraform destroy azure load balancer 如何使用 Terraform 将 VM 添加到 Azure 中的负载均衡器? - How can I add a VM into a Load Balancer within Azure using Terraform? 使用PowerShell将可用性集添加到Azure负载均衡器的后端池 - Using PowerShell to add an Availability Set to Backend Pool for Azure Load Balancer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM