gpt4 book ai didi

azure - 在 Azure 中创建路由时,如何在 Terraform 中引用防火墙专用 IP 地址

转载 作者:行者123 更新时间:2023-12-03 06:18:24 28 4
gpt4 key购买 nike

我正在尝试通过 Terraform 创建 Azure 路由,并希望将下一个防火墙的私有(private) IP 地址作为下一个跃点地址。但所有编码都不起作用。

resource "azurerm_firewall" "Fireall-variable" {
name = "Main-Firewall"
location = azurerm_resource_group.East-rg-variable.location
resource_group_name = azurerm_resource_group.East-rg-variable.name
sku_name = "AZFW_VNet"
sku_tier = "Standard"

ip_configuration {
name = "configuration"
subnet_id = azurerm_subnet.subnet2.id
public_ip_address_id = azurerm_public_ip.Firewallip-variable.id
}
}

resource "azurerm_route_table" "westroute" {
name = "West-route-table"
location = azurerm_resource_group.East-rg-variable.location
resource_group_name = azurerm_resource_group.East-rg-variable.name
disable_bgp_route_propagation = false

route {
name = "route1"
address_prefix = "0.0.0.0/0"
next_hop_type = "VirtualAppliance"
next_hop_in_ip_address = "10.0.1.4"
}

最佳答案

我已经在我的环境中重现并得到了预期结果,如下:

这是我使用路由表创建 Azure 防火墙的代码,我遵循 Document1Document2 :

provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "emo-rg" {
name = "emo-resources"
location = "West Europe"
}

resource "azurerm_public_ip" "example" {
name = "testpip"
location = azurerm_resource_group.emo-rg.location
resource_group_name = azurerm_resource_group.emo-rg.name
allocation_method = "Static"
sku = "Standard"
}


resource "azurerm_virtual_network" "vnet" {
name = "ritwik-vnet"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.emo-rg.location
resource_group_name = azurerm_resource_group.emo-rg.name
}

resource "azurerm_subnet" "subnet" {
name = "AzureFirewallSubnet"
resource_group_name = azurerm_resource_group.emo-rg.name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefixes = ["10.0.1.0/24"]
}

resource "azurerm_firewall" "firewall" {
name = "testfirewall"
location = azurerm_resource_group.emo-rg.location
resource_group_name = azurerm_resource_group.emo-rg.name
sku_name = "AZFW_VNet"
sku_tier = "Premium"

ip_configuration {
name = "configuration"
subnet_id = azurerm_subnet.subnet.id
public_ip_address_id = azurerm_public_ip.example.id
}
}

resource "azurerm_route_table" "westroute" {
name = "West-route-table"
location = azurerm_resource_group.emo-rg.location
resource_group_name = azurerm_resource_group.emo-rg.name
disable_bgp_route_propagation = false

route {
name = "route1"
address_prefix = "0.0.0.0/0"
next_hop_type = "VirtualAppliance"
next_hop_in_ip_address = azurerm_firewall.firewall.ip_configuration[0].private_ip_address
}
}

enter image description here

输出:

执行 terraform 代码后创建的资源:

enter image description here

成功运行上述代码后,将使用以下 IP 地址创建路由表:

enter image description here

现在在防火墙中:

enter image description here

关于azure - 在 Azure 中创建路由时,如何在 Terraform 中引用防火墙专用 IP 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76055914/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com