Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for azurerm_virtual_hub_route_table route as a distinct resource. #11169

Closed
TomKimber opened this issue Mar 31, 2021 · 5 comments
Closed
Labels
enhancement new-virtual-resource Resources which are split out to enhance the user experience service/virtual-hub
Milestone

Comments

@TomKimber
Copy link

TomKimber commented Mar 31, 2021

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

Support for azurerm_virtual_hub_route_table routes as a distinct resource. This would be useful as in the current implementation to routes for a azurerm_virtual_hub_route_table are created in the route block, a required parameter in that block is "next_hop", "next_hop" requires a azurerm_virtual_hub_connection ID.

If I'm defining a azurerm_virtual_hub_connection in the same Terraform and I want to either associate the route table with the connection using the "associated_route_table_id" in the routing block or associate a list of route table resources with the connection via the route_table_ids in the propagated_route_table block this causes a cyclical dependency due to the route requiring a connection to create and the connection requiring a route table to create. This would be solved if the azurerm_virtual_hub_route_table route could be created as a distinct resource in line with the way regular Route Table/Routes can be created.

New or Affected Resource(s)

  • azurerm_virtual_hub_route_table
  • azurerm_virtual_hub_connection

Potential Terraform Configuration

resource "azurerm_virtualhub_route" "example" {
  name              = "acceptanceTestRoute1"
  destinations_type = "CIDR"
  destinations      = ["10.0.0.0/16"] 
  next_hop_type     = "ResourceId"
  next_hop          = azurerm_virtual_hub_connection.example.id
  route_table = azurerm_virtual_hub_route_table.example.id
}

References

@josh-barker
Copy link
Contributor

Hi all,

I've been looking at how we can solve this.
From what I can find, there isn't an API for a single route.
If we were to implement a resource as described above, that would mean that for each route there would be multiple API calls to GET, PUT/POST to the Route Table API. Each Route resource would have to be run sequentially so that the Route Table ends up with all of the routes in the end.

Let me know if I have overlooked something.

I have 2 additional options.

  1. Option 1: A routing configuration resource - new resource: azurerm_virtual_hub_connection_routing
    How does this help?
    It allows the connection to be created, then the route table can create routes that refer back to the connection.
    Finally, the azurerm_virtual_hub_connection_routing resource can associate the route table to the connection.

This option also allows the propagated route tables and static routes to be managed in this new resource.

The downside to this is that you can either configure a connection inside the azurerm_virtual_hub_connection resource or the azurerm_virtual_hub_connection_routing resource, but not both.

resource "azurerm_virtual_hub" "example" {
  name                = "example-vhub"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  virtual_wan_id      = azurerm_virtual_wan.example.id
  address_prefix      = "10.0.2.0/24"
}

resource "azurerm_virtual_hub_connection" "example" {
  name                      = "example-vhubconn"
  virtual_hub_id            = azurerm_virtual_hub.example.id
  remote_virtual_network_id = azurerm_virtual_network.example.id
}

resource "azurerm_virtual_hub_route_table" "example" {
  name           = "example-vhubroutetable"
  virtual_hub_id = azurerm_virtual_hub.example.id
  labels         = ["label1"]

  route {
    name              = "example-route"
    destinations_type = "CIDR"
    destinations      = ["10.0.0.0/16"]
    next_hop_type     = "ResourceId"
    next_hop          = azurerm_virtual_hub_connection.example.id
  }
}

