Skip to content

Commit

Permalink
dependencies: network private endpoint and `application security gr…
Browse files Browse the repository at this point in the history
…oup`: migrate to `hashicorp/go-azure-sdk` (#22396)

* Start of swapping azurerm_application_security_group

* finish swapping azurerm_private_endpoint

* Remove parse/validate files for swapped resources

* lint + cleanup

* lint

* fix TestAccPrivateEndpointApplicationSecurityGroupAssociationResource_deleted
  • Loading branch information
mbfrahry authored Jul 7, 2023
1 parent 9585976 commit 4033118
Show file tree
Hide file tree
Showing 142 changed files with 4,553 additions and 982 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/go-azure-sdk/resource-manager/network/2022-09-01/applicationsecuritygroups"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
azValidate "github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/validate"
Expand Down Expand Up @@ -344,7 +345,7 @@ func orchestratedVirtualMachineScaleSetIPConfigurationSchema() *pluginsdk.Schema
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
ValidateFunc: networkValidate.ApplicationSecurityGroupID,
ValidateFunc: applicationsecuritygroups.ValidateApplicationSecurityGroupID,
},
Set: pluginsdk.HashString,
MaxItems: 20,
Expand Down
3 changes: 2 additions & 1 deletion internal/services/compute/virtual_machine_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/go-azure-helpers/resourcemanager/identity"
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryapplicationversions"
"github.com/hashicorp/go-azure-sdk/resource-manager/network/2022-09-01/applicationsecuritygroups"
azValidate "github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/validate"
Expand Down Expand Up @@ -638,7 +639,7 @@ func virtualMachineScaleSetIPConfigurationSchema() *pluginsdk.Schema {
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
ValidateFunc: networkValidate.ApplicationSecurityGroupID,
ValidateFunc: applicationsecuritygroups.ValidateApplicationSecurityGroupID,
},
Set: pluginsdk.HashString,
MaxItems: 20,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/workspaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/network/2022-09-01/privateendpoints"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
networkValidate "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/timeouts"
)
Expand All @@ -33,7 +33,7 @@ func dataSourceDatabricksWorkspacePrivateEndpointConnection() *pluginsdk.Resourc
"private_endpoint_id": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: networkValidate.PrivateEndpointID,
ValidateFunc: privateendpoints.ValidatePrivateEndpointID,
},

"connections": {
Expand Down
26 changes: 15 additions & 11 deletions internal/services/network/application_security_group_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"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/2022-09-01/applicationsecuritygroups"
"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"
)

func dataSourceApplicationSecurityGroup() *pluginsdk.Resource {
Expand All @@ -35,7 +35,7 @@ func dataSourceApplicationSecurityGroup() *pluginsdk.Resource {

"resource_group_name": commonschema.ResourceGroupNameForDataSource(),

"tags": tags.SchemaDataSource(),
"tags": commonschema.TagsDataSource(),
},
}
}
Expand All @@ -46,10 +46,10 @@ func dataSourceApplicationSecurityGroupRead(d *pluginsdk.ResourceData, meta inte
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id := parse.NewApplicationSecurityGroupID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string))
resp, err := client.Get(ctx, id.ResourceGroup, id.Name)
id := applicationsecuritygroups.NewApplicationSecurityGroupID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string))
resp, err := client.Get(ctx, id)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
if response.WasNotFound(resp.HttpResponse) {
return fmt.Errorf("%s was not found", id)
}

Expand All @@ -58,10 +58,14 @@ func dataSourceApplicationSecurityGroupRead(d *pluginsdk.ResourceData, meta inte

d.SetId(id.ID())

d.Set("name", id.Name)
d.Set("resource_group_name", id.ResourceGroup)
d.Set("name", id.ApplicationSecurityGroupName)
d.Set("resource_group_name", id.ResourceGroupName)

d.Set("location", location.NormalizeNilable(resp.Location))
if model := resp.Model; model != nil {
d.Set("location", location.NormalizeNilable(model.Location))

return tags.FlattenAndSet(d, resp.Tags)
return tags.FlattenAndSet(d, model.Tags)
}

return nil
}
54 changes: 24 additions & 30 deletions internal/services/network/application_security_group_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import (
"log"
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"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/2022-09-01/applicationsecuritygroups"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"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 resourceApplicationSecurityGroup() *pluginsdk.Resource {
Expand All @@ -28,7 +28,7 @@ func resourceApplicationSecurityGroup() *pluginsdk.Resource {
Update: resourceApplicationSecurityGroupCreateUpdate,
Delete: resourceApplicationSecurityGroupDelete,
Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error {
_, err := parse.ApplicationSecurityGroupID(id)
_, err := applicationsecuritygroups.ParseApplicationSecurityGroupID(id)
return err
}),

Expand All @@ -50,7 +50,7 @@ func resourceApplicationSecurityGroup() *pluginsdk.Resource {

"resource_group_name": commonschema.ResourceGroupName(),

"tags": tags.Schema(),
"tags": commonschema.Tags(),
},
}
}
Expand All @@ -61,36 +61,31 @@ func resourceApplicationSecurityGroupCreateUpdate(d *pluginsdk.ResourceData, met
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()

id := parse.NewApplicationSecurityGroupID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string))
id := applicationsecuritygroups.NewApplicationSecurityGroupID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string))
if d.IsNewResource() {
existing, err := client.Get(ctx, id.ResourceGroup, id.Name)
existing, err := client.Get(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_application_security_group", id.ID())
}
}

