Skip to content

Commit

Permalink
Merge pull request #1891 from terraform-providers/azurestack-vng
Browse files Browse the repository at this point in the history
AzureStack: virtual network gateway PR comments
  • Loading branch information
katbyte authored Sep 7, 2018
2 parents 5ef0f6b + 63ce9ce commit 2766410
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 89 deletions.
18 changes: 16 additions & 2 deletions azurerm/data_source_virtual_network_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-04-01/network"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

Expand All @@ -17,8 +18,9 @@ func dataSourceArmVirtualNetworkGateway() *schema.Resource {

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

"resource_group_name": resourceGroupNameForDataSourceSchema(),
Expand Down Expand Up @@ -59,14 +61,17 @@ func dataSourceArmVirtualNetworkGateway() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"private_ip_address_allocation": {
Type: schema.TypeString,
Computed: true,
},

"subnet_id": {
Type: schema.TypeString,
Computed: true,
},

"public_ip_address_id": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -87,6 +92,7 @@ func dataSourceArmVirtualNetworkGateway() *schema.Resource {
Type: schema.TypeString,
},
},

"root_certificate": {
Type: schema.TypeSet,
Computed: true,
Expand All @@ -96,6 +102,7 @@ func dataSourceArmVirtualNetworkGateway() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"public_cert_data": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -104,6 +111,7 @@ func dataSourceArmVirtualNetworkGateway() *schema.Resource {
},
Set: hashVirtualNetworkGatewayDataSourceRootCert,
},

"revoked_certificate": {
Type: schema.TypeSet,
Computed: true,
Expand All @@ -113,6 +121,7 @@ func dataSourceArmVirtualNetworkGateway() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"thumbprint": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -121,14 +130,17 @@ func dataSourceArmVirtualNetworkGateway() *schema.Resource {
},
Set: hashVirtualNetworkGatewayDataSourceRevokedCert,
},

"radius_server_address": {
Type: schema.TypeString,
Computed: true,
},

"radius_server_secret": {
Type: schema.TypeString,
Computed: true,
},

"vpn_client_protocols": {
Type: schema.TypeSet,
Computed: true,
Expand All @@ -149,10 +161,12 @@ func dataSourceArmVirtualNetworkGateway() *schema.Resource {
Type: schema.TypeInt,
Computed: true,
},

"peering_address": {
Type: schema.TypeString,
Computed: true,
},

"peer_weight": {
Type: schema.TypeInt,
Computed: true,
Expand Down
32 changes: 0 additions & 32 deletions azurerm/import_arm_virtual_network_gateway_test.go

This file was deleted.

75 changes: 39 additions & 36 deletions azurerm/resource_arm_virtual_network_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema"
"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/suppress"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
Expand All @@ -28,40 +30,37 @@ func resourceArmVirtualNetworkGateway() *schema.Resource {

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": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"resource_group_name": resourceGroupNameSchema(),

"location": locationSchema(),

"type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: suppress.CaseDifference,
ValidateFunc: validation.StringInSlice([]string{
string(network.VirtualNetworkGatewayTypeExpressRoute),
string(network.VirtualNetworkGatewayTypeVpn),
}, true),
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},

"vpn_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: string(network.RouteBased),
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: string(network.RouteBased),
DiffSuppressFunc: suppress.CaseDifference,
ValidateFunc: validation.StringInSlice([]string{
string(network.RouteBased),
string(network.PolicyBased),
}, true),
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},

"enable_bgp": {
Expand All @@ -79,7 +78,7 @@ func resourceArmVirtualNetworkGateway() *schema.Resource {
"sku": {
Type: schema.TypeString,
Required: true,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
DiffSuppressFunc: suppress.CaseDifference,
ValidateFunc: validation.StringInSlice([]string{
string(network.VirtualNetworkGatewaySkuTierBasic),
string(network.VirtualNetworkGatewaySkuTierStandard),
Expand All @@ -105,6 +104,7 @@ func resourceArmVirtualNetworkGateway() *schema.Resource {
// Azure portal.
Default: "vnetGatewayConfig",
},

"private_ip_address_allocation": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -114,15 +114,18 @@ func resourceArmVirtualNetworkGateway() *schema.Resource {
}, false),
Default: string(network.Dynamic),
},

"subnet_id": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateArmVirtualNetworkGatewaySubnetId,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
DiffSuppressFunc: suppress.CaseDifference,
},

"public_ip_address_id": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: azure.ValidateResourceIDOrEmpty,
},
},
},
Expand All @@ -141,6 +144,7 @@ func resourceArmVirtualNetworkGateway() *schema.Resource {
Type: schema.TypeString,
},
},

