Skip to content

Commit

Permalink
Fix error when changing route from virtual appliance to any other type (
Browse files Browse the repository at this point in the history
#2184)

* Route table now allows removing next-hop

* Route now allows removing next hop and is now more similar to route_table

* run gofmt 1.10.4 against resource_arm_route_table

* merge from master upstream and fix linting errors

* add route test for next_hop_type change

* add route table test for next_hop_type change

* Update route test to verify empty next hop ip

Co-Authored-By: draggeta <draggeta@users.noreply.github.com>

* Update route test to verify empty next hop ip

Co-Authored-By: draggeta <draggeta@users.noreply.github.com>

* ensuring the `next_hop_in_ip_address` field is always set

```
$ acctests azurerm TestAccAzureRMRoute_update
=== RUN   TestAccAzureRMRoute_update
--- PASS: TestAccAzureRMRoute_update (151.30s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	153.050s
```
  • Loading branch information
draggeta authored and tombuildsstuff committed Nov 7, 2018
1 parent 984662e commit b7c50a0
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 10 deletions.
16 changes: 7 additions & 9 deletions azurerm/resource_arm_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ func resourceArmRoute() *schema.Resource {
},

"address_prefix": {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.NoZeroValues,
},

"next_hop_type": {
Expand All @@ -57,9 +58,9 @@ func resourceArmRoute() *schema.Resource {
},

"next_hop_in_ip_address": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.NoZeroValues,
},
},
}
Expand Down Expand Up @@ -140,10 +141,7 @@ func resourceArmRouteRead(d *schema.ResourceData, meta interface{}) error {
if props := resp.RoutePropertiesFormat; props != nil {
d.Set("address_prefix", props.AddressPrefix)
d.Set("next_hop_type", string(props.NextHopType))

if ip := props.NextHopIPAddress; ip != nil {
d.Set("next_hop_in_ip_address", props.NextHopIPAddress)
}
d.Set("next_hop_in_ip_address", props.NextHopIPAddress)
}

return nil
Expand Down
1 change: 0 additions & 1 deletion azurerm/resource_arm_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func resourceArmRouteTable() *schema.Resource {
"next_hop_in_ip_address": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.NoZeroValues,
},
},
Expand Down
30 changes: 30 additions & 0 deletions azurerm/resource_arm_route_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ func TestAccAzureRMRouteTable_update(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "route.#", "0"),
),
},
{
Config: testAccAzureRMRouteTable_basicAppliance(ri, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMRouteTableExists("azurerm_route_table.test"),
resource.TestCheckResourceAttr(resourceName, "disable_bgp_route_propagation", "false"),
resource.TestCheckResourceAttr(resourceName, "route.#", "1"),
),
},
{
Config: testAccAzureRMRouteTable_complete(ri, testLocation()),
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -367,6 +375,28 @@ resource "azurerm_route_table" "test" {
`, rInt, location, rInt)
}

func testAccAzureRMRouteTable_basicAppliance(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_route_table" "test" {
name = "acctestrt%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
route {
name = "route1"
address_prefix = "10.1.0.0/16"
next_hop_type = "VirtualAppliance"
next_hop_in_ip_address = "192.168.0.1"
}
}
`, rInt, location, rInt)
}

func testAccAzureRMRouteTable_complete(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down
62 changes: 62 additions & 0 deletions azurerm/resource_arm_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,43 @@ func TestAccAzureRMRoute_basic(t *testing.T) {
})
}

func TestAccAzureRMRoute_update(t *testing.T) {
resourceName := "azurerm_route.test"
ri := acctest.RandInt()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMRouteDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMRoute_basic(ri, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMRouteExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "next_hop_type", "VnetLocal"),
resource.TestCheckResourceAttr(resourceName, "next_hop_in_ip_address", ""),
),
},
{
Config: testAccAzureRMRoute_basicAppliance(ri, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMRouteExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "next_hop_type", "VirtualAppliance"),
resource.TestCheckResourceAttr(resourceName, "next_hop_in_ip_address", "192.168.0.1"),
),
},
{
Config: testAccAzureRMRoute_basic(ri, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMRouteExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "next_hop_type", "VnetLocal"),
resource.TestCheckResourceAttr(resourceName, "next_hop_in_ip_address", ""),
),
},
},
})
}

func TestAccAzureRMRoute_disappears(t *testing.T) {
ri := acctest.RandInt()
config := testAccAzureRMRoute_basic(ri, testLocation())
Expand Down Expand Up @@ -197,6 +234,31 @@ resource "azurerm_route" "test" {
`, rInt, location, rInt, rInt)
}

func testAccAzureRMRoute_basicAppliance(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_route_table" "test" {
name = "acctestrt%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
}
resource "azurerm_route" "test" {
name = "acctestroute%d"
resource_group_name = "${azurerm_resource_group.test.name}"
route_table_name = "${azurerm_route_table.test.name}"
address_prefix = "10.1.0.0/16"
next_hop_type = "VirtualAppliance"
next_hop_in_ip_address = "192.168.0.1"
}
`, rInt, location, rInt, rInt)
}

func testAccAzureRMRoute_multipleRoutes(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down

0 comments on commit b7c50a0

Please sign in to comment.