Skip to content

Commit

Permalink
add default_route_table to virtual hub (#13840)
Browse files Browse the repository at this point in the history
* fix: add default_route_table_id to virtual hub resource

* fix: add default_route_table_id to virtual hub data resource
  • Loading branch information
josh-barker authored Oct 25, 2021
1 parent 5655725 commit e754516
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
14 changes: 14 additions & 0 deletions internal/services/network/virtual_hub_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/network/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/network/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tags"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
Expand Down Expand Up @@ -43,6 +44,11 @@ func dataSourceVirtualHub() *pluginsdk.Resource {
},

"tags": tags.SchemaDataSource(),

"default_route_table_id": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -80,5 +86,13 @@ func dataSourceVirtualHubRead(d *pluginsdk.ResourceData, meta interface{}) error
d.Set("virtual_wan_id", virtualWanId)
}

virtualHub, err := parse.VirtualHubID(*resp.ID)
if err != nil {
return err
}

defaultRouteTable := parse.NewHubRouteTableID(virtualHub.SubscriptionId, virtualHub.ResourceGroup, virtualHub.Name, "defaultRouteTable")
d.Set("default_route_table_id", defaultRouteTable.ID())

return tags.FlattenAndSet(d, resp.Tags)
}
8 changes: 8 additions & 0 deletions internal/services/network/virtual_hub_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ func resourceVirtualHub() *pluginsdk.Resource {
},

"tags": tags.Schema(),

"default_route_table_id": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -234,6 +239,9 @@ func resourceVirtualHubRead(d *pluginsdk.ResourceData, meta interface{}) error {
d.Set("virtual_wan_id", virtualWanId)
}

defaultRouteTable := parse.NewHubRouteTableID(id.SubscriptionId, id.ResourceGroup, id.Name, "defaultRouteTable")
d.Set("default_route_table_id", defaultRouteTable.ID())

return tags.FlattenAndSet(d, resp.Tags)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func TestAccVirtualHubRouteTableRoute_complete(t *testing.T) {
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That("azurerm_virtual_hub_route_table_route.test_2").ExistsInAzure(r),
check.That("azurerm_virtual_hub_route_table_route.test_3").ExistsInAzure(r),
),
},
data.ImportStep(),
Expand All @@ -75,6 +76,7 @@ func TestAccVirtualHubRouteTableRoute_update(t *testing.T) {
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That("azurerm_virtual_hub_route_table_route.test_2").ExistsInAzure(r),
check.That("azurerm_virtual_hub_route_table_route.test_3").ExistsInAzure(r),
),
},
data.ImportStep(),
Expand Down Expand Up @@ -233,5 +235,17 @@ resource "azurerm_virtual_hub_route_table_route" "test_2" {
next_hop_type = "ResourceId"
next_hop = azurerm_virtual_hub_connection.test.id
}
`, r.template(data), data.RandomInteger, data.RandomInteger)
// test a route on the default route table
resource "azurerm_virtual_hub_route_table_route" "test_3" {
route_table_id = azurerm_virtual_hub.test.default_route_table_id
name = "acctest-Route-%d"
destinations_type = "CIDR"
destinations = ["10.3.0.0/16"]
next_hop_type = "ResourceId"
next_hop = azurerm_virtual_hub_connection.test.id
}
`, r.template(data), data.RandomInteger, data.RandomInteger, data.RandomInteger)
}
4 changes: 2 additions & 2 deletions website/docs/d/virtual_hub.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ output "virtual_hub_id" {
}
```


## Argument Reference

The following arguments are supported:
Expand All @@ -32,7 +31,6 @@ The following arguments are supported:

* `resource_group_name` - The Name of the Resource Group where the Virtual Hub exists.


## Attributes Reference

The following attributes are exported:
Expand All @@ -45,6 +43,8 @@ The following attributes are exported:

* `virtual_wan_id` - The ID of the Virtual WAN within which the Virtual Hub exists.

* `default_route_table_id` - The ID of the default Route Table in the Virtual Hub.

## Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/virtual_hub.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ The following attributes are exported:

* `id` - The ID of the Virtual Hub.

* `default_route_table_id` - The ID of the default Route Table in the Virtual Hub.

## Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:
Expand Down

0 comments on commit e754516

Please sign in to comment.