"root_certificate": {
Type: schema.TypeSet,
Optional: true,
Expand All @@ -163,6 +167,7 @@ func resourceArmVirtualNetworkGateway() *schema.Resource {
},
Set: hashVirtualNetworkGatewayRootCert,
},

"revoked_certificate": {
Type: schema.TypeSet,
Optional: true,
Expand All @@ -184,6 +189,7 @@ func resourceArmVirtualNetworkGateway() *schema.Resource {
},
Set: hashVirtualNetworkGatewayRevokedCert,
},

"radius_server_address": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -193,6 +199,7 @@ func resourceArmVirtualNetworkGateway() *schema.Resource {
},
ValidateFunc: validate.IPv4Address,
},

"radius_server_secret": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -201,6 +208,7 @@ func resourceArmVirtualNetworkGateway() *schema.Resource {
"vpn_client_configuration.0.revoked_certificate",
},
},

"vpn_client_protocols": {
Type: schema.TypeSet,
Optional: true,
Expand All @@ -227,12 +235,14 @@ func resourceArmVirtualNetworkGateway() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
},

"peering_address": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},

"peer_weight": {
Type: schema.TypeInt,
Optional: true,
Expand All @@ -242,8 +252,9 @@ func resourceArmVirtualNetworkGateway() *schema.Resource {
},

"default_local_network_gateway_id": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: azure.ValidateResourceIDOrEmpty,
},

"tags": tagsSchema(),
Expand Down Expand Up @@ -279,8 +290,7 @@ func resourceArmVirtualNetworkGatewayCreateUpdate(d *schema.ResourceData, meta i
return fmt.Errorf("Error Creating/Updating AzureRM Virtual Network Gateway %q (Resource Group %q): %+v", name, 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 of AzureRM Virtual Network Gateway %q (Resource Group %q): %+v", name, resGroup, err)
}

Expand Down Expand Up @@ -374,8 +384,7 @@ func resourceArmVirtualNetworkGatewayDelete(d *schema.ResourceData, meta interfa
return fmt.Errorf("Error deleting Virtual Network Gateway %q (Resource Group %q): %+v", name, 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 deletion of Virtual Network Gateway %q (Resource Group %q): %+v", name, resGroup, err)
}

Expand Down Expand Up @@ -413,27 +422,21 @@ func getArmVirtualNetworkGatewayProperties(d *schema.ResourceData) (*network.Vir

// Sku validation for policy-based VPN gateways
if props.GatewayType == network.VirtualNetworkGatewayTypeVpn && props.VpnType == network.PolicyBased {
ok, err := evaluateSchemaValidateFunc(string(props.Sku.Name), "sku", validateArmVirtualNetworkGatewayPolicyBasedVpnSku())

if !ok {
if ok, err := evaluateSchemaValidateFunc(string(props.Sku.Name), "sku", validateArmVirtualNetworkGatewayPolicyBasedVpnSku()); !ok {
return nil, err
}
}

// Sku validation for route-based VPN gateways
if props.GatewayType == network.VirtualNetworkGatewayTypeVpn && props.VpnType == network.RouteBased {
ok, err := evaluateSchemaValidateFunc(string(props.Sku.Name), "sku", validateArmVirtualNetworkGatewayRouteBasedVpnSku())

if !ok {
if ok, err := evaluateSchemaValidateFunc(string(props.Sku.Name), "sku", validateArmVirtualNetworkGatewayRouteBasedVpnSku()); !ok {
return nil, err
}
}

// Sku validation for ExpressRoute gateways
if props.GatewayType == network.VirtualNetworkGatewayTypeExpressRoute {
ok, err := evaluateSchemaValidateFunc(string(props.Sku.Name), "sku", validateArmVirtualNetworkGatewayExpressRouteSku())

if !ok {
if ok, err := evaluateSchemaValidateFunc(string(props.Sku.Name), "sku", validateArmVirtualNetworkGatewayExpressRouteSku()); !ok {
return nil, err
}
}
Expand Down
10 changes: 10 additions & 0 deletions azurerm/resource_arm_virtual_network_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func TestAccAzureRMVirtualNetworkGateway_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "sku", "Basic"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand All @@ -48,6 +53,11 @@ func TestAccAzureRMVirtualNetworkGateway_lowerCaseSubnetName(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "sku", "Basic"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down
Loading

0 comments on commit 2766410

Please sign in to comment.