From ceac318698b8e71ec931b7a4c3ea69553681993d Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 6 Oct 2017 15:10:22 +0100 Subject: [PATCH] Removing Route's when none are defined. Fixes #39 ``` $ acctests azurerm TestAccAzureRMRouteTable_removeRoute === RUN TestAccAzureRMRouteTable_removeRoute --- PASS: TestAccAzureRMRouteTable_removeRoute (93.89s) PASS ok github.com/terraform-providers/terraform-provider-azurerm/azurerm 93.914s ``` --- azurerm/resource_arm_route_table.go | 26 ++++++++------------- azurerm/resource_arm_route_table_test.go | 29 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/azurerm/resource_arm_route_table.go b/azurerm/resource_arm_route_table.go index 459966c73e02..51bef9c0cdfc 100644 --- a/azurerm/resource_arm_route_table.go +++ b/azurerm/resource_arm_route_table.go @@ -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": { @@ -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 } diff --git a/azurerm/resource_arm_route_table_test.go b/azurerm/resource_arm_route_table_test.go index bf26ebfc680e..e532e956843e 100644 --- a/azurerm/resource_arm_route_table_test.go +++ b/azurerm/resource_arm_route_table_test.go @@ -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()