resource "azurerm_virtual_hub_connection_routing" "example" {
  virtual_hub_connection_id = azurerm_virtual_hub_connection.example.id

  associated_route_table_id = azurerm_virtual_hub_route_table.example.id

  propagated_route_table {
      labels = ["some", "labels"]
      route_table_ids = [
        azurerm_virtual_hub_route_table.example1.id, 
        azurerm_virtual_hub_route_table.example2.id
      ]
  }

  static_vnet_route {
    name                = "testvnetroute"
    address_prefixes    = ["10.0.3.0/24", "10.0.4.0/24"]
    next_hop_ip_address = "10.0.3.5"
  }

  static_vnet_route {
    name                = "testvnetroute2"
    address_prefixes    = ["10.0.5.0/24"]
    next_hop_ip_address = "10.0.5.5"
  }
}
  1. Association resources - New resources: azurerm_virtual_hub_connection_route_table_association, azurerm_virtual_hub_connection_propagation_route_table_association
    How does this help?
    It allows the connection to be created, then the route table can create routes that refer back to the connection.
    Finally, the azurerm_virtual_hub_connection_route_table_association resource can associate the route table to the connection.

The downside to this option is that multiple resources would need to be created for each of the elements in the routing block.

resource "azurerm_virtual_hub" "example" {
  name                = "example-vhub"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  virtual_wan_id      = azurerm_virtual_wan.example.id
  address_prefix      = "10.0.2.0/24"
}

resource "azurerm_virtual_hub_connection" "example" {
  name                      = "example-vhubconn"
  virtual_hub_id            = azurerm_virtual_hub.example.id
  remote_virtual_network_id = azurerm_virtual_network.example.id
}

resource "azurerm_virtual_hub_route_table" "example" {
  name           = "example-vhubroutetable"
  virtual_hub_id = azurerm_virtual_hub.example.id
  labels         = ["label1"]

  route {
    name              = "example-route"
    destinations_type = "CIDR"
    destinations      = ["10.0.0.0/16"]
    next_hop_type     = "ResourceId"
    next_hop          = azurerm_virtual_hub_connection.example.id
  }
}

resource "azurerm_virtual_hub_connection_route_table_association" "example" {
  virtual_hub_connection_id = azurerm_virtual_hub.example.id
  route_table_id            = azurerm_virtual_hub_route_table.example.id
}

I think option 1 is the best way forward, as we only need to make 1 more resource.

I have been able to build a rough implementation of option 2 and will begin implementing option 1.

I'll create 2 x draft PRs and link to this issues for further discussion.

@NikolaiKleppe
Copy link

Hi, I see that #11644 was closed as duplicate to this issue. @tombuildsstuff

Do you know if the fix you're working on @josh-barker will help with this, as suggested in the issue above? Just to make sure we're aligned here as that one is a pretty important issue as well.

@katbyte katbyte added this to the v2.82.0 milestone Oct 21, 2021
katbyte pushed a commit that referenced this issue Oct 21, 2021
@katbyte katbyte closed this as completed Oct 21, 2021
@github-actions
Copy link

This functionality has been released in v2.82.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@josh-barker
Copy link
Contributor

Hey @NikolaiKleppe, yep this new route resource can be used to create a route on a default route table.
For example:

resource "azurerm_virtual_hub_route_table_route" "example" {
  route_table_id = "${azurerm_virtual_hub.example.id}/hubRouteTables/defaultRouteTable"

  name              = "example-route"
  destinations_type = "CIDR"
  destinations      = ["10.0.0.0/16"]
  next_hop_type     = "ResourceId"
  next_hop          = azurerm_virtual_hub_connection.example.id
}

As that's a bit clunky, I'm going to create a new PR to add default_route_table_id to the azurerm_virtual_hub resource.

Example configuration:

resource "azurerm_virtual_hub_route_table_route" "example" {
  route_table_id = azurerm_virtual_hub.example.default_route_table_id

  name              = "example-route"
  destinations_type = "CIDR"
  destinations      = ["10.0.0.0/16"]
  next_hop_type     = "ResourceId"
  next_hop          = azurerm_virtual_hub_connection.example.id
}

I'll mention this issue and #11644 in the new PR when I've created it.

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement new-virtual-resource Resources which are split out to enhance the user experience service/virtual-hub
Projects
None yet
Development

No branches or pull requests

5 participants