Skip to content

Commit

Permalink
azurerm_virtual_network_gateway: ignoring the case of `GatewaySubne…
Browse files Browse the repository at this point in the history
…t` (#1141)

* ignore case for gateway subnet name

* Adding an acceptance test covering the subnet-name being in lowerCase
  • Loading branch information
YuriyKishchenko authored and tombuildsstuff committed May 6, 2018
1 parent 182b29c commit c1bf682
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
3 changes: 2 additions & 1 deletion azurerm/resource_arm_virtual_network_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"log"
"strings"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2017-09-01/network"
"github.com/hashicorp/terraform/helper/hashcode"
Expand Down Expand Up @@ -628,7 +629,7 @@ func validateArmVirtualNetworkGatewaySubnetId(i interface{}, k string) (s []stri
return
}

if subnet != "GatewaySubnet" {
if strings.ToLower(subnet) != "gatewaysubnet" {
es = append(es, fmt.Errorf("expected %s to reference a gateway subnet with name GatewaySubnet", k))
}

Expand Down
65 changes: 65 additions & 0 deletions azurerm/resource_arm_virtual_network_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ func TestAccAzureRMVirtualNetworkGateway_basic(t *testing.T) {
})
}

func TestAccAzureRMVirtualNetworkGateway_lowerCaseSubnetName(t *testing.T) {
ri := acctest.RandInt()
config := testAccAzureRMVirtualNetworkGateway_lowerCaseSubnetName(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualNetworkGatewayDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualNetworkGatewayExists("azurerm_virtual_network_gateway.test"),
),
},
},
})
}

func TestAccAzureRMVirtualNetworkGateway_vpnGw1(t *testing.T) {
ri := acctest.RandInt()
config := testAccAzureRMVirtualNetworkGateway_vpnGw1(ri, testLocation())
Expand Down Expand Up @@ -162,6 +181,52 @@ resource "azurerm_virtual_network_gateway" "test" {
`, rInt, location, rInt, rInt, rInt)
}

func testAccAzureRMVirtualNetworkGateway_lowerCaseSubnetName(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_virtual_network" "test" {
name = "acctestvn-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
address_space = ["10.0.0.0/16"]
}
resource "azurerm_subnet" "test" {
name = "gatewaySubnet"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.1.0/24"
}
resource "azurerm_public_ip" "test" {
name = "acctestpip-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
public_ip_address_allocation = "Dynamic"
}
resource "azurerm_virtual_network_gateway" "test" {
name = "acctestvng-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
type = "Vpn"
vpn_type = "RouteBased"
sku = "Basic"
ip_configuration {
public_ip_address_id = "${azurerm_public_ip.test.id}"
private_ip_address_allocation = "Dynamic"
subnet_id = "${azurerm_subnet.test.id}"
}
}
`, rInt, location, rInt, rInt, rInt)
}

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

0 comments on commit c1bf682

Please sign in to comment.