Skip to content

Commit

Permalink
refactor: Remove unused RootDiskSize field and simplify ExtraAPIInfo …
Browse files Browse the repository at this point in the history
…construction (#2974)
  • Loading branch information
EspenAlbert authored Jan 17, 2025
1 parent e4a1590 commit c84ef81
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const (
type ExtraAPIInfo struct {
ZoneNameNumShards map[string]int64
ZoneNameReplicationSpecIDs map[string]string
RootDiskSize *float64
ContainerIDs map[string]string
UsingLegacySchema bool
ForceLegacySchemaFailed bool
Expand Down
17 changes: 3 additions & 14 deletions internal/service/advancedclustertpf/resource_compatiblity.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func findNumShardsUpdates(ctx context.Context, state, plan *TFModel, diags *diag
func resolveAPIInfo(ctx context.Context, diags *diag.Diagnostics, client *config.MongoDBClient, plan *TFModel, clusterLatest *admin.ClusterDescription20240805, forceLegacySchema bool) *ExtraAPIInfo {
var (
api20240530 = client.AtlasV220240530.ClustersApi
rootDiskSize = conversion.NilForUnknown(plan.DiskSizeGB, plan.DiskSizeGB.ValueFloat64Pointer())
projectID = plan.ProjectID.ValueString()
clusterName = plan.Name.ValueString()
forceLegacySchemaFailed = false
Expand All @@ -56,28 +55,18 @@ func resolveAPIInfo(ctx context.Context, diags *diag.Diagnostics, client *config
return nil
}
}
if rootDiskSize == nil {
rootDiskSize = findRegionRootDiskSize(clusterLatest.ReplicationSpecs)
}
containerIDs, err := resolveContainerIDs(ctx, projectID, clusterLatest, client.AtlasV2.NetworkPeeringApi)
if err != nil {
diags.AddError(errorResolveContainerIDs, fmt.Sprintf("cluster name = %s, error details: %s", clusterName, err.Error()))
return nil
}
info := &ExtraAPIInfo{
return &ExtraAPIInfo{
ContainerIDs: containerIDs,
RootDiskSize: rootDiskSize,
ZoneNameReplicationSpecIDs: replicationSpecIDsFromOldAPI(clusterRespOld),
ForceLegacySchemaFailed: forceLegacySchemaFailed,
ZoneNameNumShards: numShardsMapFromOldAPI(clusterRespOld),
UsingLegacySchema: forceLegacySchema || usingLegacySchema(ctx, plan.ReplicationSpecs, diags),
}
if forceLegacySchema {
info.UsingLegacySchema = true
info.ZoneNameNumShards = numShardsMapFromOldAPI(clusterRespOld) // plan is empty in data source Read when forcing legacy, so we get num_shards from the old API
} else {
info.UsingLegacySchema = usingLegacySchema(ctx, plan.ReplicationSpecs, diags)
info.ZoneNameNumShards = numShardsMap(ctx, plan.ReplicationSpecs, diags)
}
return info
}

// instead of using `num_shards` explode the replication specs, and set disk_size_gb
Expand Down

0 comments on commit c84ef81

Please sign in to comment.