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: updating to v0.20231129.1103252 of github.com/hashicorp/go-azure-sdk #24063

Merged
merged 5 commits into from
Nov 29, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ require (
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/google/go-cmp v0.5.9
github.com/google/uuid v1.3.1
github.com/hashicorp/go-azure-helpers v0.63.0
github.com/hashicorp/go-azure-sdk v0.20231124.1163225
github.com/hashicorp/go-azure-helpers v0.64.0
github.com/hashicorp/go-azure-sdk v0.20231129.1103252
github.com/hashicorp/go-hclog v1.5.0
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-uuid v1.0.3
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-azure-helpers v0.12.0/go.mod h1:Zc3v4DNeX6PDdy7NljlYpnrdac1++qNW0I4U+ofGwpg=
github.com/hashicorp/go-azure-helpers v0.63.0 h1:7bYnYZsqzPjxVevi0z8Irwp5DwS8okLcaA183DQAcmY=
github.com/hashicorp/go-azure-helpers v0.63.0/go.mod h1:ELmZ65vzHJNTk6ml4jsPD+xq2gZb7t78D35s+XN02Kk=
github.com/hashicorp/go-azure-sdk v0.20231124.1163225 h1:ko/p/fRdcjxqnGiwcLKVysoYXr8T66EgfrB/3Hqntcw=
github.com/hashicorp/go-azure-sdk v0.20231124.1163225/go.mod h1:mdU6Hrw1jPiwBFmENOcjRlkMWi6yRI0Tt+p4vmPvc0g=
github.com/hashicorp/go-azure-helpers v0.64.0 h1:JNTt0F7tbApmpmF9hzNq2TN1lduOiXJFkMFoAPVctK8=
github.com/hashicorp/go-azure-helpers v0.64.0/go.mod h1:ELmZ65vzHJNTk6ml4jsPD+xq2gZb7t78D35s+XN02Kk=
github.com/hashicorp/go-azure-sdk v0.20231129.1103252 h1:H5SzxFYj++yIwN4o3WeEz0qMDFDOGeQt+H/j0yyhhz8=
github.com/hashicorp/go-azure-sdk v0.20231129.1103252/go.mod h1:MfF4SCtGLaSP7OeJk+Y3xd4MQL5tFbz31c+ERP1S9D0=
github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3mlgcqk5mU=
github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuDrwkBuEQsVcpCOgg=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
Expand Down
9 changes: 5 additions & 4 deletions internal/services/mssql/helper/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/Azure/azure-sdk-for-go/services/preview/sql/mgmt/v5.0/sql" // nolint: staticcheck
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2020-06-01/resources" // nolint: staticcheck
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/mssql/parse"
"github.com/hashicorp/terraform-provider-azurerm/utils"
Expand All @@ -18,7 +19,7 @@ import (
// FindDatabaseReplicationPartners looks for partner databases having one of the specified replication roles, by
// reading any replication links then attempting to discover and match the corresponding server/database resources for
// the other end of the link.
func FindDatabaseReplicationPartners(ctx context.Context, databasesClient *sql.DatabasesClient, replicationLinksClient *sql.ReplicationLinksClient, resourcesClient *resources.Client, id parse.DatabaseId, rolesToFind []sql.ReplicationRole) ([]sql.Database, error) {
func FindDatabaseReplicationPartners(ctx context.Context, databasesClient *sql.DatabasesClient, replicationLinksClient *sql.ReplicationLinksClient, resourcesClient *resources.Client, id commonids.SqlDatabaseId, rolesToFind []sql.ReplicationRole) ([]sql.Database, error) {
var partnerDatabases []sql.Database

matchesRole := func(role sql.ReplicationRole) bool {
Expand All @@ -30,7 +31,7 @@ func FindDatabaseReplicationPartners(ctx context.Context, databasesClient *sql.D
return false
}

for linksIterator, err := replicationLinksClient.ListByDatabaseComplete(ctx, id.ResourceGroup, id.ServerName, id.Name); linksIterator.NotDone(); err = linksIterator.NextWithContext(ctx) {
for linksIterator, err := replicationLinksClient.ListByDatabaseComplete(ctx, id.ResourceGroupName, id.ServerName, id.DatabaseName); linksIterator.NotDone(); err = linksIterator.NextWithContext(ctx) {
if err != nil {
return nil, fmt.Errorf("reading Replication Links for %s: %+v", id, err)
}
Expand Down Expand Up @@ -91,8 +92,8 @@ func FindDatabaseReplicationPartners(ctx context.Context, databasesClient *sql.D

// If the database has a replication link for the specified role, we'll consider it a partner of this database if the location is the same as expected partner
if matchesRole(linkPropsPossiblePartner.Role) {
partnerDatabaseId := parse.NewDatabaseID(partnerServerId.SubscriptionId, partnerServerId.ResourceGroup, partnerServerId.Name, *linkProps.PartnerDatabase)
partnerDatabase, err := databasesClient.Get(ctx, partnerDatabaseId.ResourceGroup, partnerDatabaseId.ServerName, partnerDatabaseId.Name)
partnerDatabaseId := commonids.NewSqlDatabaseID(partnerServerId.SubscriptionId, partnerServerId.ResourceGroup, partnerServerId.Name, *linkProps.PartnerDatabase)
partnerDatabase, err := databasesClient.Get(ctx, partnerDatabaseId.ResourceGroupName, partnerDatabaseId.ServerName, partnerDatabaseId.DatabaseName)
if err != nil {
return nil, fmt.Errorf("retrieving Partner %s: %+v", partnerDatabaseId, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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/services/mssql/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/mssql/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"
Expand Down Expand Up @@ -45,7 +44,7 @@ func resourceMsSqlDatabaseExtendedAuditingPolicy() *pluginsdk.Resource {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.DatabaseID,
ValidateFunc: commonids.ValidateSqlDatabaseID,
},

"enabled": {
Expand Down Expand Up @@ -96,13 +95,13 @@ func resourceMsSqlDatabaseExtendedAuditingPolicyCreateUpdate(d *pluginsdk.Resour

log.Printf("[INFO] preparing arguments for MsSql Database Extended Auditing Policy creation.")

dbId, err := parse.DatabaseID(d.Get("database_id").(string))
dbId, err := commonids.ParseSqlDatabaseID(d.Get("database_id").(string))
if err != nil {
return err
}

if d.IsNewResource() {
existing, err := client.Get(ctx, dbId.ResourceGroup, dbId.ServerName, dbId.Name)
existing, err := client.Get(ctx, dbId.ResourceGroupName, dbId.ServerName, dbId.DatabaseName)
if err != nil {
if !utils.ResponseWasNotFound(existing.Response) {
return fmt.Errorf("checking for the presence of existing %s: %+v", dbId, err)
Expand Down Expand Up @@ -134,11 +133,11 @@ func resourceMsSqlDatabaseExtendedAuditingPolicyCreateUpdate(d *pluginsdk.Resour
params.ExtendedDatabaseBlobAuditingPolicyProperties.StorageAccountAccessKey = utils.String(v.(string))
}

if _, err = client.CreateOrUpdate(ctx, dbId.ResourceGroup, dbId.ServerName, dbId.Name, params); err != nil {
if _, err = client.CreateOrUpdate(ctx, dbId.ResourceGroupName, dbId.ServerName, dbId.DatabaseName, params); err != nil {
return fmt.Errorf("creating extended auditing policy for %s: %+v", dbId, err)
}

read, err := client.Get(ctx, dbId.ResourceGroup, dbId.ServerName, dbId.Name)
read, err := client.Get(ctx, dbId.ResourceGroupName, dbId.ServerName, dbId.DatabaseName)
if err != nil {
return fmt.Errorf("retrieving the extended auditing policy for %s: %+v", dbId, err)
}
Expand Down
41 changes: 15 additions & 26 deletions internal/services/mssql/mssql_database_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/locks"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/mssql/helper"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/mssql/migration"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/mssql/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/mssql/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress"
Expand All @@ -48,7 +47,7 @@ func resourceMsSqlDatabase() *pluginsdk.Resource {
Delete: resourceMsSqlDatabaseDelete,

Importer: pluginsdk.ImporterValidatingResourceIdThen(func(id string) error {
_, err := parse.DatabaseID(id)
_, err := commonids.ParseSqlDatabaseID(id)
return err
}, resourceMsSqlDatabaseImporter),

Expand Down Expand Up @@ -88,7 +87,7 @@ func resourceMsSqlDatabaseImporter(ctx context.Context, d *pluginsdk.ResourceDat
legacyreplicationLinksClient := meta.(*clients.Client).MSSQL.LegacyReplicationLinksClient
resourcesClient := meta.(*clients.Client).Resource.ResourcesClient

id, err := parse.DatabaseID(d.Id())
id, err := commonids.ParseSqlDatabaseID(d.Id())
if err != nil {
return nil, err
}
Expand All @@ -101,7 +100,7 @@ func resourceMsSqlDatabaseImporter(ctx context.Context, d *pluginsdk.ResourceDat
if len(partnerDatabases) > 0 {
partnerDatabase := partnerDatabases[0]

partnerDatabaseId, err := parse.DatabaseID(*partnerDatabase.ID)
partnerDatabaseId, err := commonids.ParseSqlDatabaseIDInsensitively(*partnerDatabase.ID)
if err != nil {
return nil, fmt.Errorf("parsing ID for Replication Partner Database %q: %+v", *partnerDatabase.ID, err)
}
Expand Down Expand Up @@ -186,20 +185,15 @@ func resourceMsSqlDatabaseCreate(d *pluginsdk.ResourceData, meta interface{}) er
locks.ByID(id.ID())
defer locks.UnlockByID(id.ID())

legacyId, err := parse.DatabaseID(id.ID())
if err != nil {
return fmt.Errorf("parsing ID for Replication Partner Database %s: %+v", id, err)
}

if skuName := d.Get("sku_name"); skuName != "" {
partnerDatabases, err := helper.FindDatabaseReplicationPartners(ctx, legacyClient, legacyReplicationLinksClient, resourcesClient, *legacyId, []sql.ReplicationRole{sql.ReplicationRoleSecondary, sql.ReplicationRoleNonReadableSecondary})
partnerDatabases, err := helper.FindDatabaseReplicationPartners(ctx, legacyClient, legacyReplicationLinksClient, resourcesClient, id, []sql.ReplicationRole{sql.ReplicationRoleSecondary, sql.ReplicationRoleNonReadableSecondary})
if err != nil {
return err
}

// Place a lock for the partner databases, so they can't update themselves whilst we're poking their SKUs
for _, partnerDatabase := range partnerDatabases {
partnerDatabaseId, err := parse.DatabaseID(*partnerDatabase.ID)
partnerDatabaseId, err := commonids.ParseSqlDatabaseIDInsensitively(*partnerDatabase.ID)
if err != nil {
return fmt.Errorf("parsing ID for Replication Partner Database %q: %+v", *partnerDatabase.ID, err)
}
Expand All @@ -210,14 +204,14 @@ func resourceMsSqlDatabaseCreate(d *pluginsdk.ResourceData, meta interface{}) er

// Update the SKUs of any partner databases where deemed necessary
for _, partnerDatabase := range partnerDatabases {
partnerDatabaseId, err := parse.DatabaseID(*partnerDatabase.ID)
partnerDatabaseId, err := commonids.ParseSqlDatabaseIDInsensitively(*partnerDatabase.ID)
if err != nil {
return fmt.Errorf("parsing ID for Replication Partner Database %q: %+v", *partnerDatabase.ID, err)
}

// See: https://docs.microsoft.com/en-us/azure/azure-sql/database/active-geo-replication-overview#configuring-secondary-database
if partnerDatabase.Sku != nil && partnerDatabase.Sku.Name != nil && helper.CompareDatabaseSkuServiceTiers(skuName.(string), *partnerDatabase.Sku.Name) {
future, err := legacyClient.Update(ctx, partnerDatabaseId.ResourceGroup, partnerDatabaseId.ServerName, partnerDatabaseId.Name, sql.DatabaseUpdate{
future, err := legacyClient.Update(ctx, partnerDatabaseId.ResourceGroupName, partnerDatabaseId.ServerName, partnerDatabaseId.DatabaseName, sql.DatabaseUpdate{
Sku: &sql.Sku{
Name: utils.String(skuName.(string)),
},
Expand Down Expand Up @@ -495,7 +489,7 @@ func resourceMsSqlDatabaseRead(d *pluginsdk.ResourceData, meta interface{}) erro
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := commonids.ParseDatabaseID(d.Id())
id, err := commonids.ParseSqlDatabaseID(d.Id())
if err != nil {
return err
}
Expand Down Expand Up @@ -720,20 +714,15 @@ func resourceMsSqlDatabaseUpdate(d *pluginsdk.ResourceData, meta interface{}) er
locks.ByID(id.ID())
defer locks.UnlockByID(id.ID())

legacyId, err := parse.DatabaseID(id.ID())
if err != nil {
return fmt.Errorf("parsing ID for Replication Partner Database %s: %+v", id, err)
}

if d.HasChange("sku_name") && skuName != "" {
partnerDatabases, err := helper.FindDatabaseReplicationPartners(ctx, legacyClient, legacyReplicationLinksClient, resourcesClient, *legacyId, []sql.ReplicationRole{sql.ReplicationRoleSecondary, sql.ReplicationRoleNonReadableSecondary})
partnerDatabases, err := helper.FindDatabaseReplicationPartners(ctx, legacyClient, legacyReplicationLinksClient, resourcesClient, id, []sql.ReplicationRole{sql.ReplicationRoleSecondary, sql.ReplicationRoleNonReadableSecondary})
if err != nil {
return err
}

// Place a lock for the partner databases, so they can't update themselves whilst we're poking their SKUs
for _, v := range partnerDatabases {
id, err := parse.DatabaseID(pointer.From(v.ID))
id, err := commonids.ParseSqlDatabaseIDInsensitively(pointer.From(v.ID))
if err != nil {
return fmt.Errorf("parsing ID for Replication Partner Database %q: %+v", id.ID(), err)
}
Expand All @@ -744,14 +733,14 @@ func resourceMsSqlDatabaseUpdate(d *pluginsdk.ResourceData, meta interface{}) er

// Update the SKUs of any partner databases where deemed necessary
for _, partnerDatabase := range partnerDatabases {
partnerDatabaseId, err := parse.DatabaseID(*partnerDatabase.ID)
partnerDatabaseId, err := commonids.ParseSqlDatabaseIDInsensitively(*partnerDatabase.ID)
if err != nil {
return fmt.Errorf("parsing ID for Replication Partner Database %q: %+v", *partnerDatabase.ID, err)
}

// See: https://docs.microsoft.com/en-us/azure/azure-sql/database/active-geo-replication-overview#configuring-secondary-database
if partnerDatabase.Sku != nil && partnerDatabase.Sku.Name != nil && helper.CompareDatabaseSkuServiceTiers(skuName, *partnerDatabase.Sku.Name) {
future, err := legacyClient.Update(ctx, partnerDatabaseId.ResourceGroup, partnerDatabaseId.ServerName, partnerDatabaseId.Name, sql.DatabaseUpdate{
future, err := legacyClient.Update(ctx, partnerDatabaseId.ResourceGroupName, partnerDatabaseId.ServerName, partnerDatabaseId.DatabaseName, sql.DatabaseUpdate{
Sku: &sql.Sku{
Name: pointer.To(skuName),
},
Expand Down Expand Up @@ -1047,12 +1036,12 @@ func resourceMsSqlDatabaseDelete(d *pluginsdk.ResourceData, meta interface{}) er
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := commonids.ParseDatabaseID(d.Id())
id, err := commonids.ParseSqlDatabaseID(d.Id())
if err != nil {
return err
}

err = client.DeleteThenPoll(ctx, pointer.From(id))
err = client.DeleteThenPoll(ctx, *id)
if err != nil {
return fmt.Errorf("deleting %s: %+v", id, err)
}
Expand Down Expand Up @@ -1382,7 +1371,7 @@ func resourceMsSqlDatabaseSchema() map[string]*pluginsdk.Schema {
Optional: true,
ForceNew: true,
Computed: true,
ValidateFunc: validate.DatabaseID,
ValidateFunc: commonids.ValidateSqlDatabaseID,
},

"storage_account_type": {
Expand Down
2 changes: 1 addition & 1 deletion internal/services/mssql/mssql_database_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ func TestAccMsSqlDatabase_bacpac(t *testing.T) {
}

func (MsSqlDatabaseResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := commonids.ParseDatabaseID(state.ID)
id, err := commonids.ParseSqlDatabaseID(state.ID)
if err != nil {
return nil, err
}
Expand Down
10 changes: 7 additions & 3 deletions internal/services/mssql/mssql_job_agent_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/Azure/azure-sdk-for-go/services/preview/sql/mgmt/v5.0/sql" // nolint: staticcheck
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
Expand Down Expand Up @@ -52,7 +53,7 @@ func resourceMsSqlJobAgent() *pluginsdk.Resource {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.DatabaseID,
ValidateFunc: commonids.ValidateSqlDatabaseID,
},

"location": commonschema.Location(),
Expand All @@ -71,8 +72,11 @@ func resourceMsSqlJobAgentCreateUpdate(d *pluginsdk.ResourceData, meta interface

location := azure.NormalizeLocation(d.Get("location").(string))
databaseId := d.Get("database_id").(string)
dbId, _ := parse.DatabaseID(databaseId)
id := parse.NewJobAgentID(dbId.SubscriptionId, dbId.ResourceGroup, dbId.ServerName, d.Get("name").(string))
dbId, err := commonids.ParseSqlDatabaseID(databaseId)
if err != nil {
return err
}
id := parse.NewJobAgentID(dbId.SubscriptionId, dbId.ResourceGroupName, dbId.ServerName, d.Get("name").(string))

if d.IsNewResource() {
existing, err := client.Get(ctx, id.ResourceGroup, id.ServerName, id.Name)
Expand Down
78 changes: 0 additions & 78 deletions internal/services/mssql/parse/database.go

This file was deleted.

Loading
Loading