0

不知道我做错了什么。我在 terraform 配置中只有一个 NAT 规则,而且我没有使用 NAT 池。

错误:

azurerm_virtual_machine_scale_set.development-eastus-ss:     compute.VirtualMachineScaleSetsClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="InvalidRequestFormat" Message="Cannot parse the request." Details=[{"code":"InvalidJsonReferenceWrongType","message":"Reference Id /subscriptions/sub-id/resourceGroups/prod-eastus-rg/providers/Microsoft.Network/loadBalancers/development-eastus-lb/inboundNatRules/development-eastus-lb-nat-http is referencing resource of a wrong type. The Id is expected to reference resources of type loadBalancers/inboundNatPools. Path Properties.UpdateGroups[0].NetworkProfile.networkInterfaceConfigurations[0].properties.ipConfigurations[0].properties.loadBalancerInboundNatPools[0]."}]

NAT 规则:

resource "azurerm_lb_nat_rule" "development-eastus-lb-nat-http" {
  name                           = "development-eastus-lb-nat-http"
  resource_group_name            = "${var.resource_group_name}"
  loadbalancer_id                = "${azurerm_lb.development-eastus-lb.id}"
  protocol                       = "Tcp"
  frontend_port                  = 80
  backend_port                   = 8080
  frontend_ip_configuration_name = "development-eastus-lb-frontend"
4

1 回答 1

1

看起来这是尝试将单个 nat 规则绑定到比例集的问题。正如错误所暗示的那样,它期望一个nat 池而不是一个nat 规则,一个 nat 池将允许负载均衡器和规模集构建一组规则,其中负载均衡器将为每个底层 VM 公开不同的端口到同一端口在虚拟机上。

考虑一下您希望能够远程访问特定 VM 的 RDP,这将通过为您提供一个唯一的端口来使用该端口来映射到该 VM 来实现这一点。

resource "azurerm_lb_nat_pool" "test" {
  resource_group_name            = "${azurerm_resource_group.test.name}"
  loadbalancer_id                = "${azurerm_lb.test.id}"
  name                           = "SampleApplicationPool"
  protocol                       = "Tcp"
  frontend_port_start            = 80
  frontend_port_end              = 81
  backend_port                   = 8080
  frontend_ip_configuration_name = "PublicIPAddress"
}

但是,如果您希望在内部与外部不同的端口上运行诸如 HTTP 网站之类的服务,例如本地网络上的 8080 和外部公共网络上的端口 80,那么我会看一下lb规则这特别允许您设置端口,如下所示。

resource "azurerm_lb_rule" "test" {
  resource_group_name            = "${azurerm_resource_group.test.name}"
  loadbalancer_id                = "${azurerm_lb.test.id}"
  name                           = "LBRule"
  protocol                       = "Tcp"
  frontend_port                  = 3389
  backend_port                   = 3389
  frontend_ip_configuration_name = "PublicIPAddress"
}

希望这会有所帮助

于 2018-07-06T12:14:07.003 回答