不能通过资源azurerm_virtual_network_gateway_connection使用terraform创



请让我知道这是bug还是我犯了一个错误?我想用新订阅创建一个快速路由连接,如果我通过Azure GUI控制台工作正常,但通过terraform(应用阶段)失败。在地形计划(成功运行)中,我看到所有输入值正确,但我得到了下面的这个错误。有谁知道发生了什么事吗?

代码:

resource "azurerm_virtual_network_gateway_connection" "express_route_circuit_connection" {
name                = "az-prd-euw-expressrouteconn-001"
location            = azurerm_resource_group.resource_group.location
resource_group_name = azurerm_resource_group.resource_group.name
type                            = "ExpressRoute"
virtual_network_gateway_id      = azurerm_virtual_network_gateway.disaster_recovery_virtual_network_gateway.id
peer_virtual_network_gateway_id = data.azurerm_express_route_circuit.express_route_circuit.id
authorization_key               = azurerm_express_route_circuit_authorization.marel-disasterrecovery.authorization_key
routing_weight                  = 1
}

地形平面图阶段

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# module.disaster_recovery.azurerm_virtual_network_gateway_connection.express_route_circuit_connection will be created
+ resource "azurerm_virtual_network_gateway_connection" "express_route_circuit_connection" {
+ authorization_key                  = (sensitive value)
+ connection_mode                    = "Default"
+ connection_protocol                = (known after apply)
+ enable_bgp                         = (known after apply)
+ express_route_gateway_bypass       = (known after apply)
+ id                                 = (known after apply)
+ location                           = "westeurope"
+ name                               = "***********-expressrouteconn-001"
+ peer_virtual_network_gateway_id    = "/subscriptions/***********/resourceGroups/***********-rg-001/providers/Microsoft.Network/expressRouteCircuits/***********-001"
+ resource_group_name                = "***********-rg-001"
+ routing_weight                     = 1
+ type                               = "ExpressRoute"
+ use_policy_based_traffic_selectors = (known after apply)
+ virtual_network_gateway_id         = "/subscriptions/***********/resourceGroups/***********-rg-001/providers/Microsoft.Network/virtualNetworkGateways/***********-vgw-001"
}

遵循错误消息:

module.disaster_recovery.azurerm_virtual_network_gateway_connection.express_route_circuit_connection: Creating...
╷
│ Error: ID was missing the `virtualNetworkGateways` element
│
│   with module.disaster_recovery.azurerm_virtual_network_gateway_connection.express_route_circuit_connection,
│   on modules/disaster-recovery/network.tf line 118, in resource "azurerm_virtual_network_gateway_connection" "express_route_circuit_connection":
│  118: resource "azurerm_virtual_network_gateway_connection" "express_route_circuit_connection" {
│
你能帮我解决这个奇怪的问题吗?我真的很感谢你的帮助和时间

问候,

您可以遵循解决上述问题的变通方法之一;

您使用的类型是ExpressRoute,当您使用它时,您需要传递express_route_circuit_id代替peer_virtual_network_gateway_id因为当类型为Vnet2Vnet时使用。

例如: -

gateway_connection_type  = "ExpressRoute"
express_route_circuit_id = var.express_route_circuit_id

更多信息请参考以下链接:-

  • HashiCorp terrain Documentation|azurerm_virtual_network_gateway_connection.

  • GitHub回购|terraform-azurerm-vpn-gateway模块详细信息通过@kumarvna.

最新更新