Skip to content

Commit

Permalink
Removing Route's when none are defined. Fixes #39
Browse files Browse the repository at this point in the history
```
$ acctests azurerm TestAccAzureRMRouteTable_removeRoute
=== RUN   TestAccAzureRMRouteTable_removeRoute
--- PASS: TestAccAzureRMRouteTable_removeRoute (93.89s)
PASS
ok      github.com/terraform-providers/terraform-provider-azurerm/azurerm    93.914s
```
  • Loading branch information
tombuildsstuff committed Oct 6, 2017
1 parent e14c45c commit ceac318
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 ceac318

Please sign in to comment.