Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when changing route from virtual appliance to any other type #2184

Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 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
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"),
draggeta marked this conversation as resolved.
Show resolved Hide resolved
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"),
draggeta marked this conversation as resolved.
Show resolved Hide resolved
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