Skip to content

Commit

Permalink
Merge pull request #403 from terraform-providers/route-table-rules
Browse files Browse the repository at this point in the history
`azurerm_route_table` - removing routes when none are specified
  • Loading branch information
tombuildsstuff committed Oct 6, 2017
2 parents f28dfa5 + ceac318 commit c695631
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
26 changes: 10 additions & 16 deletions azurerm/resource_arm_route_table.go
Expand Up @@ -36,7 +36,6 @@ func resourceArmRouteTable() *schema.Resource {
"route": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Expand Down Expand Up @@ -93,27 +92,22 @@ func resourceArmRouteTableCreate(d *schema.ResourceData, meta interface{}) error
resGroup := d.Get("resource_group_name").(string)
tags := d.Get("tags").(map[string]interface{})

routes, err := expandRouteTableRoutes(d)
if err != nil {
return fmt.Errorf("Error Expanding list of Route Table Routes: %+v", err)
}

routeSet := network.RouteTable{
Name: &name,
Location: &location,
Tags: expandTags(tags),
}

if _, ok := d.GetOk("route"); ok {
routes, routeErr := expandRouteTableRoutes(d)
if routeErr != nil {
return fmt.Errorf("Error Expanding list of Route Table Routes: %+v", routeErr)
}

if len(routes) > 0 {
routeSet.RouteTablePropertiesFormat = &network.RouteTablePropertiesFormat{
Routes: &routes,
}
}
RouteTablePropertiesFormat: &network.RouteTablePropertiesFormat{
Routes: &routes,
},
Tags: expandTags(tags),
}

_, createErr := client.CreateOrUpdate(resGroup, name, routeSet, make(chan struct{}))
err := <-createErr
err = <-createErr
if err != nil {
return err
}
Expand Down
29 changes: 29 additions & 0 deletions azurerm/resource_arm_route_table_test.go
Expand Up @@ -48,6 +48,35 @@ func TestAccAzureRMRouteTable_singleRoute(t *testing.T) {
})
}

func TestAccAzureRMRouteTable_removeRoute(t *testing.T) {
resourceName := "azurerm_route_table.test"
ri := acctest.RandInt()
config := testAccAzureRMRouteTable_singleRoute(ri, testLocation())
updatedConfig := testAccAzureRMRouteTable_basic(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMRouteTableDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMRouteTableExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "route.#", "1"),
),
},
{
Config: updatedConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMRouteTableExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "route.#", "0"),
),
},
},
})
}

func TestAccAzureRMRouteTable_disappears(t *testing.T) {
resourceName := "azurerm_route_table.test"
ri := acctest.RandInt()
Expand Down

0 comments on commit c695631

Please sign in to comment.