location := azure.NormalizeLocation(d.Get("location").(string))
t := d.Get("tags").(map[string]interface{})

securityGroup := network.ApplicationSecurityGroup{
securityGroup := applicationsecuritygroups.ApplicationSecurityGroup{
Location: utils.String(location),
Tags: tags.Expand(t),
}
future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, securityGroup)
if err != nil {
if err := client.CreateOrUpdateThenPoll(ctx, id, securityGroup); err != nil {
return fmt.Errorf("creating %s: %+v", id, err)
}

if err = future.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("waiting for the creation of %s: %+v", id, err)
}

d.SetId(id.ID())
return resourceApplicationSecurityGroupRead(d, meta)
}
Expand All @@ -100,14 +95,14 @@ func resourceApplicationSecurityGroupRead(d *pluginsdk.ResourceData, meta interf
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := parse.ApplicationSecurityGroupID(d.Id())
id, err := applicationsecuritygroups.ParseApplicationSecurityGroupID(d.Id())
if err != nil {
return err
}

resp, err := client.Get(ctx, id.ResourceGroup, id.Name)
resp, err := client.Get(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
Expand All @@ -116,31 +111,30 @@ func resourceApplicationSecurityGroupRead(d *pluginsdk.ResourceData, meta interf
return fmt.Errorf("retrieving %s: %+v", *id, err)
}

d.Set("name", id.Name)
d.Set("resource_group_name", id.ResourceGroup)
d.Set("location", location.NormalizeNilable(resp.Location))
return tags.FlattenAndSet(d, resp.Tags)
d.Set("name", id.ApplicationSecurityGroupName)
d.Set("resource_group_name", id.ResourceGroupName)
if model := resp.Model; model != nil {
d.Set("location", location.NormalizeNilable(model.Location))
return tags.FlattenAndSet(d, model.Tags)
}

return nil
}

func resourceApplicationSecurityGroupDelete(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Network.ApplicationSecurityGroupsClient
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := parse.ApplicationSecurityGroupID(d.Id())
id, err := applicationsecuritygroups.ParseApplicationSecurityGroupID(d.Id())
if err != nil {
return err
}

log.Printf("[DEBUG] Deleting %s..", *id)
future, err := client.Delete(ctx, id.ResourceGroup, id.Name)
if err != nil {
if err := client.DeleteThenPoll(ctx, *id); err != nil {
return fmt.Errorf("deleting %s: %+v", *id, err)
}

if err = future.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("waiting for the deletion of %s: %+v", *id, err)
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"fmt"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/network/2022-09-01/applicationsecuritygroups"
"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"
)
Expand Down Expand Up @@ -91,17 +91,17 @@ func TestAccApplicationSecurityGroup_update(t *testing.T) {
}

func (t ApplicationSecurityGroupResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.ApplicationSecurityGroupID(state.ID)
id, err := applicationsecuritygroups.ParseApplicationSecurityGroupID(state.ID)
if err != nil {
return nil, err
}

resp, err := clients.Network.ApplicationSecurityGroupsClient.Get(ctx, id.ResourceGroup, id.Name)
resp, err := clients.Network.ApplicationSecurityGroupsClient.Get(ctx, *id)
if err != nil {
return nil, fmt.Errorf("reading %s: %+v", *id, err)
}

return utils.Bool(resp.ID != nil), nil
return utils.Bool(resp.Model != nil), nil
}

func (ApplicationSecurityGroupResource) basic(data acceptance.TestData) string {
Expand Down
24 changes: 16 additions & 8 deletions internal/services/network/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (

"github.com/hashicorp/go-azure-sdk/resource-manager/network/2022-09-01/adminrulecollections"
"github.com/hashicorp/go-azure-sdk/resource-manager/network/2022-09-01/adminrules"
"github.com/hashicorp/go-azure-sdk/resource-manager/network/2022-09-01/applicationsecuritygroups"
"github.com/hashicorp/go-azure-sdk/resource-manager/network/2022-09-01/connectivityconfigurations"
"github.com/hashicorp/go-azure-sdk/resource-manager/network/2022-09-01/networkgroups"
"github.com/hashicorp/go-azure-sdk/resource-manager/network/2022-09-01/networkmanagerconnections"
"github.com/hashicorp/go-azure-sdk/resource-manager/network/2022-09-01/networkmanagers"
"github.com/hashicorp/go-azure-sdk/resource-manager/network/2022-09-01/privateendpoints"
"github.com/hashicorp/go-azure-sdk/resource-manager/network/2022-09-01/routefilters"
"github.com/hashicorp/go-azure-sdk/resource-manager/network/2022-09-01/routes"
"github.com/hashicorp/go-azure-sdk/resource-manager/network/2022-09-01/routetables"
Expand All @@ -25,7 +27,7 @@ import (

type Client struct {
ApplicationGatewaysClient *network.ApplicationGatewaysClient
ApplicationSecurityGroupsClient *network.ApplicationSecurityGroupsClient
ApplicationSecurityGroupsClient *applicationsecuritygroups.ApplicationSecurityGroupsClient
BastionHostsClient *network.BastionHostsClient
ConfigurationPolicyGroupClient *network.ConfigurationPolicyGroupsClient
ConnectionMonitorsClient *network.ConnectionMonitorsClient
Expand Down Expand Up @@ -57,7 +59,7 @@ type Client struct {
PointToSiteVpnGatewaysClient *network.P2sVpnGatewaysClient
ProfileClient *network.ProfilesClient
PacketCapturesClient *network.PacketCapturesClient
PrivateEndpointClient *network.PrivateEndpointsClient
PrivateEndpointClient *privateendpoints.PrivateEndpointsClient
PublicIPsClient *network.PublicIPAddressesClient
PublicIPPrefixesClient *network.PublicIPPrefixesClient
RouteMapsClient *network.RouteMapsClient
Expand Down Expand Up @@ -97,8 +99,11 @@ func NewClient(o *common.ClientOptions) (*Client, error) {
ApplicationGatewaysClient := network.NewApplicationGatewaysClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&ApplicationGatewaysClient.Client, o.ResourceManagerAuthorizer)

ApplicationSecurityGroupsClient := network.NewApplicationSecurityGroupsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&ApplicationSecurityGroupsClient.Client, o.ResourceManagerAuthorizer)
ApplicationSecurityGroupsClient, err := applicationsecuritygroups.NewApplicationSecurityGroupsClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building application security groups client: %+v", err)
}
o.Configure(ApplicationSecurityGroupsClient.Client, o.Authorizers.ResourceManager)

BastionHostsClient := network.NewBastionHostsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&BastionHostsClient.Client, o.ResourceManagerAuthorizer)
Expand Down Expand Up @@ -226,8 +231,11 @@ func NewClient(o *common.ClientOptions) (*Client, error) {
PacketCapturesClient := network.NewPacketCapturesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&PacketCapturesClient.Client, o.ResourceManagerAuthorizer)

PrivateEndpointClient := network.NewPrivateEndpointsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&PrivateEndpointClient.Client, o.ResourceManagerAuthorizer)
PrivateEndpointClient, err := privateendpoints.NewPrivateEndpointsClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building private endpoint client: %+v", err)
}
o.Configure(PrivateEndpointClient.Client, o.Authorizers.ResourceManager)

VnetPeeringsClient := network.NewVirtualNetworkPeeringsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&VnetPeeringsClient.Client, o.ResourceManagerAuthorizer)
Expand Down Expand Up @@ -336,7 +344,7 @@ func NewClient(o *common.ClientOptions) (*Client, error) {

return &Client{
ApplicationGatewaysClient: &ApplicationGatewaysClient,
ApplicationSecurityGroupsClient: &ApplicationSecurityGroupsClient,
ApplicationSecurityGroupsClient: ApplicationSecurityGroupsClient,
BastionHostsClient: &BastionHostsClient,
ConfigurationPolicyGroupClient: &configurationPolicyGroupClient,
ConnectionMonitorsClient: &ConnectionMonitorsClient,
Expand Down Expand Up @@ -368,7 +376,7 @@ func NewClient(o *common.ClientOptions) (*Client, error) {
PointToSiteVpnGatewaysClient: &pointToSiteVpnGatewaysClient,
ProfileClient: &ProfileClient,
PacketCapturesClient: &PacketCapturesClient,
PrivateEndpointClient: &PrivateEndpointClient,
PrivateEndpointClient: PrivateEndpointClient,
PublicIPsClient: &PublicIPsClient,
PublicIPPrefixesClient: &PublicIPPrefixesClient,
RouteMapsClient: &RouteMapsClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"time"

"github.com/hashicorp/go-azure-sdk/resource-manager/network/2022-09-01/applicationsecuritygroups"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/locks"
Expand All @@ -30,7 +31,7 @@ func resourceNetworkInterfaceApplicationSecurityGroupAssociation() *pluginsdk.Re
if _, err := parse.NetworkInterfaceID(splitId[0]); err != nil {
return err
}
if _, err := parse.ApplicationSecurityGroupID(splitId[1]); err != nil {
if _, err := applicationsecuritygroups.ParseApplicationSecurityGroupID(splitId[1]); err != nil {
return err
}
return nil
Expand Down Expand Up @@ -60,7 +61,7 @@ func resourceNetworkInterfaceApplicationSecurityGroupAssociation() *pluginsdk.Re
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.ApplicationSecurityGroupID,
ValidateFunc: applicationsecuritygroups.ValidateApplicationSecurityGroupID,
},
},
}
Expand Down
Loading

0 comments on commit 4033118

Please sign in to comment.