0

I am trying to create Route for Azure through Terraform and and wants to next Firewall's private IP address as next hop address. But none of the coding is working.

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"
 }

1 Answers1

1

I have reproduced in my environment and got expected results as below:

Here is the code with which I created Azure Firewall with route table and I followed Document1 and Document2:

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

Output:

Resources created after executing terraform code:

enter image description here

After running the above code successfully, Route table is created with the below IP Address:

enter image description here

Now in Firewall:

enter image description here

RithwikBojja
  • 5,069
  • 2
  • 3
  • 7