From 6f11f6ac9af3942a66a1fcfea87f5927f81b98a9 Mon Sep 17 00:00:00 2001 From: Tony Fortes Ramos Date: Tue, 30 Oct 2018 11:14:42 +0100 Subject: [PATCH 1/9] Route table now allows removing next-hop --- azurerm/resource_arm_route.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/azurerm/resource_arm_route.go b/azurerm/resource_arm_route.go index b5f889f52a85..c4dd395e42d0 100644 --- a/azurerm/resource_arm_route.go +++ b/azurerm/resource_arm_route.go @@ -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": { @@ -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, }, }, } From 53aafdbc192f29ccc70934d942791e231eb46427 Mon Sep 17 00:00:00 2001 From: Tony Fortes Ramos Date: Tue, 30 Oct 2018 11:15:52 +0100 Subject: [PATCH 2/9] Route now allows removing next hop and is now more similar to route_table --- azurerm/resource_arm_route_table.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/azurerm/resource_arm_route_table.go b/azurerm/resource_arm_route_table.go index 773193a47a0f..6a67ddf5b33a 100644 --- a/azurerm/resource_arm_route_table.go +++ b/azurerm/resource_arm_route_table.go @@ -71,7 +71,6 @@ func resourceArmRouteTable() *schema.Resource { "next_hop_in_ip_address": { Type: schema.TypeString, Optional: true, - Computed: true, ValidateFunc: validation.NoZeroValues, }, }, @@ -111,7 +110,7 @@ func resourceArmRouteTableCreateUpdate(d *schema.ResourceData, meta interface{}) Name: &name, Location: &location, RouteTablePropertiesFormat: &network.RouteTablePropertiesFormat{ - Routes: expandRouteTableRoutes(d), + Routes: expandRouteTableRoutes(d), DisableBgpRoutePropagation: utils.Bool(d.Get("disable_bgp_route_propagation").(bool)), }, Tags: expandTags(tags), From b2693057c80d169ee2774d0216b226c37332b369 Mon Sep 17 00:00:00 2001 From: Tony Fortes Ramos Date: Tue, 30 Oct 2018 11:29:47 +0100 Subject: [PATCH 3/9] run gofmt 1.10.4 against resource_arm_route_table --- azurerm/resource_arm_route_table.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_route_table.go b/azurerm/resource_arm_route_table.go index 6a67ddf5b33a..734de1380238 100644 --- a/azurerm/resource_arm_route_table.go +++ b/azurerm/resource_arm_route_table.go @@ -110,7 +110,7 @@ func resourceArmRouteTableCreateUpdate(d *schema.ResourceData, meta interface{}) Name: &name, Location: &location, RouteTablePropertiesFormat: &network.RouteTablePropertiesFormat{ - Routes: expandRouteTableRoutes(d), + Routes: expandRouteTableRoutes(d), DisableBgpRoutePropagation: utils.Bool(d.Get("disable_bgp_route_propagation").(bool)), }, Tags: expandTags(tags), From 2e44211440a0ddcec0291cd5cc789d24e2add798 Mon Sep 17 00:00:00 2001 From: Tony Fortes Ramos Date: Tue, 30 Oct 2018 14:10:55 +0100 Subject: [PATCH 4/9] merge from master upstream and fix linting errors --- azurerm/resource_arm_eventhub_namespace.go | 2 +- azurerm/resource_arm_managed_disk.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/azurerm/resource_arm_eventhub_namespace.go b/azurerm/resource_arm_eventhub_namespace.go index 62aeacbacaa2..260ee9433478 100644 --- a/azurerm/resource_arm_eventhub_namespace.go +++ b/azurerm/resource_arm_eventhub_namespace.go @@ -3,7 +3,6 @@ package azurerm import ( "context" "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" "log" "strconv" "time" @@ -14,6 +13,7 @@ import ( "github.com/hashicorp/terraform/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) diff --git a/azurerm/resource_arm_managed_disk.go b/azurerm/resource_arm_managed_disk.go index 529196a8c7a4..7d4465c2a17d 100644 --- a/azurerm/resource_arm_managed_disk.go +++ b/azurerm/resource_arm_managed_disk.go @@ -2,7 +2,6 @@ package azurerm import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" "log" "strings" @@ -10,6 +9,7 @@ import ( "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) From 05c1dd69bb0bfb999901829c720f6c0fce97a787 Mon Sep 17 00:00:00 2001 From: Tony Fortes Ramos Date: Tue, 30 Oct 2018 22:13:27 +0100 Subject: [PATCH 5/9] add route test for next_hop_type change --- azurerm/resource_arm_route_test.go | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/azurerm/resource_arm_route_test.go b/azurerm/resource_arm_route_test.go index 0c1acc978f64..c7cdc935c89c 100644 --- a/azurerm/resource_arm_route_test.go +++ b/azurerm/resource_arm_route_test.go @@ -35,6 +35,41 @@ 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"), + ), + }, + { + 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"), + ), + }, + }, + }) +} + func TestAccAzureRMRoute_disappears(t *testing.T) { ri := acctest.RandInt() config := testAccAzureRMRoute_basic(ri, testLocation()) @@ -197,6 +232,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" { From 4860048d6bbccdb9927ca7b3876a2f6155463466 Mon Sep 17 00:00:00 2001 From: Tony Fortes Ramos Date: Tue, 30 Oct 2018 22:13:36 +0100 Subject: [PATCH 6/9] add route table test for next_hop_type change --- azurerm/resource_arm_route_table_test.go | 38 +++++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/azurerm/resource_arm_route_table_test.go b/azurerm/resource_arm_route_table_test.go index 634c35fda922..4db36353ec85 100644 --- a/azurerm/resource_arm_route_table_test.go +++ b/azurerm/resource_arm_route_table_test.go @@ -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( @@ -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" { @@ -520,12 +550,12 @@ resource "azurerm_virtual_network" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" address_space = ["10.0.0.0/16"] - + tags { environment = "staging" } } - + resource "azurerm_subnet" "subnet1" { name = "subnet1" resource_group_name = "${azurerm_resource_group.test.name}" @@ -568,13 +598,13 @@ resource "azurerm_virtual_network" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" address_space = ["10.0.0.0/16"] - + tags { environment = "staging" cloud = "Azure" } } - + resource "azurerm_subnet" "subnet1" { name = "subnet1" resource_group_name = "${azurerm_resource_group.test.name}" From 4d81815c6ea209672a0c983f4a831a095dfe3791 Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Tue, 6 Nov 2018 13:13:15 +0100 Subject: [PATCH 7/9] Update route test to verify empty next hop ip Co-Authored-By: draggeta --- azurerm/resource_arm_route_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/azurerm/resource_arm_route_test.go b/azurerm/resource_arm_route_test.go index 7b4492430c83..b2d8e1146b2f 100644 --- a/azurerm/resource_arm_route_test.go +++ b/azurerm/resource_arm_route_test.go @@ -64,6 +64,7 @@ func TestAccAzureRMRoute_update(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMRouteExists(resourceName), resource.TestCheckResourceAttr(resourceName, "next_hop_type", "VnetLocal"), + resource.TestCheckResourceAttr(resourceName, "next_hop_in_ip_address", ""), ), }, }, From d90f7fa1aaadbd38769abb6c6fc3a7d224b0e244 Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Tue, 6 Nov 2018 13:15:52 +0100 Subject: [PATCH 8/9] Update route test to verify empty next hop ip Co-Authored-By: draggeta --- azurerm/resource_arm_route_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/azurerm/resource_arm_route_test.go b/azurerm/resource_arm_route_test.go index b2d8e1146b2f..472fd6e7f646 100644 --- a/azurerm/resource_arm_route_test.go +++ b/azurerm/resource_arm_route_test.go @@ -49,6 +49,7 @@ func TestAccAzureRMRoute_update(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMRouteExists(resourceName), resource.TestCheckResourceAttr(resourceName, "next_hop_type", "VnetLocal"), + resource.TestCheckResourceAttr(resourceName, "next_hop_in_ip_address", ""), ), }, { From 26c9e8c58e4e9969af292a8dc2592aa0fffe385d Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Wed, 7 Nov 2018 13:19:31 +0000 Subject: [PATCH 9/9] 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 ``` --- azurerm/resource_arm_route.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/azurerm/resource_arm_route.go b/azurerm/resource_arm_route.go index edd572e25722..3a53f0c2ff37 100644 --- a/azurerm/resource_arm_route.go +++ b/azurerm/resource_arm_route.go @@ -141,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