diff --git a/.changelog/2814.txt b/.changelog/2814.txt new file mode 100644 index 0000000000..71ab0a867c --- /dev/null +++ b/.changelog/2814.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/mongodbatlas_advanced_cluster: Adjusts update operation to support cluster tier auto scaling per shard. +``` diff --git a/internal/common/conversion/flatten_expand.go b/internal/common/conversion/flatten_expand.go index a9ecb6b727..a28e5ec6fa 100644 --- a/internal/common/conversion/flatten_expand.go +++ b/internal/common/conversion/flatten_expand.go @@ -3,7 +3,6 @@ package conversion import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - admin20240805 "go.mongodb.org/atlas-sdk/v20240805005/admin" "go.mongodb.org/atlas-sdk/v20241023002/admin" ) @@ -29,19 +28,6 @@ func FlattenTags(tags []admin.ResourceTag) []map[string]string { return ret } -func ExpandTagsFromSetSchemaV220240805(d *schema.ResourceData) *[]admin20240805.ResourceTag { - list := d.Get("tags").(*schema.Set) - ret := make([]admin20240805.ResourceTag, list.Len()) - for i, item := range list.List() { - tag := item.(map[string]any) - ret[i] = admin20240805.ResourceTag{ - Key: tag["key"].(string), - Value: tag["value"].(string), - } - } - return &ret -} - func ExpandTagsFromSetSchema(d *schema.ResourceData) *[]admin.ResourceTag { list := d.Get("tags").(*schema.Set) ret := make([]admin.ResourceTag, list.Len()) diff --git a/internal/service/advancedcluster/model_advanced_cluster.go b/internal/service/advancedcluster/model_advanced_cluster.go index abb32a1c8b..10b95389b3 100644 --- a/internal/service/advancedcluster/model_advanced_cluster.go +++ b/internal/service/advancedcluster/model_advanced_cluster.go @@ -12,7 +12,6 @@ import ( "strings" admin20240530 "go.mongodb.org/atlas-sdk/v20240530005/admin" - admin20240805 "go.mongodb.org/atlas-sdk/v20240805005/admin" "go.mongodb.org/atlas-sdk/v20241023002/admin" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -401,7 +400,7 @@ func flattenTags(tags *[]admin.ResourceTag) []map[string]string { } // CheckRegionConfigsPriorityOrder will be deleted in CLOUDP-275825 -func CheckRegionConfigsPriorityOrder(regionConfigs []admin20240805.ReplicationSpec20240805) error { +func CheckRegionConfigsPriorityOrder(regionConfigs []admin.ReplicationSpec20240805) error { for _, spec := range regionConfigs { configs := spec.GetRegionConfigs() for i := 0; i < len(configs)-1; i++ { @@ -473,11 +472,11 @@ func flattenBiConnectorConfig(biConnector *admin.BiConnector) []map[string]any { } } -func expandBiConnectorConfig(d *schema.ResourceData) *admin20240805.BiConnector { +func expandBiConnectorConfig(d *schema.ResourceData) *admin.BiConnector { if v, ok := d.GetOk("bi_connector_config"); ok { if biConn := v.([]any); len(biConn) > 0 { biConnMap := biConn[0].(map[string]any) - return &admin20240805.BiConnector{ + return &admin.BiConnector{ Enabled: conversion.Pointer(cast.ToBool(biConnMap["enabled"])), ReadPreference: conversion.StringPtr(cast.ToString(biConnMap["read_preference"])), } @@ -695,11 +694,11 @@ func hwSpecToDedicatedHwSpec(apiObject *admin.HardwareSpec20240805) *admin.Dedic } } -func dedicatedHwSpecToHwSpec(apiObject *admin20240805.DedicatedHardwareSpec20240805) *admin20240805.HardwareSpec20240805 { +func dedicatedHwSpecToHwSpec(apiObject *admin.DedicatedHardwareSpec20240805) *admin.HardwareSpec20240805 { if apiObject == nil { return nil } - return &admin20240805.HardwareSpec20240805{ + return &admin.HardwareSpec20240805{ DiskSizeGB: apiObject.DiskSizeGB, NodeCount: apiObject.NodeCount, DiskIOPS: apiObject.DiskIOPS, @@ -872,16 +871,16 @@ func IsChangeStreamOptionsMinRequiredMajorVersion(input *string) bool { return value >= minVersionForChangeStreamOptions } -func expandLabelSliceFromSetSchema(d *schema.ResourceData) ([]admin20240805.ComponentLabel, diag.Diagnostics) { +func expandLabelSliceFromSetSchema(d *schema.ResourceData) ([]admin.ComponentLabel, diag.Diagnostics) { list := d.Get("labels").(*schema.Set) - res := make([]admin20240805.ComponentLabel, list.Len()) + res := make([]admin.ComponentLabel, list.Len()) for i, val := range list.List() { v := val.(map[string]any) key := v["key"].(string) if key == ignoreLabel { return nil, diag.FromErr(fmt.Errorf("you should not set `Infrastructure Tool` label, it is used for internal purposes")) } - res[i] = admin20240805.ComponentLabel{ + res[i] = admin.ComponentLabel{ Key: conversion.StringPtr(key), Value: conversion.StringPtr(v["value"].(string)), } @@ -889,8 +888,8 @@ func expandLabelSliceFromSetSchema(d *schema.ResourceData) ([]admin20240805.Comp return res, nil } -func expandAdvancedReplicationSpecs(tfList []any, rootDiskSizeGB *float64) *[]admin20240805.ReplicationSpec20240805 { - var apiObjects []admin20240805.ReplicationSpec20240805 +func expandAdvancedReplicationSpecs(tfList []any, rootDiskSizeGB *float64) *[]admin.ReplicationSpec20240805 { + var apiObjects []admin.ReplicationSpec20240805 for _, tfMapRaw := range tfList { tfMap, ok := tfMapRaw.(map[string]any) if !ok || tfMap == nil { @@ -927,8 +926,8 @@ func expandAdvancedReplicationSpecsOldSDK(tfList []any) *[]admin20240530.Replica return &apiObjects } -func expandAdvancedReplicationSpec(tfMap map[string]any, rootDiskSizeGB *float64) *admin20240805.ReplicationSpec20240805 { - apiObject := &admin20240805.ReplicationSpec20240805{ +func expandAdvancedReplicationSpec(tfMap map[string]any, rootDiskSizeGB *float64) *admin.ReplicationSpec20240805 { + apiObject := &admin.ReplicationSpec20240805{ ZoneName: conversion.StringPtr(tfMap["zone_name"].(string)), RegionConfigs: expandRegionConfigs(tfMap["region_configs"].([]any), rootDiskSizeGB), } @@ -950,8 +949,8 @@ func expandAdvancedReplicationSpecOldSDK(tfMap map[string]any) *admin20240530.Re return apiObject } -func expandRegionConfigs(tfList []any, rootDiskSizeGB *float64) *[]admin20240805.CloudRegionConfig20240805 { - var apiObjects []admin20240805.CloudRegionConfig20240805 +func expandRegionConfigs(tfList []any, rootDiskSizeGB *float64) *[]admin.CloudRegionConfig20240805 { + var apiObjects []admin.CloudRegionConfig20240805 for _, tfMapRaw := range tfList { tfMap, ok := tfMapRaw.(map[string]any) if !ok || tfMap == nil { @@ -966,9 +965,9 @@ func expandRegionConfigs(tfList []any, rootDiskSizeGB *float64) *[]admin20240805 return &apiObjects } -func expandRegionConfig(tfMap map[string]any, rootDiskSizeGB *float64) *admin20240805.CloudRegionConfig20240805 { +func expandRegionConfig(tfMap map[string]any, rootDiskSizeGB *float64) *admin.CloudRegionConfig20240805 { providerName := tfMap["provider_name"].(string) - apiObject := &admin20240805.CloudRegionConfig20240805{ + apiObject := &admin.CloudRegionConfig20240805{ Priority: conversion.Pointer(cast.ToInt(tfMap["priority"])), ProviderName: conversion.StringPtr(providerName), RegionName: conversion.StringPtr(tfMap["region_name"].(string)), @@ -995,9 +994,9 @@ func expandRegionConfig(tfMap map[string]any, rootDiskSizeGB *float64) *admin202 return apiObject } -func expandRegionConfigSpec(tfList []any, providerName string, rootDiskSizeGB *float64) *admin20240805.DedicatedHardwareSpec20240805 { +func expandRegionConfigSpec(tfList []any, providerName string, rootDiskSizeGB *float64) *admin.DedicatedHardwareSpec20240805 { tfMap, _ := tfList[0].(map[string]any) - apiObject := new(admin20240805.DedicatedHardwareSpec20240805) + apiObject := new(admin.DedicatedHardwareSpec20240805) if providerName == constant.AWS || providerName == constant.AZURE { if v, ok := tfMap["disk_iops"]; ok && v.(int) > 0 { apiObject.DiskIOPS = conversion.Pointer(v.(int)) @@ -1027,11 +1026,11 @@ func expandRegionConfigSpec(tfList []any, providerName string, rootDiskSizeGB *f return apiObject } -func expandRegionConfigAutoScaling(tfList []any) *admin20240805.AdvancedAutoScalingSettings { +func expandRegionConfigAutoScaling(tfList []any) *admin.AdvancedAutoScalingSettings { tfMap, _ := tfList[0].(map[string]any) - settings := admin20240805.AdvancedAutoScalingSettings{ - DiskGB: new(admin20240805.DiskGBAutoScaling), - Compute: new(admin20240805.AdvancedComputeAutoScaling), + settings := admin.AdvancedAutoScalingSettings{ + DiskGB: new(admin.DiskGBAutoScaling), + Compute: new(admin.AdvancedComputeAutoScaling), } if v, ok := tfMap["disk_gb_enabled"]; ok { diff --git a/internal/service/advancedcluster/model_advanced_cluster_test.go b/internal/service/advancedcluster/model_advanced_cluster_test.go index ecef34a418..7dd517c469 100644 --- a/internal/service/advancedcluster/model_advanced_cluster_test.go +++ b/internal/service/advancedcluster/model_advanced_cluster_test.go @@ -8,7 +8,6 @@ import ( "testing" admin20240530 "go.mongodb.org/atlas-sdk/v20240530005/admin" - admin20240805 "go.mongodb.org/atlas-sdk/v20240805005/admin" "go.mongodb.org/atlas-sdk/v20241023002/admin" "go.mongodb.org/atlas-sdk/v20241023002/mockadmin" @@ -451,13 +450,13 @@ func TestCheckRegionConfigsPriorityOrder(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { - configs := make([]admin20240805.CloudRegionConfig20240805, len(tc.priorities)) + configs := make([]admin.CloudRegionConfig20240805, len(tc.priorities)) configsOld := make([]admin20240530.CloudRegionConfig, len(tc.priorities)) for i, priority := range tc.priorities { configs[i].Priority = conversion.IntPtr(priority) configsOld[i].Priority = conversion.IntPtr(priority) } - err := advancedcluster.CheckRegionConfigsPriorityOrder([]admin20240805.ReplicationSpec20240805{{RegionConfigs: &configs}}) + err := advancedcluster.CheckRegionConfigsPriorityOrder([]admin.ReplicationSpec20240805{{RegionConfigs: &configs}}) assert.Equal(t, tc.errorExpected, err != nil) err = advancedcluster.CheckRegionConfigsPriorityOrderOld([]admin20240530.ReplicationSpec{{RegionConfigs: &configsOld}}) assert.Equal(t, tc.errorExpected, err != nil) diff --git a/internal/service/advancedcluster/model_sdk_version_conversion.go b/internal/service/advancedcluster/model_sdk_version_conversion.go index 8226efb633..292cc71136 100644 --- a/internal/service/advancedcluster/model_sdk_version_conversion.go +++ b/internal/service/advancedcluster/model_sdk_version_conversion.go @@ -2,7 +2,6 @@ package advancedcluster import ( admin20240530 "go.mongodb.org/atlas-sdk/v20240530005/admin" - admin20240805 "go.mongodb.org/atlas-sdk/v20240805005/admin" "go.mongodb.org/atlas-sdk/v20241023002/admin" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -20,7 +19,7 @@ func convertTagsPtrToLatest(tags *[]admin20240530.ResourceTag) *[]admin.Resource return &result } -func convertTagsPtrToOldSDK(tags *[]admin20240805.ResourceTag) *[]admin20240530.ResourceTag { +func convertTagsPtrToOldSDK(tags *[]admin.ResourceTag) *[]admin20240530.ResourceTag { if tags == nil { return nil } @@ -48,7 +47,7 @@ func convertTagsToLatest(tags []admin20240530.ResourceTag) []admin.ResourceTag { return results } -func convertBiConnectToOldSDK(biconnector *admin20240805.BiConnector) *admin20240530.BiConnector { +func convertBiConnectToOldSDK(biconnector *admin.BiConnector) *admin20240530.BiConnector { if biconnector == nil { return nil } @@ -126,7 +125,7 @@ func convertLabelsToLatest(labels *[]admin20240530.ComponentLabel) *[]admin.Comp return &results } -func convertLabelSliceToOldSDK(slice []admin20240805.ComponentLabel, err diag.Diagnostics) ([]admin20240530.ComponentLabel, diag.Diagnostics) { +func convertLabelSliceToOldSDK(slice []admin.ComponentLabel, err diag.Diagnostics) ([]admin20240530.ComponentLabel, diag.Diagnostics) { if err != nil { return nil, err } @@ -141,7 +140,7 @@ func convertLabelSliceToOldSDK(slice []admin20240805.ComponentLabel, err diag.Di return results, nil } -func convertRegionConfigSliceToOldSDK(slice *[]admin20240805.CloudRegionConfig20240805) *[]admin20240530.CloudRegionConfig { +func convertRegionConfigSliceToOldSDK(slice *[]admin.CloudRegionConfig20240805) *[]admin20240530.CloudRegionConfig { if slice == nil { return nil } @@ -164,7 +163,7 @@ func convertRegionConfigSliceToOldSDK(slice *[]admin20240805.CloudRegionConfig20 return &results } -func convertHardwareSpecToOldSDK(hwspec *admin20240805.HardwareSpec20240805) *admin20240530.HardwareSpec { +func convertHardwareSpecToOldSDK(hwspec *admin.HardwareSpec20240805) *admin20240530.HardwareSpec { if hwspec == nil { return nil } @@ -176,7 +175,7 @@ func convertHardwareSpecToOldSDK(hwspec *admin20240805.HardwareSpec20240805) *ad } } -func convertAdvancedAutoScalingSettingsToOldSDK(settings *admin20240805.AdvancedAutoScalingSettings) *admin20240530.AdvancedAutoScalingSettings { +func convertAdvancedAutoScalingSettingsToOldSDK(settings *admin.AdvancedAutoScalingSettings) *admin20240530.AdvancedAutoScalingSettings { if settings == nil { return nil } @@ -186,7 +185,7 @@ func convertAdvancedAutoScalingSettingsToOldSDK(settings *admin20240805.Advanced } } -func convertAdvancedComputeAutoScalingToOldSDK(settings *admin20240805.AdvancedComputeAutoScaling) *admin20240530.AdvancedComputeAutoScaling { +func convertAdvancedComputeAutoScalingToOldSDK(settings *admin.AdvancedComputeAutoScaling) *admin20240530.AdvancedComputeAutoScaling { if settings == nil { return nil } @@ -198,7 +197,7 @@ func convertAdvancedComputeAutoScalingToOldSDK(settings *admin20240805.AdvancedC } } -func convertDiskGBAutoScalingToOldSDK(settings *admin20240805.DiskGBAutoScaling) *admin20240530.DiskGBAutoScaling { +func convertDiskGBAutoScalingToOldSDK(settings *admin.DiskGBAutoScaling) *admin20240530.DiskGBAutoScaling { if settings == nil { return nil } @@ -207,7 +206,7 @@ func convertDiskGBAutoScalingToOldSDK(settings *admin20240805.DiskGBAutoScaling) } } -func convertDedicatedHardwareSpecToOldSDK(spec *admin20240805.DedicatedHardwareSpec20240805) *admin20240530.DedicatedHardwareSpec { +func convertDedicatedHardwareSpecToOldSDK(spec *admin.DedicatedHardwareSpec20240805) *admin20240530.DedicatedHardwareSpec { if spec == nil { return nil } diff --git a/internal/service/advancedcluster/resource_advanced_cluster.go b/internal/service/advancedcluster/resource_advanced_cluster.go index 5e12803397..38b53ab5cc 100644 --- a/internal/service/advancedcluster/resource_advanced_cluster.go +++ b/internal/service/advancedcluster/resource_advanced_cluster.go @@ -416,7 +416,7 @@ func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag. rootDiskSizeGB = conversion.Pointer(v.(float64)) } - params := &admin20240805.ClusterDescription20240805{ + params := &admin.ClusterDescription20240805{ Name: conversion.StringPtr(cast.ToString(d.Get("name"))), ClusterType: conversion.StringPtr(cast.ToString(d.Get("cluster_type"))), ReplicationSpecs: expandAdvancedReplicationSpecs(d.Get("replication_specs").([]any), rootDiskSizeGB), @@ -442,7 +442,7 @@ func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag. } if _, ok := d.GetOk("tags"); ok { - params.Tags = conversion.ExpandTagsFromSetSchemaV220240805(d) + params.Tags = conversion.ExpandTagsFromSetSchema(d) } if v, ok := d.GetOk("mongo_db_major_version"); ok { params.MongoDBMajorVersion = conversion.StringPtr(FormatMongoDBMajorVersion(v.(string))) @@ -482,8 +482,8 @@ func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag. if err := CheckRegionConfigsPriorityOrder(params.GetReplicationSpecs()); err != nil { return diag.FromErr(err) } - // cannot call latest API (2024-10-23 or newer) as it can enable ISS autoscaling - cluster, _, err := connV220240805.ClustersApi.CreateCluster(ctx, projectID, params).Execute() + + cluster, _, err := connV2.ClustersApi.CreateCluster(ctx, projectID, params).Execute() if err != nil { return diag.FromErr(fmt.Errorf(errorCreate, err)) } @@ -821,7 +821,6 @@ func resourceUpgrade(ctx context.Context, upgradeRequest *admin.LegacyAtlasTenan func resourceUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { connV220240530 := meta.(*config.MongoDBClient).AtlasV220240530 - connV220240805 := meta.(*config.MongoDBClient).AtlasV220240805 connV2 := meta.(*config.MongoDBClient).AtlasV2 ids := conversion.DecodeStateID(d.Id()) projectID := ids["project_id"] @@ -850,7 +849,7 @@ func resourceUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag. waitOnUpdate = true } if d.HasChange("replica_set_scaling_strategy") || d.HasChange("redact_client_log_data") || d.HasChange("config_server_management_mode") { - request := new(admin20240805.ClusterDescription20240805) + request := new(admin.ClusterDescription20240805) if d.HasChange("replica_set_scaling_strategy") { request.ReplicaSetScalingStrategy = conversion.Pointer(d.Get("replica_set_scaling_strategy").(string)) } @@ -860,8 +859,8 @@ func resourceUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag. if d.HasChange("config_server_management_mode") { request.ConfigServerManagementMode = conversion.StringPtr(d.Get("config_server_management_mode").(string)) } - // can call latest API (2024-10-23 or newer) as autoscaling property is not specified, using older version just for caution until iss autoscaling epic is done - if _, _, err := connV220240805.ClustersApi.UpdateCluster(ctx, projectID, clusterName, request).Execute(); err != nil { + // can call latest API (2024-10-23 or newer) as replications specs with autoscaling property is not specified + if _, _, err := connV2.ClustersApi.UpdateCluster(ctx, projectID, clusterName, request).Execute(); err != nil { return diag.FromErr(fmt.Errorf(errorUpdate, clusterName, err)) } waitOnUpdate = true @@ -881,8 +880,7 @@ func resourceUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag. if err := CheckRegionConfigsPriorityOrder(req.GetReplicationSpecs()); err != nil { return diag.FromErr(err) } - // cannot call latest API (2024-10-23 or newer) as it can enable ISS autoscaling - if _, _, err := connV220240805.ClustersApi.UpdateCluster(ctx, projectID, clusterName, req).Execute(); err != nil { + if _, _, err := connV2.ClustersApi.UpdateCluster(ctx, projectID, clusterName, req).Execute(); err != nil { return diag.FromErr(fmt.Errorf(errorUpdate, clusterName, err)) } if err := waitForUpdateToFinish(ctx, connV2, projectID, clusterName, timeout); err != nil { @@ -916,11 +914,10 @@ func resourceUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag. } if d.Get("paused").(bool) { - clusterRequest := &admin20240805.ClusterDescription20240805{ + clusterRequest := &admin.ClusterDescription20240805{ Paused: conversion.Pointer(true), } - // can call latest API (2024-10-23 or newer) as autoscaling property is not specified, using older version just for caution until iss autoscaling epic is done - if _, _, err := connV220240805.ClustersApi.UpdateCluster(ctx, projectID, clusterName, clusterRequest).Execute(); err != nil { + if _, _, err := connV2.ClustersApi.UpdateCluster(ctx, projectID, clusterName, clusterRequest).Execute(); err != nil { return diag.FromErr(fmt.Errorf(errorUpdate, clusterName, err)) } if err := waitForUpdateToFinish(ctx, connV2, projectID, clusterName, timeout); err != nil { @@ -931,8 +928,8 @@ func resourceUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag. return resourceRead(ctx, d, meta) } -func updateRequest(ctx context.Context, d *schema.ResourceData, projectID, clusterName string, connV2 *admin.APIClient) (*admin20240805.ClusterDescription20240805, diag.Diagnostics) { - cluster := new(admin20240805.ClusterDescription20240805) +func updateRequest(ctx context.Context, d *schema.ResourceData, projectID, clusterName string, connV2 *admin.APIClient) (*admin.ClusterDescription20240805, diag.Diagnostics) { + cluster := new(admin.ClusterDescription20240805) if d.HasChange("replication_specs") || d.HasChange("disk_size_gb") { var updatedDiskSizeGB *float64 @@ -979,7 +976,7 @@ func updateRequest(ctx context.Context, d *schema.ResourceData, projectID, clust } if d.HasChange("tags") { - cluster.Tags = conversion.ExpandTagsFromSetSchemaV220240805(d) + cluster.Tags = conversion.ExpandTagsFromSetSchema(d) } if d.HasChange("mongo_db_major_version") { @@ -1073,7 +1070,7 @@ func updateRequestOldAPI(d *schema.ResourceData, clusterName string) (*admin2024 } if d.HasChange("tags") { - cluster.Tags = convertTagsPtrToOldSDK(conversion.ExpandTagsFromSetSchemaV220240805(d)) + cluster.Tags = convertTagsPtrToOldSDK(conversion.ExpandTagsFromSetSchema(d)) } if d.HasChange("mongo_db_major_version") { diff --git a/internal/service/advancedcluster/resource_update_logic.go b/internal/service/advancedcluster/resource_update_logic.go index 1e643ab581..8caa468583 100644 --- a/internal/service/advancedcluster/resource_update_logic.go +++ b/internal/service/advancedcluster/resource_update_logic.go @@ -6,11 +6,10 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - admin20240805 "go.mongodb.org/atlas-sdk/v20240805005/admin" "go.mongodb.org/atlas-sdk/v20241023002/admin" ) -func noIDsPopulatedInReplicationSpecs(replicationSpecs *[]admin20240805.ReplicationSpec20240805) bool { +func noIDsPopulatedInReplicationSpecs(replicationSpecs *[]admin.ReplicationSpec20240805) bool { if replicationSpecs == nil || len(*replicationSpecs) == 0 { return false } @@ -22,7 +21,7 @@ func noIDsPopulatedInReplicationSpecs(replicationSpecs *[]admin20240805.Replicat return true } -func populateIDValuesUsingNewAPI(ctx context.Context, projectID, clusterName string, connV2ClusterAPI admin.ClustersApi, replicationSpecs *[]admin20240805.ReplicationSpec20240805) (*[]admin20240805.ReplicationSpec20240805, diag.Diagnostics) { +func populateIDValuesUsingNewAPI(ctx context.Context, projectID, clusterName string, connV2ClusterAPI admin.ClustersApi, replicationSpecs *[]admin.ReplicationSpec20240805) (*[]admin.ReplicationSpec20240805, diag.Diagnostics) { if replicationSpecs == nil || len(*replicationSpecs) == 0 { return replicationSpecs, nil } @@ -36,7 +35,7 @@ func populateIDValuesUsingNewAPI(ctx context.Context, projectID, clusterName str return &result, nil } -func AddIDsToReplicationSpecs(replicationSpecs []admin20240805.ReplicationSpec20240805, zoneToReplicationSpecsIDs map[string][]string) []admin20240805.ReplicationSpec20240805 { +func AddIDsToReplicationSpecs(replicationSpecs []admin.ReplicationSpec20240805, zoneToReplicationSpecsIDs map[string][]string) []admin.ReplicationSpec20240805 { for zoneName, availableIDs := range zoneToReplicationSpecsIDs { var indexOfIDToUse = 0 for i := range replicationSpecs { @@ -65,12 +64,12 @@ func groupIDsByZone(specs []admin.ReplicationSpec20240805) map[string][]string { // - Existing replication specs can have the autoscaling values present in the state with default values even if not defined in the config (case when cluster is imported) // - API expects autoScaling and analyticsAutoScaling aligned cross all region configs in the PATCH request // This function is needed to avoid errors if a new replication spec is added, ensuring the PATCH request will have the auto scaling aligned with other replication specs when not present in config. -func SyncAutoScalingConfigs(replicationSpecs *[]admin20240805.ReplicationSpec20240805) { +func SyncAutoScalingConfigs(replicationSpecs *[]admin.ReplicationSpec20240805) { if replicationSpecs == nil || len(*replicationSpecs) == 0 { return } - var defaultAnalyticsAutoScaling, defaultAutoScaling *admin20240805.AdvancedAutoScalingSettings + var defaultAnalyticsAutoScaling, defaultAutoScaling *admin.AdvancedAutoScalingSettings for _, spec := range *replicationSpecs { for i := range *spec.RegionConfigs { @@ -86,7 +85,7 @@ func SyncAutoScalingConfigs(replicationSpecs *[]admin20240805.ReplicationSpec202 applyDefaultAutoScaling(replicationSpecs, defaultAutoScaling, defaultAnalyticsAutoScaling) } -func applyDefaultAutoScaling(replicationSpecs *[]admin20240805.ReplicationSpec20240805, defaultAutoScaling, defaultAnalyticsAutoScaling *admin20240805.AdvancedAutoScalingSettings) { +func applyDefaultAutoScaling(replicationSpecs *[]admin.ReplicationSpec20240805, defaultAutoScaling, defaultAnalyticsAutoScaling *admin.AdvancedAutoScalingSettings) { for _, spec := range *replicationSpecs { for i := range *spec.RegionConfigs { regionConfig := &(*spec.RegionConfigs)[i] diff --git a/internal/service/advancedcluster/resource_update_logic_test.go b/internal/service/advancedcluster/resource_update_logic_test.go index 1528450bbc..a53cbce6fd 100644 --- a/internal/service/advancedcluster/resource_update_logic_test.go +++ b/internal/service/advancedcluster/resource_update_logic_test.go @@ -5,18 +5,17 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/advancedcluster" "github.com/stretchr/testify/assert" - admin20240805 "go.mongodb.org/atlas-sdk/v20240805005/admin" "go.mongodb.org/atlas-sdk/v20241023002/admin" ) func TestAddIDsToReplicationSpecs(t *testing.T) { testCases := map[string]struct { - ReplicationSpecs []admin20240805.ReplicationSpec20240805 + ReplicationSpecs []admin.ReplicationSpec20240805 ZoneToReplicationSpecsIDs map[string][]string - ExpectedReplicationSpecs []admin20240805.ReplicationSpec20240805 + ExpectedReplicationSpecs []admin.ReplicationSpec20240805 }{ "two zones with same amount of available ids and replication specs to populate": { - ReplicationSpecs: []admin20240805.ReplicationSpec20240805{ + ReplicationSpecs: []admin.ReplicationSpec20240805{ { ZoneName: admin.PtrString("Zone 1"), }, @@ -34,7 +33,7 @@ func TestAddIDsToReplicationSpecs(t *testing.T) { "Zone 1": {"zone1-id1", "zone1-id2"}, "Zone 2": {"zone2-id1", "zone2-id2"}, }, - ExpectedReplicationSpecs: []admin20240805.ReplicationSpec20240805{ + ExpectedReplicationSpecs: []admin.ReplicationSpec20240805{ { ZoneName: admin.PtrString("Zone 1"), Id: admin.PtrString("zone1-id1"), @@ -54,7 +53,7 @@ func TestAddIDsToReplicationSpecs(t *testing.T) { }, }, "less available ids than replication specs to populate": { - ReplicationSpecs: []admin20240805.ReplicationSpec20240805{ + ReplicationSpecs: []admin.ReplicationSpec20240805{ { ZoneName: admin.PtrString("Zone 1"), }, @@ -72,7 +71,7 @@ func TestAddIDsToReplicationSpecs(t *testing.T) { "Zone 1": {"zone1-id1"}, "Zone 2": {"zone2-id1"}, }, - ExpectedReplicationSpecs: []admin20240805.ReplicationSpec20240805{ + ExpectedReplicationSpecs: []admin.ReplicationSpec20240805{ { ZoneName: admin.PtrString("Zone 1"), Id: admin.PtrString("zone1-id1"), @@ -92,7 +91,7 @@ func TestAddIDsToReplicationSpecs(t *testing.T) { }, }, "more available ids than replication specs to populate": { - ReplicationSpecs: []admin20240805.ReplicationSpec20240805{ + ReplicationSpecs: []admin.ReplicationSpec20240805{ { ZoneName: admin.PtrString("Zone 1"), }, @@ -104,7 +103,7 @@ func TestAddIDsToReplicationSpecs(t *testing.T) { "Zone 1": {"zone1-id1", "zone1-id2"}, "Zone 2": {"zone2-id1", "zone2-id2"}, }, - ExpectedReplicationSpecs: []admin20240805.ReplicationSpec20240805{ + ExpectedReplicationSpecs: []admin.ReplicationSpec20240805{ { ZoneName: admin.PtrString("Zone 1"), Id: admin.PtrString("zone1-id1"), @@ -127,23 +126,23 @@ func TestAddIDsToReplicationSpecs(t *testing.T) { func TestSyncAutoScalingConfigs(t *testing.T) { testCases := map[string]struct { - ReplicationSpecs []admin20240805.ReplicationSpec20240805 - ExpectedReplicationSpecs []admin20240805.ReplicationSpec20240805 + ReplicationSpecs []admin.ReplicationSpec20240805 + ExpectedReplicationSpecs []admin.ReplicationSpec20240805 }{ "apply same autoscaling options for new replication spec which does not have autoscaling defined": { - ReplicationSpecs: []admin20240805.ReplicationSpec20240805{ + ReplicationSpecs: []admin.ReplicationSpec20240805{ { Id: admin.PtrString("id-1"), - RegionConfigs: &[]admin20240805.CloudRegionConfig20240805{ + RegionConfigs: &[]admin.CloudRegionConfig20240805{ { - AutoScaling: &admin20240805.AdvancedAutoScalingSettings{ - Compute: &admin20240805.AdvancedComputeAutoScaling{ + AutoScaling: &admin.AdvancedAutoScalingSettings{ + Compute: &admin.AdvancedComputeAutoScaling{ Enabled: admin.PtrBool(false), ScaleDownEnabled: admin.PtrBool(false), }, }, - AnalyticsAutoScaling: &admin20240805.AdvancedAutoScalingSettings{ - Compute: &admin20240805.AdvancedComputeAutoScaling{ + AnalyticsAutoScaling: &admin.AdvancedAutoScalingSettings{ + Compute: &admin.AdvancedComputeAutoScaling{ Enabled: admin.PtrBool(false), ScaleDownEnabled: admin.PtrBool(false), }, @@ -153,7 +152,7 @@ func TestSyncAutoScalingConfigs(t *testing.T) { }, { Id: admin.PtrString("id-2"), - RegionConfigs: &[]admin20240805.CloudRegionConfig20240805{ + RegionConfigs: &[]admin.CloudRegionConfig20240805{ { AutoScaling: nil, AnalyticsAutoScaling: nil, @@ -161,19 +160,19 @@ func TestSyncAutoScalingConfigs(t *testing.T) { }, }, }, - ExpectedReplicationSpecs: []admin20240805.ReplicationSpec20240805{ + ExpectedReplicationSpecs: []admin.ReplicationSpec20240805{ { Id: admin.PtrString("id-1"), - RegionConfigs: &[]admin20240805.CloudRegionConfig20240805{ + RegionConfigs: &[]admin.CloudRegionConfig20240805{ { - AutoScaling: &admin20240805.AdvancedAutoScalingSettings{ - Compute: &admin20240805.AdvancedComputeAutoScaling{ + AutoScaling: &admin.AdvancedAutoScalingSettings{ + Compute: &admin.AdvancedComputeAutoScaling{ Enabled: admin.PtrBool(false), ScaleDownEnabled: admin.PtrBool(false), }, }, - AnalyticsAutoScaling: &admin20240805.AdvancedAutoScalingSettings{ - Compute: &admin20240805.AdvancedComputeAutoScaling{ + AnalyticsAutoScaling: &admin.AdvancedAutoScalingSettings{ + Compute: &admin.AdvancedComputeAutoScaling{ Enabled: admin.PtrBool(false), ScaleDownEnabled: admin.PtrBool(false), }, @@ -183,16 +182,16 @@ func TestSyncAutoScalingConfigs(t *testing.T) { }, { Id: admin.PtrString("id-2"), - RegionConfigs: &[]admin20240805.CloudRegionConfig20240805{ + RegionConfigs: &[]admin.CloudRegionConfig20240805{ { - AutoScaling: &admin20240805.AdvancedAutoScalingSettings{ - Compute: &admin20240805.AdvancedComputeAutoScaling{ + AutoScaling: &admin.AdvancedAutoScalingSettings{ + Compute: &admin.AdvancedComputeAutoScaling{ Enabled: admin.PtrBool(false), ScaleDownEnabled: admin.PtrBool(false), }, }, - AnalyticsAutoScaling: &admin20240805.AdvancedAutoScalingSettings{ - Compute: &admin20240805.AdvancedComputeAutoScaling{ + AnalyticsAutoScaling: &admin.AdvancedAutoScalingSettings{ + Compute: &admin.AdvancedComputeAutoScaling{ Enabled: admin.PtrBool(false), ScaleDownEnabled: admin.PtrBool(false), }, @@ -204,19 +203,19 @@ func TestSyncAutoScalingConfigs(t *testing.T) { }, // for this case the API will respond with an error and guide the user to align autoscaling options cross all nodes "when different autoscaling options are defined values will not be changed": { - ReplicationSpecs: []admin20240805.ReplicationSpec20240805{ + ReplicationSpecs: []admin.ReplicationSpec20240805{ { Id: admin.PtrString("id-1"), - RegionConfigs: &[]admin20240805.CloudRegionConfig20240805{ + RegionConfigs: &[]admin.CloudRegionConfig20240805{ { - AutoScaling: &admin20240805.AdvancedAutoScalingSettings{ - Compute: &admin20240805.AdvancedComputeAutoScaling{ + AutoScaling: &admin.AdvancedAutoScalingSettings{ + Compute: &admin.AdvancedComputeAutoScaling{ Enabled: admin.PtrBool(false), ScaleDownEnabled: admin.PtrBool(false), }, }, - AnalyticsAutoScaling: &admin20240805.AdvancedAutoScalingSettings{ - Compute: &admin20240805.AdvancedComputeAutoScaling{ + AnalyticsAutoScaling: &admin.AdvancedAutoScalingSettings{ + Compute: &admin.AdvancedComputeAutoScaling{ Enabled: admin.PtrBool(true), ScaleDownEnabled: admin.PtrBool(true), }, @@ -226,15 +225,15 @@ func TestSyncAutoScalingConfigs(t *testing.T) { }, { Id: admin.PtrString("id-2"), - RegionConfigs: &[]admin20240805.CloudRegionConfig20240805{ + RegionConfigs: &[]admin.CloudRegionConfig20240805{ { - AutoScaling: &admin20240805.AdvancedAutoScalingSettings{ - Compute: &admin20240805.AdvancedComputeAutoScaling{ + AutoScaling: &admin.AdvancedAutoScalingSettings{ + Compute: &admin.AdvancedComputeAutoScaling{ Enabled: admin.PtrBool(true), }, }, - AnalyticsAutoScaling: &admin20240805.AdvancedAutoScalingSettings{ - Compute: &admin20240805.AdvancedComputeAutoScaling{ + AnalyticsAutoScaling: &admin.AdvancedAutoScalingSettings{ + Compute: &admin.AdvancedComputeAutoScaling{ Enabled: admin.PtrBool(false), }, }, @@ -242,19 +241,19 @@ func TestSyncAutoScalingConfigs(t *testing.T) { }, }, }, - ExpectedReplicationSpecs: []admin20240805.ReplicationSpec20240805{ + ExpectedReplicationSpecs: []admin.ReplicationSpec20240805{ { Id: admin.PtrString("id-1"), - RegionConfigs: &[]admin20240805.CloudRegionConfig20240805{ + RegionConfigs: &[]admin.CloudRegionConfig20240805{ { - AutoScaling: &admin20240805.AdvancedAutoScalingSettings{ - Compute: &admin20240805.AdvancedComputeAutoScaling{ + AutoScaling: &admin.AdvancedAutoScalingSettings{ + Compute: &admin.AdvancedComputeAutoScaling{ Enabled: admin.PtrBool(false), ScaleDownEnabled: admin.PtrBool(false), }, }, - AnalyticsAutoScaling: &admin20240805.AdvancedAutoScalingSettings{ - Compute: &admin20240805.AdvancedComputeAutoScaling{ + AnalyticsAutoScaling: &admin.AdvancedAutoScalingSettings{ + Compute: &admin.AdvancedComputeAutoScaling{ Enabled: admin.PtrBool(true), ScaleDownEnabled: admin.PtrBool(true), }, @@ -264,15 +263,15 @@ func TestSyncAutoScalingConfigs(t *testing.T) { }, { Id: admin.PtrString("id-2"), - RegionConfigs: &[]admin20240805.CloudRegionConfig20240805{ + RegionConfigs: &[]admin.CloudRegionConfig20240805{ { - AutoScaling: &admin20240805.AdvancedAutoScalingSettings{ - Compute: &admin20240805.AdvancedComputeAutoScaling{ + AutoScaling: &admin.AdvancedAutoScalingSettings{ + Compute: &admin.AdvancedComputeAutoScaling{ Enabled: admin.PtrBool(true), }, }, - AnalyticsAutoScaling: &admin20240805.AdvancedAutoScalingSettings{ - Compute: &admin20240805.AdvancedComputeAutoScaling{ + AnalyticsAutoScaling: &admin.AdvancedAutoScalingSettings{ + Compute: &admin.AdvancedComputeAutoScaling{ Enabled: admin.PtrBool(false), }, },