Skip to content

Commit

Permalink
Fix Read function...
Browse files Browse the repository at this point in the history
  • Loading branch information
WodansSon committed Nov 6, 2023
1 parent 47089e5 commit f9cd346
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
13 changes: 10 additions & 3 deletions internal/services/mssql/helper/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
"context"
"fmt"
"log"

// nolint: staticcheck
"strings"

"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2020-06-01/resources" // nolint: staticcheck
"github.com/hashicorp/go-azure-helpers/lang/pointer"
Expand Down Expand Up @@ -42,10 +41,18 @@ func FindDatabaseReplicationPartners(ctx context.Context, databasesClient *datab

results, err := replicationLinksClient.ListByDatabaseComplete(ctx, replicationDatabaseId)
if err != nil {
if strings.Contains(err.Error(), "ResourceNotFound") {
log.Printf("[INFO] %s does not exist, skipping lookup for Replication Links", id)
return partnerDatabases, nil
}
return nil, fmt.Errorf("reading Replication Links for %s: %+v", id, err)
}

// Not sure if this is really an error anymove given the change in the API...
if len(results.Items) == 0 {
return nil, fmt.Errorf("reading Replication Links for %s: Replication Links Items was empty", id)
// return nil, fmt.Errorf("reading Replication Links for %s: replicationlinks.ListByDatabaseCompleteResult was empty", id)
log.Printf("[INFO] reading Replication Links for %s: replicationlinks.ListByDatabaseCompleteResult was empty", id)
return partnerDatabases, nil
}

var linkProps *replicationlinks.ReplicationLinkProperties
Expand Down
46 changes: 36 additions & 10 deletions internal/services/mssql/mssql_database_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,19 +533,44 @@ func resourceMsSqlDatabaseRead(d *pluginsdk.ResourceData, meta interface{}) erro
skuName := ""
ledgerEnabled := false

d.Set("name", pointer.From(model.Name))
if model.Name != nil {
d.Set("name", pointer.From(model.Name))
}

d.Set("server_id", serverId.ID())

if props := model.Properties; props != nil {
d.Set("auto_pause_delay_in_minutes", props.AutoPauseDelay)
d.Set("collation", props.Collation)
d.Set("elastic_pool_id", props.ElasticPoolId)
d.Set("min_capacity", props.MinCapacity)
d.Set("read_replica_count", props.HighAvailabilityReplicaCount)
d.Set("sku_name", skuName)
d.Set("storage_account_type", string(pointer.From(props.RequestedBackupStorageRedundancy)))
d.Set("zone_redundant", props.ZoneRedundant)
d.Set("read_scale", props.ReadScale == pointer.To(databases.DatabaseReadScaleEnabled))
if props.AutoPauseDelay != nil {
d.Set("auto_pause_delay_in_minutes", props.AutoPauseDelay)
}

if props.Collation != nil {
d.Set("collation", props.Collation)
}

if props.ElasticPoolId != nil {
d.Set("elastic_pool_id", props.ElasticPoolId)
}

if props.MinCapacity != nil {
d.Set("min_capacity", props.MinCapacity)
}

if props.HighAvailabilityReplicaCount != nil {
d.Set("read_replica_count", props.HighAvailabilityReplicaCount)
}

if props.RequestedBackupStorageRedundancy != nil {
d.Set("storage_account_type", string(pointer.From(props.RequestedBackupStorageRedundancy)))
}

if props.ZoneRedundant != nil {
d.Set("zone_redundant", props.ZoneRedundant)
}

if props.ReadScale != nil {
d.Set("read_scale", pointer.From(props.ReadScale) == databases.DatabaseReadScale(databases.DatabaseReadScaleEnabled))
}

if props.LicenseType != nil {
d.Set("license_type", string(pointer.From(props.LicenseType)))
Expand Down Expand Up @@ -575,6 +600,7 @@ func resourceMsSqlDatabaseRead(d *pluginsdk.ResourceData, meta interface{}) erro
configurationName = maintenanceConfigId.PublicMaintenanceConfigurationName
}

d.Set("sku_name", skuName)
d.Set("maintenance_configuration_name", configurationName)
d.Set("ledger_enabled", ledgerEnabled)
}
Expand Down

0 comments on commit f9cd346

Please sign in to comment.