diff --git a/internal/services/network/client/client.go b/internal/services/network/client/client.go index f9f6c300ef44..16cc3141cdeb 100644 --- a/internal/services/network/client/client.go +++ b/internal/services/network/client/client.go @@ -55,7 +55,6 @@ type Client struct { VnetPeeringsClient *network.VirtualNetworkPeeringsClient VirtualWanClient *network.VirtualWansClient VirtualHubClient *network.VirtualHubsClient - VpnGatewaysClient *network.VpnGatewaysClient } func NewClient(o *common.ClientOptions) (*Client, error) { @@ -173,9 +172,6 @@ func NewClient(o *common.ClientOptions) (*Client, error) { VirtualHubClient := network.NewVirtualHubsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&VirtualHubClient.Client, o.ResourceManagerAuthorizer) - vpnGatewaysClient := network.NewVpnGatewaysClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) - o.ConfigureClient(&vpnGatewaysClient.Client, o.ResourceManagerAuthorizer) - ServiceAssociationLinkClient := network.NewServiceAssociationLinksClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&ServiceAssociationLinkClient.Client, o.ResourceManagerAuthorizer) @@ -228,7 +224,6 @@ func NewClient(o *common.ClientOptions) (*Client, error) { VnetPeeringsClient: &VnetPeeringsClient, VirtualWanClient: &VirtualWanClient, VirtualHubClient: &VirtualHubClient, - VpnGatewaysClient: &vpnGatewaysClient, PrivateDnsZoneGroupClient: &PrivateDnsZoneGroupClient, PrivateLinkServiceClient: &PrivateLinkServiceClient, ServiceAssociationLinkClient: &ServiceAssociationLinkClient, diff --git a/internal/services/network/parse/vpn_gateway.go b/internal/services/network/parse/vpn_gateway.go deleted file mode 100644 index 612ef45675e7..000000000000 --- a/internal/services/network/parse/vpn_gateway.go +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package parse - -// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten - -import ( - "fmt" - "strings" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -type VpnGatewayId struct { - SubscriptionId string - ResourceGroup string - Name string -} - -func NewVpnGatewayID(subscriptionId, resourceGroup, name string) VpnGatewayId { - return VpnGatewayId{ - SubscriptionId: subscriptionId, - ResourceGroup: resourceGroup, - Name: name, - } -} - -func (id VpnGatewayId) String() string { - segments := []string{ - fmt.Sprintf("Name %q", id.Name), - fmt.Sprintf("Resource Group %q", id.ResourceGroup), - } - segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "Vpn Gateway", segmentsStr) -} - -func (id VpnGatewayId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/vpnGateways/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.Name) -} - -// VpnGatewayID parses a VpnGateway ID into an VpnGatewayId struct -func VpnGatewayID(input string) (*VpnGatewayId, error) { - id, err := resourceids.ParseAzureResourceID(input) - if err != nil { - return nil, fmt.Errorf("parsing %q as an VpnGateway ID: %+v", input, err) - } - - resourceId := VpnGatewayId{ - SubscriptionId: id.SubscriptionID, - ResourceGroup: id.ResourceGroup, - } - - if resourceId.SubscriptionId == "" { - return nil, fmt.Errorf("ID was missing the 'subscriptions' element") - } - - if resourceId.ResourceGroup == "" { - return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") - } - - if resourceId.Name, err = id.PopSegment("vpnGateways"); err != nil { - return nil, err - } - - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err - } - - return &resourceId, nil -} diff --git a/internal/services/network/parse/vpn_gateway_test.go b/internal/services/network/parse/vpn_gateway_test.go deleted file mode 100644 index 11c088b979d6..000000000000 --- a/internal/services/network/parse/vpn_gateway_test.go +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package parse - -// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten - -import ( - "testing" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -var _ resourceids.Id = VpnGatewayId{} - -func TestVpnGatewayIDFormatter(t *testing.T) { - actual := NewVpnGatewayID("12345678-1234-9876-4563-123456789012", "resGroup1", "vpnGateway1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/vpnGateways/vpnGateway1" - if actual != expected { - t.Fatalf("Expected %q but got %q", expected, actual) - } -} - -func TestVpnGatewayID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *VpnGatewayId - }{ - - { - // empty - Input: "", - Error: true, - }, - - { - // missing SubscriptionId - Input: "/", - Error: true, - }, - - { - // missing value for SubscriptionId - Input: "/subscriptions/", - Error: true, - }, - - { - // missing ResourceGroup - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", - Error: true, - }, - - { - // missing value for ResourceGroup - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", - Error: true, - }, - - { - // missing Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", - Error: true, - }, - - { - // missing value for Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/vpnGateways/", - Error: true, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/vpnGateways/vpnGateway1", - Expected: &VpnGatewayId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroup: "resGroup1", - Name: "vpnGateway1", - }, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/VPNGATEWAYS/VPNGATEWAY1", - Error: true, - }, - } - - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := VpnGatewayID(v.Input) - if err != nil { - if v.Error { - continue - } - - t.Fatalf("Expect a value but got an error: %s", err) - } - if v.Error { - t.Fatal("Expect an error but didn't get one") - } - - if actual.SubscriptionId != v.Expected.SubscriptionId { - t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) - } - if actual.ResourceGroup != v.Expected.ResourceGroup { - t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) - } - if actual.Name != v.Expected.Name { - t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) - } - } -} diff --git a/internal/services/network/resourceids.go b/internal/services/network/resourceids.go index 655ca5b838c2..fb3b510e8887 100644 --- a/internal/services/network/resourceids.go +++ b/internal/services/network/resourceids.go @@ -54,7 +54,6 @@ package network //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=VirtualHub -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/virtualHubs/virtualHub1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=VirtualHubIpConfiguration -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/virtualHubs/virtualHub1/ipConfigurations/ipConfiguration1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=VirtualWan -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/virtualWans/virtualWan1 -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=VpnGateway -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/vpnGateways/vpnGateway1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=PointToSiteVpnGateway -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/p2sVpnGateways/pointToSite1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=VpnConnection -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/vpnGateways/vpnGateway1/vpnConnections/vpnConnection1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=VpnGatewayNatRule -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/vpnGateways/vpnGateway1/natRules/natRule1 diff --git a/internal/services/network/validate/vpn_gateway_id.go b/internal/services/network/validate/vpn_gateway_id.go deleted file mode 100644 index 1f61200e9cb7..000000000000 --- a/internal/services/network/validate/vpn_gateway_id.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package validate - -// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten - -import ( - "fmt" - - "github.com/hashicorp/terraform-provider-azurerm/internal/services/network/parse" -) - -func VpnGatewayID(input interface{}, key string) (warnings []string, errors []error) { - v, ok := input.(string) - if !ok { - errors = append(errors, fmt.Errorf("expected %q to be a string", key)) - return - } - - if _, err := parse.VpnGatewayID(v); err != nil { - errors = append(errors, err) - } - - return -} diff --git a/internal/services/network/validate/vpn_gateway_id_test.go b/internal/services/network/validate/vpn_gateway_id_test.go deleted file mode 100644 index 1aad6a16af13..000000000000 --- a/internal/services/network/validate/vpn_gateway_id_test.go +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package validate - -// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten - -import "testing" - -func TestVpnGatewayID(t *testing.T) { - cases := []struct { - Input string - Valid bool - }{ - - { - // empty - Input: "", - Valid: false, - }, - - { - // missing SubscriptionId - Input: "/", - Valid: false, - }, - - { - // missing value for SubscriptionId - Input: "/subscriptions/", - Valid: false, - }, - - { - // missing ResourceGroup - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", - Valid: false, - }, - - { - // missing value for ResourceGroup - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", - Valid: false, - }, - - { - // missing Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", - Valid: false, - }, - - { - // missing value for Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/vpnGateways/", - Valid: false, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/vpnGateways/vpnGateway1", - Valid: true, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/VPNGATEWAYS/VPNGATEWAY1", - Valid: false, - }, - } - for _, tc := range cases { - t.Logf("[DEBUG] Testing Value %s", tc.Input) - _, errors := VpnGatewayID(tc.Input, "test") - valid := len(errors) == 0 - - if tc.Valid != valid { - t.Fatalf("Expected %t but got %t", tc.Valid, valid) - } - } -} diff --git a/internal/services/network/vpn_gateway_connection_resource.go b/internal/services/network/vpn_gateway_connection_resource.go index 413c44a9386e..d107375b097d 100644 --- a/internal/services/network/vpn_gateway_connection_resource.go +++ b/internal/services/network/vpn_gateway_connection_resource.go @@ -15,7 +15,6 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/locks" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/network/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/network/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" @@ -54,7 +53,7 @@ func resourceVPNGatewayConnection() *pluginsdk.Resource { Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateFunc: validate.VpnGatewayID, + ValidateFunc: virtualwans.ValidateVpnGatewayID, }, "remote_vpn_site_id": { @@ -336,12 +335,12 @@ func resourceVpnGatewayConnectionResourceCreateUpdate(d *pluginsdk.ResourceData, defer cancel() name := d.Get("name").(string) - gatewayId, err := parse.VpnGatewayID(d.Get("vpn_gateway_id").(string)) + gatewayId, err := virtualwans.ParseVpnGatewayID(d.Get("vpn_gateway_id").(string)) if err != nil { return err } - id := commonids.NewVPNConnectionID(gatewayId.SubscriptionId, gatewayId.ResourceGroup, gatewayId.Name, name) + id := commonids.NewVPNConnectionID(gatewayId.SubscriptionId, gatewayId.ResourceGroupName, gatewayId.VpnGatewayName, name) if d.IsNewResource() { resp, err := client.VpnConnectionsGet(ctx, id) if err != nil { @@ -355,8 +354,8 @@ func resourceVpnGatewayConnectionResourceCreateUpdate(d *pluginsdk.ResourceData, } } - locks.ByName(gatewayId.Name, VPNGatewayResourceName) - defer locks.UnlockByName(gatewayId.Name, VPNGatewayResourceName) + locks.ByName(gatewayId.VpnGatewayName, VPNGatewayResourceName) + defer locks.UnlockByName(gatewayId.VpnGatewayName, VPNGatewayResourceName) payload := virtualwans.VpnConnection{ Properties: &virtualwans.VpnConnectionProperties{ @@ -403,7 +402,7 @@ func resourceVpnGatewayConnectionResourceRead(d *pluginsdk.ResourceData, meta in } d.Set("name", id.ConnectionName) - d.Set("vpn_gateway_id", parse.NewVpnGatewayID(id.SubscriptionId, id.ResourceGroupName, id.GatewayName).ID()) + d.Set("vpn_gateway_id", virtualwans.NewVpnGatewayID(id.SubscriptionId, id.ResourceGroupName, id.GatewayName).ID()) if model := resp.Model; model != nil { if props := model.Properties; props != nil { diff --git a/internal/services/network/vpn_gateway_data_source.go b/internal/services/network/vpn_gateway_data_source.go index 67846b048b8f..a68e684e5f38 100644 --- a/internal/services/network/vpn_gateway_data_source.go +++ b/internal/services/network/vpn_gateway_data_source.go @@ -7,15 +7,15 @@ import ( "fmt" "time" + "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" - "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/location" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-sdk/resource-manager/network/2023-04-01/virtualwans" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/network/parse" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" "github.com/hashicorp/terraform-provider-azurerm/utils" - "github.com/tombuildsstuff/kermit/sdk/network/2022-07-01/network" ) func dataSourceVPNGateway() *pluginsdk.Resource { @@ -143,58 +143,62 @@ func dataSourceVPNGateway() *pluginsdk.Resource { Computed: true, }, - "tags": tags.SchemaDataSource(), + "tags": commonschema.TagsDataSource(), }, } } func dataSourceVPNGatewayRead(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Network.VpnGatewaysClient + client := meta.(*clients.Client).Network.VirtualWANs ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) subscriptionId := meta.(*clients.Client).Account.SubscriptionId defer cancel() - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) - id := parse.NewVpnGatewayID(subscriptionId, resourceGroup, name) - resp, err := client.Get(ctx, id.ResourceGroup, id.Name) + id := virtualwans.NewVpnGatewayID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) + resp, err := client.VpnGatewaysGet(ctx, id) if err != nil { - if utils.ResponseWasNotFound(resp.Response) { + if response.WasNotFound(resp.HttpResponse) { return fmt.Errorf("%s was not found", id) } - return fmt.Errorf("Error retrieving VPN Gateway %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("retrieving %s: %+v", id, err) } d.SetId(id.ID()) - d.Set("name", id.Name) - d.Set("resource_group_name", id.ResourceGroup) - if location := resp.Location; location != nil { - d.Set("location", azure.NormalizeLocation(*location)) - } - if props := resp.VpnGatewayProperties; props != nil { - if err := d.Set("bgp_settings", dataSourceFlattenVPNGatewayBGPSettings(props.BgpSettings)); err != nil { - return fmt.Errorf("Error setting `bgp_settings`: %+v", err) - } + d.Set("name", id.VpnGatewayName) + d.Set("resource_group_name", id.ResourceGroupName) - scaleUnit := 0 - if props.VpnGatewayScaleUnit != nil { - scaleUnit = int(*props.VpnGatewayScaleUnit) - } - d.Set("scale_unit", scaleUnit) + if model := resp.Model; model != nil { + d.Set("location", location.Normalize(model.Location)) + + if props := model.Properties; props != nil { + if err := d.Set("bgp_settings", dataSourceFlattenVPNGatewayBGPSettings(props.BgpSettings)); err != nil { + return fmt.Errorf("Error setting `bgp_settings`: %+v", err) + } + + scaleUnit := 0 + if props.VpnGatewayScaleUnit != nil { + scaleUnit = int(*props.VpnGatewayScaleUnit) + } + d.Set("scale_unit", scaleUnit) + + virtualHubId := "" + if props.VirtualHub != nil && props.VirtualHub.Id != nil { + virtualHubId = *props.VirtualHub.Id + } + d.Set("virtual_hub_id", virtualHubId) - virtualHubId := "" - if props.VirtualHub != nil && props.VirtualHub.ID != nil { - virtualHubId = *props.VirtualHub.ID + if err := tags.FlattenAndSet(d, model.Tags); err != nil { + return err + } } - d.Set("virtual_hub_id", virtualHubId) } - return tags.FlattenAndSet(d, resp.Tags) + return nil } -func dataSourceFlattenVPNGatewayBGPSettings(input *network.BgpSettings) []interface{} { +func dataSourceFlattenVPNGatewayBGPSettings(input *virtualwans.BgpSettings) []interface{} { if input == nil { return []interface{}{} } @@ -233,10 +237,10 @@ func dataSourceFlattenVPNGatewayBGPSettings(input *network.BgpSettings) []interf } } -func dataSourceFlattenVPNGatewayIPConfigurationBgpPeeringAddress(input network.IPConfigurationBgpPeeringAddress) []interface{} { +func dataSourceFlattenVPNGatewayIPConfigurationBgpPeeringAddress(input virtualwans.IPConfigurationBgpPeeringAddress) []interface{} { ipConfigurationID := "" - if input.IpconfigurationID != nil { - ipConfigurationID = *input.IpconfigurationID + if input.IPconfigurationId != nil { + ipConfigurationID = *input.IPconfigurationId } return []interface{}{ diff --git a/internal/services/network/vpn_gateway_nat_rule_resource.go b/internal/services/network/vpn_gateway_nat_rule_resource.go index b110d0ef4ee4..6098061f8c0e 100644 --- a/internal/services/network/vpn_gateway_nat_rule_resource.go +++ b/internal/services/network/vpn_gateway_nat_rule_resource.go @@ -8,12 +8,13 @@ import ( "log" "time" + "github.com/hashicorp/go-azure-sdk/resource-manager/network/2023-04-01/virtualwans" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/services/network/parse" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/network/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" @@ -48,13 +49,14 @@ func resourceVPNGatewayNatRule() *pluginsdk.Resource { ValidateFunc: validation.StringIsNotEmpty, }, + // TODO: we should be able to remove this in 4.0 since it can be inferred from `vpn_gateway_id`? "resource_group_name": commonschema.ResourceGroupName(), "vpn_gateway_id": { Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateFunc: validate.VpnGatewayID, + ValidateFunc: virtualwans.ValidateVpnGatewayID, }, "external_mapping": { @@ -201,12 +203,12 @@ func resourceVPNGatewayNatRuleCreate(d *pluginsdk.ResourceData, meta interface{} ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - vpnGatewayId, err := parse.VpnGatewayID(d.Get("vpn_gateway_id").(string)) + vpnGatewayId, err := virtualwans.ParseVpnGatewayID(d.Get("vpn_gateway_id").(string)) if err != nil { return err } - id := parse.NewVpnGatewayNatRuleID(subscriptionId, d.Get("resource_group_name").(string), vpnGatewayId.Name, d.Get("name").(string)) + id := parse.NewVpnGatewayNatRuleID(subscriptionId, d.Get("resource_group_name").(string), vpnGatewayId.VpnGatewayName, d.Get("name").(string)) existing, err := client.Get(ctx, id.ResourceGroup, id.VpnGatewayName, id.NatRuleName) if err != nil { @@ -284,7 +286,7 @@ func resourceVPNGatewayNatRuleRead(d *pluginsdk.ResourceData, meta interface{}) d.Set("name", id.NatRuleName) d.Set("resource_group_name", id.ResourceGroup) - gatewayId := parse.NewVpnGatewayID(id.SubscriptionId, id.ResourceGroup, id.VpnGatewayName) + gatewayId := virtualwans.NewVpnGatewayID(id.SubscriptionId, id.ResourceGroup, id.VpnGatewayName) d.Set("vpn_gateway_id", gatewayId.ID()) if props := resp.VpnGatewayNatRuleProperties; props != nil { @@ -320,12 +322,12 @@ func resourceVPNGatewayNatRuleUpdate(d *pluginsdk.ResourceData, meta interface{} ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - vpnGatewayId, err := parse.VpnGatewayID(d.Get("vpn_gateway_id").(string)) + vpnGatewayId, err := virtualwans.ParseVpnGatewayID(d.Get("vpn_gateway_id").(string)) if err != nil { return err } - id := parse.NewVpnGatewayNatRuleID(subscriptionId, d.Get("resource_group_name").(string), vpnGatewayId.Name, d.Get("name").(string)) + id := parse.NewVpnGatewayNatRuleID(subscriptionId, d.Get("resource_group_name").(string), vpnGatewayId.VpnGatewayName, d.Get("name").(string)) existing, err := client.Get(ctx, id.ResourceGroup, id.VpnGatewayName, id.NatRuleName) if err != nil { diff --git a/internal/services/network/vpn_gateway_resource.go b/internal/services/network/vpn_gateway_resource.go index bcd68d1d7b0d..f14c7495b6c6 100644 --- a/internal/services/network/vpn_gateway_resource.go +++ b/internal/services/network/vpn_gateway_resource.go @@ -4,26 +4,25 @@ package network import ( - "context" "fmt" "log" "time" + "github.com/hashicorp/go-azure-helpers/lang/pointer" "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" - "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/location" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-sdk/resource-manager/network/2023-04-01/virtualwans" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" commonValidate "github.com/hashicorp/terraform-provider-azurerm/helpers/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/locks" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/network/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/network/validate" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" "github.com/hashicorp/terraform-provider-azurerm/utils" - "github.com/tombuildsstuff/kermit/sdk/network/2022-07-01/network" ) var VPNGatewayResourceName = "azurerm_vpn_gateway" @@ -35,7 +34,7 @@ func resourceVPNGateway() *pluginsdk.Resource { Update: resourceVPNGatewayUpdate, Delete: resourceVPNGatewayDelete, Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { - _, err := parse.VpnGatewayID(id) + _, err := virtualwans.ParseVpnGatewayID(id) return err }), @@ -196,130 +195,120 @@ func resourceVPNGateway() *pluginsdk.Resource { ValidateFunc: validation.IntAtLeast(0), }, - "tags": tags.Schema(), + "tags": commonschema.Tags(), }, } } func resourceVPNGatewayCreate(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Network.VpnGatewaysClient + client := meta.(*clients.Client).Network.VirtualWANs subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - id := parse.NewVpnGatewayID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) - - existing, err := client.Get(ctx, id.ResourceGroup, id.Name) + id := virtualwans.NewVpnGatewayID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) + existing, err := client.VpnGatewaysGet(ctx, id) if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { + if !response.WasNotFound(existing.HttpResponse) { return fmt.Errorf("checking for presence of existing %s: %+v", id, err) } } - if !utils.ResponseWasNotFound(existing.Response) { + if !response.WasNotFound(existing.HttpResponse) { return tf.ImportAsExistsError("azurerm_vpn_gateway", id.ID()) } bgpSettingsRaw := d.Get("bgp_settings").([]interface{}) bgpSettings := expandVPNGatewayBGPSettings(bgpSettingsRaw) - - location := azure.NormalizeLocation(d.Get("location").(string)) - scaleUnit := d.Get("scale_unit").(int) - virtualHubId := d.Get("virtual_hub_id").(string) - t := d.Get("tags").(map[string]interface{}) - - parameters := network.VpnGateway{ - Location: utils.String(location), - VpnGatewayProperties: &network.VpnGatewayProperties{ - EnableBgpRouteTranslationForNat: utils.Bool(d.Get("bgp_route_translation_for_nat_enabled").(bool)), + payload := virtualwans.VpnGateway{ + Location: location.Normalize(d.Get("location").(string)), + Properties: &virtualwans.VpnGatewayProperties{ + EnableBgpRouteTranslationForNat: pointer.To(d.Get("bgp_route_translation_for_nat_enabled").(bool)), BgpSettings: bgpSettings, - VirtualHub: &network.SubResource{ - ID: utils.String(virtualHubId), + VirtualHub: &virtualwans.SubResource{ + Id: utils.String(d.Get("virtual_hub_id").(string)), }, - VpnGatewayScaleUnit: utils.Int32(int32(scaleUnit)), - IsRoutingPreferenceInternet: utils.Bool(d.Get("routing_preference").(string) == "Internet"), + VpnGatewayScaleUnit: pointer.To(int64(d.Get("scale_unit").(int))), + IsRoutingPreferenceInternet: pointer.To(d.Get("routing_preference").(string) == "Internet"), }, - Tags: tags.Expand(t), + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } - future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, parameters) - if err != nil { + if err := client.VpnGatewaysCreateOrUpdateThenPoll(ctx, id, payload); err != nil { return fmt.Errorf("creating %s: %+v", id, err) } - - if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for creation/update of %q: %+v", id, err) - } - if err := waitForCompletion(d, ctx, client, id.ResourceGroup, id.Name); err != nil { - return err - } - resp, err := client.Get(ctx, id.ResourceGroup, id.Name) - if err != nil { - return fmt.Errorf("retrieving %s: %+v", id, err) - } + d.SetId(id.ID()) // `vpnGatewayParameters.Properties.bgpSettings.bgpPeeringAddress` customer cannot provide this field during create. This will be set with default value once gateway is created. // it could only be updated - if len(bgpSettingsRaw) > 0 && resp.VpnGatewayProperties != nil && resp.VpnGatewayProperties.BgpSettings != nil && resp.VpnGatewayProperties.BgpSettings.BgpPeeringAddresses != nil { - val := bgpSettingsRaw[0].(map[string]interface{}) - input0 := val["instance_0_bgp_peering_address"].([]interface{}) - input1 := val["instance_1_bgp_peering_address"].([]interface{}) + if len(bgpSettingsRaw) > 0 { + resp, err := client.VpnGatewaysGet(ctx, id) + if err != nil { + return fmt.Errorf("retrieving %s: %+v", id, err) + } + if resp.Model == nil || resp.Model.Properties == nil { + return fmt.Errorf("retrieving %s: `model.Properties` was nil", id) + } + props := resp.Model.Properties - if len(input0) > 0 || len(input1) > 0 { - if len(input0) > 0 { - val := input0[0].(map[string]interface{}) - (*resp.VpnGatewayProperties.BgpSettings.BgpPeeringAddresses)[0].CustomBgpIPAddresses = utils.ExpandStringSlice(val["custom_ips"].(*pluginsdk.Set).List()) - } - if len(input1) > 0 { - val := input1[0].(map[string]interface{}) - (*resp.VpnGatewayProperties.BgpSettings.BgpPeeringAddresses)[1].CustomBgpIPAddresses = utils.ExpandStringSlice(val["custom_ips"].(*pluginsdk.Set).List()) - } + if props.BgpSettings != nil && props.BgpSettings.BgpPeeringAddresses != nil { - future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, resp) - if err != nil { - return fmt.Errorf("creating %s: %+v", id, err) - } + val := bgpSettingsRaw[0].(map[string]interface{}) + input0 := val["instance_0_bgp_peering_address"].([]interface{}) + input1 := val["instance_1_bgp_peering_address"].([]interface{}) - if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for creation/update of %q: %+v", id, err) - } - if err := waitForCompletion(d, ctx, client, id.ResourceGroup, id.Name); err != nil { - return err + if len(input0) > 0 || len(input1) > 0 { + if len(input0) > 0 && input0[0] != nil { + val := input0[0].(map[string]interface{}) + (*props.BgpSettings.BgpPeeringAddresses)[0].CustomBgpIPAddresses = utils.ExpandStringSlice(val["custom_ips"].(*pluginsdk.Set).List()) + } + if len(input1) > 0 && input1[0] != nil { + val := input1[0].(map[string]interface{}) + (*props.BgpSettings.BgpPeeringAddresses)[1].CustomBgpIPAddresses = utils.ExpandStringSlice(val["custom_ips"].(*pluginsdk.Set).List()) + } + + resp.Model.Properties = props + + if err := client.VpnGatewaysCreateOrUpdateThenPoll(ctx, id, *resp.Model); err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } } } } - d.SetId(id.ID()) - return resourceVPNGatewayRead(d, meta) } func resourceVPNGatewayUpdate(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Network.VpnGatewaysClient + client := meta.(*clients.Client).Network.VirtualWANs ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.VpnGatewayID(d.Id()) + id, err := virtualwans.ParseVpnGatewayID(d.Id()) if err != nil { return err } - locks.ByName(id.Name, VPNGatewayResourceName) - defer locks.UnlockByName(id.Name, VPNGatewayResourceName) + locks.ByName(id.VpnGatewayName, VPNGatewayResourceName) + defer locks.UnlockByName(id.VpnGatewayName, VPNGatewayResourceName) - existing, err := client.Get(ctx, id.ResourceGroup, id.Name) + existing, err := client.VpnGatewaysGet(ctx, *id) if err != nil { - return fmt.Errorf("retrieving for presence of existing %s: %+v", id, err) + return fmt.Errorf("retrieving %s: %+v", *id, err) + } + if existing.Model == nil || existing.Model.Properties == nil { + return fmt.Errorf("retrieving %s: `model.Properties` was nil", *id) } + model := *existing.Model if d.HasChange("scale_unit") { - existing.VpnGatewayScaleUnit = utils.Int32(int32(d.Get("scale_unit").(int))) + model.Properties.VpnGatewayScaleUnit = pointer.To(int64(d.Get("scale_unit").(int))) } if d.HasChange("tags") { - existing.Tags = tags.Expand(d.Get("tags").(map[string]interface{})) + model.Tags = tags.Expand(d.Get("tags").(map[string]interface{})) } if d.HasChange("bgp_route_translation_for_nat_enabled") { - existing.EnableBgpRouteTranslationForNat = utils.Bool(d.Get("bgp_route_translation_for_nat_enabled").(bool)) + model.Properties.EnableBgpRouteTranslationForNat = utils.Bool(d.Get("bgp_route_translation_for_nat_enabled").(bool)) } bgpSettingsRaw := d.Get("bgp_settings").([]interface{}) @@ -329,45 +318,37 @@ func resourceVPNGatewayUpdate(d *pluginsdk.ResourceData, meta interface{}) error if d.HasChange("bgp_settings.0.instance_0_bgp_peering_address") { if input := val["instance_0_bgp_peering_address"].([]interface{}); len(input) > 0 { val := input[0].(map[string]interface{}) - (*existing.VpnGatewayProperties.BgpSettings.BgpPeeringAddresses)[0].CustomBgpIPAddresses = utils.ExpandStringSlice(val["custom_ips"].(*pluginsdk.Set).List()) + (*model.Properties.BgpSettings.BgpPeeringAddresses)[0].CustomBgpIPAddresses = utils.ExpandStringSlice(val["custom_ips"].(*pluginsdk.Set).List()) } } if d.HasChange("bgp_settings.0.instance_1_bgp_peering_address") { if input := val["instance_1_bgp_peering_address"].([]interface{}); len(input) > 0 { val := input[0].(map[string]interface{}) - (*existing.VpnGatewayProperties.BgpSettings.BgpPeeringAddresses)[1].CustomBgpIPAddresses = utils.ExpandStringSlice(val["custom_ips"].(*pluginsdk.Set).List()) + (*model.Properties.BgpSettings.BgpPeeringAddresses)[1].CustomBgpIPAddresses = utils.ExpandStringSlice(val["custom_ips"].(*pluginsdk.Set).List()) } } } - future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, existing) - if err != nil { - return fmt.Errorf("creating %s: %+v", id, err) - } - - if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for creation/update of %q: %+v", id, err) - } - if err := waitForCompletion(d, ctx, client, id.ResourceGroup, id.Name); err != nil { - return err + if err := client.VpnGatewaysCreateOrUpdateThenPoll(ctx, *id, model); err != nil { + return fmt.Errorf("updating %s: %+v", id, err) } return resourceVPNGatewayRead(d, meta) } func resourceVPNGatewayRead(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Network.VpnGatewaysClient + client := meta.(*clients.Client).Network.VirtualWANs ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.VpnGatewayID(d.Id()) + id, err := virtualwans.ParseVpnGatewayID(d.Id()) if err != nil { return err } - resp, err := client.Get(ctx, id.ResourceGroup, id.Name) + resp, err := client.VpnGatewaysGet(ctx, *id) if err != nil { - if utils.ResponseWasNotFound(resp.Response) { + if response.WasNotFound(resp.HttpResponse) { log.Printf("[DEBUG] %s was not found - removing from state", *id) d.SetId("") return nil @@ -376,113 +357,80 @@ func resourceVPNGatewayRead(d *pluginsdk.ResourceData, meta interface{}) error { return fmt.Errorf("retrieving %s: %+v", *id, err) } - d.Set("name", id.Name) - d.Set("resource_group_name", id.ResourceGroup) - if location := resp.Location; location != nil { - d.Set("location", azure.NormalizeLocation(*location)) - } + d.Set("name", id.VpnGatewayName) + d.Set("resource_group_name", id.ResourceGroupName) - if props := resp.VpnGatewayProperties; props != nil { - if err := d.Set("bgp_settings", flattenVPNGatewayBGPSettings(props.BgpSettings)); err != nil { - return fmt.Errorf("setting `bgp_settings`: %+v", err) - } + if model := resp.Model; model != nil { + d.Set("location", location.Normalize(model.Location)) - bgpRouteTranslationForNatEnabled := false - if props.EnableBgpRouteTranslationForNat != nil { - bgpRouteTranslationForNatEnabled = *props.EnableBgpRouteTranslationForNat - } - d.Set("bgp_route_translation_for_nat_enabled", bgpRouteTranslationForNatEnabled) + if props := model.Properties; props != nil { + if err := d.Set("bgp_settings", flattenVPNGatewayBGPSettings(props.BgpSettings)); err != nil { + return fmt.Errorf("setting `bgp_settings`: %+v", err) + } - scaleUnit := 0 - if props.VpnGatewayScaleUnit != nil { - scaleUnit = int(*props.VpnGatewayScaleUnit) - } - d.Set("scale_unit", scaleUnit) + bgpRouteTranslationForNatEnabled := false + if props.EnableBgpRouteTranslationForNat != nil { + bgpRouteTranslationForNatEnabled = *props.EnableBgpRouteTranslationForNat + } + d.Set("bgp_route_translation_for_nat_enabled", bgpRouteTranslationForNatEnabled) - virtualHubId := "" - if props.VirtualHub != nil && props.VirtualHub.ID != nil { - virtualHubId = *props.VirtualHub.ID + scaleUnit := 0 + if props.VpnGatewayScaleUnit != nil { + scaleUnit = int(*props.VpnGatewayScaleUnit) + } + d.Set("scale_unit", scaleUnit) + + virtualHubId := "" + if props.VirtualHub != nil && props.VirtualHub.Id != nil { + virtualHubId = *props.VirtualHub.Id + } + d.Set("virtual_hub_id", virtualHubId) + + isRoutingPreferenceInternet := "Microsoft Network" + if props.IsRoutingPreferenceInternet != nil && *props.IsRoutingPreferenceInternet { + isRoutingPreferenceInternet = "Internet" + } + d.Set("routing_preference", isRoutingPreferenceInternet) } - d.Set("virtual_hub_id", virtualHubId) - isRoutingPreferenceInternet := "Microsoft Network" - if props.IsRoutingPreferenceInternet != nil && *props.IsRoutingPreferenceInternet { - isRoutingPreferenceInternet = "Internet" + if err := tags.FlattenAndSet(d, model.Tags); err != nil { + return err } - d.Set("routing_preference", isRoutingPreferenceInternet) } - return tags.FlattenAndSet(d, resp.Tags) + return nil } func resourceVPNGatewayDelete(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Network.VpnGatewaysClient + client := meta.(*clients.Client).Network.VirtualWANs ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.VpnGatewayID(d.Id()) + id, err := virtualwans.ParseVpnGatewayID(d.Id()) if err != nil { return err } - deleteFuture, err := client.Delete(ctx, id.ResourceGroup, id.Name) - if err != nil { - if response.WasNotFound(deleteFuture.Response()) { - return nil - } - + if err := client.VpnGatewaysDeleteThenPoll(ctx, *id); err != nil { return fmt.Errorf("deleting %s: %+v", *id, err) } - err = deleteFuture.WaitForCompletionRef(ctx, client.Client) - if err != nil { - if response.WasNotFound(deleteFuture.Response()) { - return nil - } - - return fmt.Errorf("waiting for deletion of %s: %+v", *id, err) - } - - return nil -} - -func waitForCompletion(d *pluginsdk.ResourceData, ctx context.Context, client *network.VpnGatewaysClient, resourceGroup, name string) error { - log.Printf("[DEBUG] Waiting for Virtual Hub %q (Resource Group %q) to become available", name, resourceGroup) - stateConf := &pluginsdk.StateChangeConf{ - Pending: []string{"pending"}, - Target: []string{"available"}, - Refresh: vpnGatewayWaitForCreatedRefreshFunc(ctx, client, resourceGroup, name), - Delay: 30 * time.Second, - PollInterval: 10 * time.Second, - ContinuousTargetOccurence: 3, - } - - if d.IsNewResource() { - stateConf.Timeout = d.Timeout(pluginsdk.TimeoutCreate) - } else { - stateConf.Timeout = d.Timeout(pluginsdk.TimeoutUpdate) - } - - if _, err := stateConf.WaitForStateContext(ctx); err != nil { - return fmt.Errorf("waiting for creation of Virtual Hub %q (Resource Group %q): %+v", name, resourceGroup, err) - } - return nil } -func expandVPNGatewayBGPSettings(input []interface{}) *network.BgpSettings { +func expandVPNGatewayBGPSettings(input []interface{}) *virtualwans.BgpSettings { if len(input) == 0 { return nil } val := input[0].(map[string]interface{}) - return &network.BgpSettings{ - Asn: utils.Int64(int64(val["asn"].(int))), - PeerWeight: utils.Int32(int32(val["peer_weight"].(int))), + return &virtualwans.BgpSettings{ + Asn: pointer.To(int64(val["asn"].(int))), + PeerWeight: pointer.To(int64(val["peer_weight"].(int))), } } -func flattenVPNGatewayBGPSettings(input *network.BgpSettings) []interface{} { +func flattenVPNGatewayBGPSettings(input *virtualwans.BgpSettings) []interface{} { if input == nil { return []interface{}{} } @@ -521,10 +469,10 @@ func flattenVPNGatewayBGPSettings(input *network.BgpSettings) []interface{} { } } -func flattenVPNGatewayIPConfigurationBgpPeeringAddress(input network.IPConfigurationBgpPeeringAddress) []interface{} { +func flattenVPNGatewayIPConfigurationBgpPeeringAddress(input virtualwans.IPConfigurationBgpPeeringAddress) []interface{} { ipConfigurationID := "" - if input.IpconfigurationID != nil { - ipConfigurationID = *input.IpconfigurationID + if input.IPconfigurationId != nil { + ipConfigurationID = *input.IPconfigurationId } return []interface{}{ @@ -536,32 +484,3 @@ func flattenVPNGatewayIPConfigurationBgpPeeringAddress(input network.IPConfigura }, } } - -func vpnGatewayWaitForCreatedRefreshFunc(ctx context.Context, client *network.VpnGatewaysClient, resourceGroup, name string) pluginsdk.StateRefreshFunc { - return func() (interface{}, string, error) { - log.Printf("[DEBUG] Checking to see if VPN Gateway %q (Resource Group %q) has finished provisioning..", name, resourceGroup) - - resp, err := client.Get(ctx, resourceGroup, name) - if err != nil { - log.Printf("[DEBUG] Error retrieving VPN Gateway %q (Resource Group %q): %+v", name, resourceGroup, err) - return nil, "error", fmt.Errorf("retrieving VPN Gateway %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - if resp.VpnGatewayProperties == nil { - log.Printf("[DEBUG] Error retrieving VPN Gateway %q (Resource Group %q): `properties` was nil", name, resourceGroup) - return nil, "error", fmt.Errorf("retrieving VPN Gateway %q (Resource Group %q): `properties` was nil", name, resourceGroup) - } - - log.Printf("[DEBUG] VPN Gateway %q (Resource Group %q) is %q..", name, resourceGroup, string(resp.VpnGatewayProperties.ProvisioningState)) - switch resp.VpnGatewayProperties.ProvisioningState { - case network.ProvisioningStateSucceeded: - return "available", "available", nil - - case network.ProvisioningStateFailed: - return "error", "error", fmt.Errorf("VPN Gateway %q (Resource Group %q) is in provisioningState `Failed`", name, resourceGroup) - - default: - return "pending", "pending", nil - } - } -} diff --git a/internal/services/network/vpn_gateway_resource_test.go b/internal/services/network/vpn_gateway_resource_test.go index 52d6a6ae9ad8..a688d61355eb 100644 --- a/internal/services/network/vpn_gateway_resource_test.go +++ b/internal/services/network/vpn_gateway_resource_test.go @@ -8,10 +8,10 @@ import ( "fmt" "testing" + "github.com/hashicorp/go-azure-sdk/resource-manager/network/2023-04-01/virtualwans" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/network/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/utils" ) @@ -170,17 +170,17 @@ func TestAccVPNGateway_bgpRouteTranslationForNatEnabled(t *testing.T) { } func (t VPNGatewayResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := parse.VpnGatewayID(state.ID) + id, err := virtualwans.ParseVpnGatewayID(state.ID) if err != nil { return nil, err } - resp, err := clients.Network.VpnGatewaysClient.Get(ctx, id.ResourceGroup, id.Name) + resp, err := clients.Network.VirtualWANs.VpnGatewaysGet(ctx, *id) if err != nil { - return nil, fmt.Errorf("reading VPN Gateway (%s): %+v", id, err) + return nil, fmt.Errorf("retrieving %s: %+v", id, err) } - return utils.Bool(resp.ID != nil), nil + return utils.Bool(resp.Model != nil), nil } func (r VPNGatewayResource) basic(data acceptance.TestData) string {