Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dependencies: network private endpoint and application security group: swap to use hashicorp/go-azure-sdk #22396

Merged
merged 7 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,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 @@ -341,7 +342,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 @@ -7,6 +7,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 @@ -635,7 +636,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 @@ -6,8 +6,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 @@ -30,7 +30,7 @@ func dataSourceDatabricksWorkspacePrivateEndpointConnection() *pluginsdk.Resourc
"private_endpoint_id": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: networkValidate.PrivateEndpointID,
ValidateFunc: privateendpoints.ValidatePrivateEndpointID,
},

"connections": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,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 @@ -32,7 +32,7 @@ func dataSourceApplicationSecurityGroup() *pluginsdk.Resource {

"resource_group_name": commonschema.ResourceGroupNameForDataSource(),

"tags": tags.SchemaDataSource(),
"tags": commonschema.TagsDataSource(),
},
}
}
Expand All @@ -43,10 +43,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 @@ -55,10 +55,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 @@ -5,17 +5,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 @@ -25,7 +25,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 @@ -47,7 +47,7 @@ func resourceApplicationSecurityGroup() *pluginsdk.Resource {

"resource_group_name": commonschema.ResourceGroupName(),

"tags": tags.Schema(),
"tags": commonschema.Tags(),
},
}
}
Expand All @@ -58,36 +58,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 @@ -97,14 +92,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 @@ -113,31 +108,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 @@ -5,10 +5,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 @@ -88,17 +88,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 @@ -5,10 +5,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 @@ -22,7 +24,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 @@ -54,7 +56,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 @@ -94,8 +96,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 @@ -223,8 +228,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 @@ -333,7 +341,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 @@ -365,7 +373,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 @@ -6,6 +6,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 @@ -27,7 +28,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 @@ -57,7 +58,7 @@ func resourceNetworkInterfaceApplicationSecurityGroupAssociation() *pluginsdk.Re
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.ApplicationSecurityGroupID,
ValidateFunc: applicationsecuritygroups.ValidateApplicationSecurityGroupID,
},
},
}
Expand Down
Loading