Skip to content

Commit

Permalink
backport AzureStack route resource PR comments (hashicorp#1810)
Browse files Browse the repository at this point in the history
  • Loading branch information
katbyte authored and tombuildsstuff committed Aug 23, 2018
1 parent 29ecee8 commit 25abf98
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 33 deletions.
3 changes: 1 addition & 2 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,7 @@ func ignoreCaseStateFunc(val interface{}) string {
}

func userDataDiffSuppressFunc(k, old, new string, d *schema.ResourceData) bool {
oldValue := userDataStateFunc(old)
return oldValue == new
return userDataStateFunc(old) == new
}

func userDataStateFunc(v interface{}) string {
Expand Down
38 changes: 19 additions & 19 deletions azurerm/resource_arm_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-04-01/network"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

Expand All @@ -15,23 +16,26 @@ func resourceArmRoute() *schema.Resource {
Read: resourceArmRouteRead,
Update: resourceArmRouteCreateUpdate,
Delete: resourceArmRouteDelete,

Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.NoZeroValues,
},

"resource_group_name": resourceGroupNameSchema(),

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

"address_prefix": {
Expand All @@ -49,7 +53,7 @@ func resourceArmRoute() *schema.Resource {
string(network.RouteNextHopTypeVirtualAppliance),
string(network.RouteNextHopTypeNone),
}, true),
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
DiffSuppressFunc: suppress.CaseDifference,
},

"next_hop_in_ip_address": {
Expand All @@ -75,28 +79,24 @@ func resourceArmRouteCreateUpdate(d *schema.ResourceData, meta interface{}) erro
azureRMLockByName(rtName, routeTableResourceName)
defer azureRMUnlockByName(rtName, routeTableResourceName)

properties := network.RoutePropertiesFormat{
AddressPrefix: &addressPrefix,
NextHopType: network.RouteNextHopType(nextHopType),
route := network.Route{
Name: &name,
RoutePropertiesFormat: &network.RoutePropertiesFormat{
AddressPrefix: &addressPrefix,
NextHopType: network.RouteNextHopType(nextHopType),
},
}

if v, ok := d.GetOk("next_hop_in_ip_address"); ok {
nextHopInIpAddress := v.(string)
properties.NextHopIPAddress = &nextHopInIpAddress
}

route := network.Route{
Name: &name,
RoutePropertiesFormat: &properties,
route.RoutePropertiesFormat.NextHopIPAddress = utils.String(v.(string))
}

future, err := client.CreateOrUpdate(ctx, resGroup, rtName, name, route)
if err != nil {
return fmt.Errorf("Error Creating/Updating Route %q (Route Table %q / Resource Group %q): %+v", name, rtName, resGroup, err)
}

err = future.WaitForCompletionRef(ctx, client.Client)
if err != nil {
if err := future.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("Error waiting for completion for Route %q (Route Table %q / Resource Group %q): %+v", name, rtName, resGroup, err)
}

Expand Down
24 changes: 12 additions & 12 deletions azurerm/resource_arm_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,47 +171,47 @@ func testCheckAzureRMRouteDestroy(s *terraform.State) error {
func testAccAzureRMRoute_basic(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_route_table" "test" {
name = "acctestrt%d"
location = "${azurerm_resource_group.test.location}"
name = "acctestrt%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
}
resource "azurerm_route" "test" {
name = "acctestroute%d"
name = "acctestroute%d"
resource_group_name = "${azurerm_resource_group.test.name}"
route_table_name = "${azurerm_route_table.test.name}"
route_table_name = "${azurerm_route_table.test.name}"
address_prefix = "10.1.0.0/16"
next_hop_type = "vnetlocal"
next_hop_type = "vnetlocal"
}
`, rInt, location, rInt, rInt)
}

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

0 comments on commit 25abf98

Please sign in to comment.