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

chore: Update dev preview to use latest version of cluster API #2406

Merged
merged 1 commit into from
Jul 11, 2024
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/zclconf/go-cty v1.14.4
go.mongodb.org/atlas v0.36.0
go.mongodb.org/atlas-sdk/v20231115014 v20231115014.0.0
go.mongodb.org/atlas-sdk/v20240530002 v20240530002.0.1-0.20240703083409-9e77f6cad45f
go.mongodb.org/atlas-sdk/v20240530002 v20240530002.0.1-0.20240710142852-8a1b5dd5d8f3
go.mongodb.org/realm v0.1.0
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,8 @@ go.mongodb.org/atlas-sdk/v20240530002 v20240530002.0.0 h1:D+e3bpRwa9WH3HHs8bLjOd
go.mongodb.org/atlas-sdk/v20240530002 v20240530002.0.0/go.mod h1:seuG5HpfG20/8FhJGyWi4yL7hqAcmq7pf/G0gipNOyM=
go.mongodb.org/atlas-sdk/v20240530002 v20240530002.0.1-0.20240703083409-9e77f6cad45f h1:p4oDdUBXj4hW/QUwQ6R3Uqx8tMJw1Z8g4b6/hfZBHfk=
go.mongodb.org/atlas-sdk/v20240530002 v20240530002.0.1-0.20240703083409-9e77f6cad45f/go.mod h1:seuG5HpfG20/8FhJGyWi4yL7hqAcmq7pf/G0gipNOyM=
go.mongodb.org/atlas-sdk/v20240530002 v20240530002.0.1-0.20240710142852-8a1b5dd5d8f3 h1:Y2OD2wNisDWY/am92KmGGftOZxLOXSzr9+WyACRQ1Zw=
go.mongodb.org/atlas-sdk/v20240530002 v20240530002.0.1-0.20240710142852-8a1b5dd5d8f3/go.mod h1:seuG5HpfG20/8FhJGyWi4yL7hqAcmq7pf/G0gipNOyM=
go.mongodb.org/realm v0.1.0 h1:zJiXyLaZrznQ+Pz947ziSrDKUep39DO4SfA0Fzx8M4M=
go.mongodb.org/realm v0.1.0/go.mod h1:4Vj6iy+Puo1TDERcoh4XZ+pjtwbOzPpzqy3Cwe8ZmDM=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.
return nil
}

func setRootFields(d *schema.ResourceData, cluster *admin.ClusterDescription20240710) diag.Diagnostics {
func setRootFields(d *schema.ResourceData, cluster *admin.ClusterDescription20250101) diag.Diagnostics {
clusterName := *cluster.Name

if err := d.Set("backup_enabled", cluster.GetBackupEnabled()); err != nil {
Expand Down
48 changes: 24 additions & 24 deletions internal/service/advancedcluster/model_advanced_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,14 +458,14 @@ func FlattenAdvancedReplicationSpecsOldSDK(ctx context.Context, apiObjects []adm
doesAdvancedReplicationSpecMatchAPIOldSDK, replicationSpecFlattener, connV2)
}

func flattenAdvancedReplicationSpecs(ctx context.Context, apiObjects []admin.ReplicationSpec20240710, tfMapObjects []any,
func flattenAdvancedReplicationSpecs(ctx context.Context, apiObjects []admin.ReplicationSpec20250101, tfMapObjects []any,
d *schema.ResourceData, connV2 *admin.APIClient) ([]map[string]any, error) {
return flattenAdvancedReplicationSpecsLogic[admin.ReplicationSpec20240710](ctx, apiObjects, tfMapObjects, d,
return flattenAdvancedReplicationSpecsLogic[admin.ReplicationSpec20250101](ctx, apiObjects, tfMapObjects, d,
doesAdvancedReplicationSpecMatchAPI, flattenAdvancedReplicationSpec, connV2)
}

type ReplicationSpecSDKModel interface {
admin20231115.ReplicationSpec | admin.ReplicationSpec20240710
admin20231115.ReplicationSpec | admin.ReplicationSpec20250101
}

func flattenAdvancedReplicationSpecsLogic[T ReplicationSpecSDKModel](
Expand Down Expand Up @@ -533,7 +533,7 @@ func doesAdvancedReplicationSpecMatchAPIOldSDK(tfObject map[string]any, apiObjec
return tfObject["id"] == apiObject.GetId() || (tfObject["id"] == nil && tfObject["zone_name"] == apiObject.GetZoneName())
}

func doesAdvancedReplicationSpecMatchAPI(tfObject map[string]any, apiObject *admin.ReplicationSpec20240710) bool {
func doesAdvancedReplicationSpecMatchAPI(tfObject map[string]any, apiObject *admin.ReplicationSpec20250101) bool {
return tfObject["external_id"] == apiObject.GetId()
}

Expand Down Expand Up @@ -566,7 +566,7 @@ func flattenAdvancedReplicationSpecOldSDK(ctx context.Context, apiObject *admin2
return tfMap, nil
}

func flattenAdvancedReplicationSpecRegionConfigs(ctx context.Context, apiObjects []admin.CloudRegionConfig20240710, tfMapObjects []any,
func flattenAdvancedReplicationSpecRegionConfigs(ctx context.Context, apiObjects []admin.CloudRegionConfig20250101, tfMapObjects []any,
d *schema.ResourceData, connV2 *admin.APIClient) (tfResult []map[string]any, containersIDs map[string]string, err error) {
if len(apiObjects) == 0 {
return nil, nil, nil
Expand Down Expand Up @@ -602,7 +602,7 @@ func flattenAdvancedReplicationSpecRegionConfigs(ctx context.Context, apiObjects
return tfList, containerIDs, nil
}

func flattenAdvancedReplicationSpecRegionConfig(apiObject *admin.CloudRegionConfig20240710, tfMapObject map[string]any) map[string]any {
func flattenAdvancedReplicationSpecRegionConfig(apiObject *admin.CloudRegionConfig20250101, tfMapObject map[string]any) map[string]any {
if apiObject == nil {
return nil
}
Expand Down Expand Up @@ -640,11 +640,11 @@ func flattenAdvancedReplicationSpecRegionConfig(apiObject *admin.CloudRegionConf
return tfMap
}

func hwSpecToDedicatedHwSpec(apiObject *admin.HardwareSpec20240710) *admin.DedicatedHardwareSpec20240710 {
func hwSpecToDedicatedHwSpec(apiObject *admin.HardwareSpec20250101) *admin.DedicatedHardwareSpec20250101 {
if apiObject == nil {
return nil
}
return &admin.DedicatedHardwareSpec20240710{
return &admin.DedicatedHardwareSpec20250101{
NodeCount: apiObject.NodeCount,
DiskIOPS: apiObject.DiskIOPS,
EbsVolumeType: apiObject.EbsVolumeType,
Expand All @@ -653,11 +653,11 @@ func hwSpecToDedicatedHwSpec(apiObject *admin.HardwareSpec20240710) *admin.Dedic
}
}

func dedicatedHwSpecToHwSpec(apiObject *admin.DedicatedHardwareSpec20240710) *admin.HardwareSpec20240710 {
func dedicatedHwSpecToHwSpec(apiObject *admin.DedicatedHardwareSpec20250101) *admin.HardwareSpec20250101 {
if apiObject == nil {
return nil
}
return &admin.HardwareSpec20240710{
return &admin.HardwareSpec20250101{
DiskSizeGB: apiObject.DiskSizeGB,
NodeCount: apiObject.NodeCount,
DiskIOPS: apiObject.DiskIOPS,
Expand All @@ -666,7 +666,7 @@ func dedicatedHwSpecToHwSpec(apiObject *admin.DedicatedHardwareSpec20240710) *ad
}
}

func flattenAdvancedReplicationSpecRegionConfigSpec(apiObject *admin.DedicatedHardwareSpec20240710, providerName string, tfMapObjects []any) []map[string]any {
func flattenAdvancedReplicationSpecRegionConfigSpec(apiObject *admin.DedicatedHardwareSpec20250101, providerName string, tfMapObjects []any) []map[string]any {
if apiObject == nil {
return nil
}
Expand Down Expand Up @@ -725,7 +725,7 @@ func flattenAdvancedReplicationSpecAutoScaling(apiObject *admin.AdvancedAutoScal
return tfList
}

func getAdvancedClusterContainerID(containers []admin.CloudProviderContainer, cluster *admin.CloudRegionConfig20240710) string {
func getAdvancedClusterContainerID(containers []admin.CloudProviderContainer, cluster *admin.CloudRegionConfig20250101) string {
if len(containers) == 0 {
return ""
}
Expand Down Expand Up @@ -820,8 +820,8 @@ func expandLabelSliceFromSetSchema(d *schema.ResourceData) ([]admin.ComponentLab
return res, nil
}

func expandAdvancedReplicationSpecs(tfList []any, rootDiskSizeGB *float64) *[]admin.ReplicationSpec20240710 {
var apiObjects []admin.ReplicationSpec20240710
func expandAdvancedReplicationSpecs(tfList []any, rootDiskSizeGB *float64) *[]admin.ReplicationSpec20250101 {
var apiObjects []admin.ReplicationSpec20250101
for _, tfMapRaw := range tfList {
tfMap, ok := tfMapRaw.(map[string]any)
if !ok || tfMap == nil {
Expand Down Expand Up @@ -858,8 +858,8 @@ func expandAdvancedReplicationSpecsOldSDK(tfList []any) *[]admin20231115.Replica
return &apiObjects
}

func expandAdvancedReplicationSpec(tfMap map[string]any, rootDiskSizeGB *float64) *admin.ReplicationSpec20240710 {
apiObject := &admin.ReplicationSpec20240710{
func expandAdvancedReplicationSpec(tfMap map[string]any, rootDiskSizeGB *float64) *admin.ReplicationSpec20250101 {
apiObject := &admin.ReplicationSpec20250101{
ZoneName: conversion.StringPtr(tfMap["zone_name"].(string)),
RegionConfigs: expandRegionConfigs(tfMap["region_configs"].([]any), rootDiskSizeGB),
}
Expand All @@ -879,8 +879,8 @@ func expandAdvancedReplicationSpecOldSDK(tfMap map[string]any) *admin20231115.Re
return apiObject
}

func expandRegionConfigs(tfList []any, rootDiskSizeGB *float64) *[]admin.CloudRegionConfig20240710 {
var apiObjects []admin.CloudRegionConfig20240710
func expandRegionConfigs(tfList []any, rootDiskSizeGB *float64) *[]admin.CloudRegionConfig20250101 {
var apiObjects []admin.CloudRegionConfig20250101
for _, tfMapRaw := range tfList {
tfMap, ok := tfMapRaw.(map[string]any)
if !ok || tfMap == nil {
Expand All @@ -895,9 +895,9 @@ func expandRegionConfigs(tfList []any, rootDiskSizeGB *float64) *[]admin.CloudRe
return &apiObjects
}

func expandRegionConfig(tfMap map[string]any, rootDiskSizeGB *float64) *admin.CloudRegionConfig20240710 {
func expandRegionConfig(tfMap map[string]any, rootDiskSizeGB *float64) *admin.CloudRegionConfig20250101 {
providerName := tfMap["provider_name"].(string)
apiObject := &admin.CloudRegionConfig20240710{
apiObject := &admin.CloudRegionConfig20250101{
Priority: conversion.Pointer(cast.ToInt(tfMap["priority"])),
ProviderName: conversion.StringPtr(providerName),
RegionName: conversion.StringPtr(tfMap["region_name"].(string)),
Expand All @@ -924,9 +924,9 @@ func expandRegionConfig(tfMap map[string]any, rootDiskSizeGB *float64) *admin.Cl
return apiObject
}

func expandRegionConfigSpec(tfList []any, providerName string, rootDiskSizeGB *float64) *admin.DedicatedHardwareSpec20240710 {
func expandRegionConfigSpec(tfList []any, providerName string, rootDiskSizeGB *float64) *admin.DedicatedHardwareSpec20250101 {
tfMap, _ := tfList[0].(map[string]any)
apiObject := new(admin.DedicatedHardwareSpec20240710)
apiObject := new(admin.DedicatedHardwareSpec20250101)
if providerName == "AWS" {
if v, ok := tfMap["disk_iops"]; ok && v.(int) > 0 {
apiObject.DiskIOPS = conversion.Pointer(v.(int))
Expand Down Expand Up @@ -979,7 +979,7 @@ func expandRegionConfigAutoScaling(tfList []any) *admin.AdvancedAutoScalingSetti
return &settings
}

func flattenAdvancedReplicationSpecsDS(ctx context.Context, apiRepSpecs []admin.ReplicationSpec20240710, d *schema.ResourceData, connV2 *admin.APIClient) ([]map[string]any, error) {
func flattenAdvancedReplicationSpecsDS(ctx context.Context, apiRepSpecs []admin.ReplicationSpec20250101, d *schema.ResourceData, connV2 *admin.APIClient) ([]map[string]any, error) {
if len(apiRepSpecs) == 0 {
return nil, nil
}
Expand All @@ -996,7 +996,7 @@ func flattenAdvancedReplicationSpecsDS(ctx context.Context, apiRepSpecs []admin.
return tfList, nil
}

func flattenAdvancedReplicationSpec(ctx context.Context, apiObject *admin.ReplicationSpec20240710, tfMapObject map[string]any,
func flattenAdvancedReplicationSpec(ctx context.Context, apiObject *admin.ReplicationSpec20250101, tfMapObject map[string]any,
d *schema.ResourceData, connV2 *admin.APIClient) (map[string]any, error) {
if apiObject == nil {
return nil, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var (
dummyClusterName = "clusterName"
dummyProjectID = "projectId"
errGeneric = errors.New("generic")
advancedClusters = []admin.ClusterDescription20240710{{StateName: conversion.StringPtr("NOT IDLE")}}
advancedClusters = []admin.ClusterDescription20250101{{StateName: conversion.StringPtr("NOT IDLE")}}
)

func TestFlattenReplicationSpecs(t *testing.T) {
Expand Down Expand Up @@ -252,7 +252,7 @@ func TestUpgradeRefreshFunc(t *testing.T) {

func TestResourceListAdvancedRefreshFunc(t *testing.T) {
testCases := []struct {
mockCluster *admin.PaginatedClusterDescription20240710
mockCluster *admin.PaginatedClusterDescription20250101
mockResponse *http.Response
expectedResult Result
mockError error
Expand Down Expand Up @@ -314,7 +314,7 @@ func TestResourceListAdvancedRefreshFunc(t *testing.T) {
},
{
name: "Successful but with at least one cluster not idle",
mockCluster: &admin.PaginatedClusterDescription20240710{Results: &advancedClusters},
mockCluster: &admin.PaginatedClusterDescription20250101{Results: &advancedClusters},
mockResponse: &http.Response{StatusCode: 200},
expectedError: false,
expectedResult: Result{
Expand All @@ -325,11 +325,11 @@ func TestResourceListAdvancedRefreshFunc(t *testing.T) {
},
{
name: "Successful",
mockCluster: &admin.PaginatedClusterDescription20240710{},
mockCluster: &admin.PaginatedClusterDescription20250101{},
mockResponse: &http.Response{StatusCode: 200},
expectedError: false,
expectedResult: Result{
response: &admin.PaginatedClusterDescription20240710{},
response: &admin.PaginatedClusterDescription20250101{},
state: "IDLE",
error: nil,
},
Expand Down
24 changes: 12 additions & 12 deletions internal/service/advancedcluster/model_sdk_version_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func convertLabelSliceToOldSDK(slice []admin.ComponentLabel, err diag.Diagnostic
return results, nil
}

func convertRegionConfigSliceToOldSDK(slice *[]admin.CloudRegionConfig20240710) *[]admin20231115.CloudRegionConfig {
func convertRegionConfigSliceToOldSDK(slice *[]admin.CloudRegionConfig20250101) *[]admin20231115.CloudRegionConfig {
if slice == nil {
return nil
}
Expand All @@ -163,7 +163,7 @@ func convertRegionConfigSliceToOldSDK(slice *[]admin.CloudRegionConfig20240710)
return &results
}

func convertHardwareSpecToOldSDK(hwspec *admin.HardwareSpec20240710) *admin20231115.HardwareSpec {
func convertHardwareSpecToOldSDK(hwspec *admin.HardwareSpec20250101) *admin20231115.HardwareSpec {
if hwspec == nil {
return nil
}
Expand Down Expand Up @@ -206,7 +206,7 @@ func convertDiskGBAutoScalingToOldSDK(settings *admin.DiskGBAutoScaling) *admin2
}
}

func convertDedicatedHardwareSpecToOldSDK(spec *admin.DedicatedHardwareSpec20240710) *admin20231115.DedicatedHardwareSpec {
func convertDedicatedHardwareSpecToOldSDK(spec *admin.DedicatedHardwareSpec20250101) *admin20231115.DedicatedHardwareSpec {
if spec == nil {
return nil
}
Expand All @@ -218,11 +218,11 @@ func convertDedicatedHardwareSpecToOldSDK(spec *admin.DedicatedHardwareSpec20240
}
}

func convertDedicatedHwSpecToLatest(spec *admin20231115.DedicatedHardwareSpec, rootDiskSizeGB float64) *admin.DedicatedHardwareSpec20240710 {
func convertDedicatedHwSpecToLatest(spec *admin20231115.DedicatedHardwareSpec, rootDiskSizeGB float64) *admin.DedicatedHardwareSpec20250101 {
if spec == nil {
return nil
}
return &admin.DedicatedHardwareSpec20240710{
return &admin.DedicatedHardwareSpec20250101{
NodeCount: spec.NodeCount,
DiskIOPS: spec.DiskIOPS,
EbsVolumeType: spec.EbsVolumeType,
Expand Down Expand Up @@ -262,11 +262,11 @@ func convertDiskGBAutoScalingToLatest(settings *admin20231115.DiskGBAutoScaling)
}
}

func convertHardwareSpecToLatest(hwspec *admin20231115.HardwareSpec, rootDiskSizeGB float64) *admin.HardwareSpec20240710 {
func convertHardwareSpecToLatest(hwspec *admin20231115.HardwareSpec, rootDiskSizeGB float64) *admin.HardwareSpec20250101 {
if hwspec == nil {
return nil
}
return &admin.HardwareSpec20240710{
return &admin.HardwareSpec20250101{
DiskIOPS: hwspec.DiskIOPS,
EbsVolumeType: hwspec.EbsVolumeType,
InstanceSize: hwspec.InstanceSize,
Expand All @@ -275,15 +275,15 @@ func convertHardwareSpecToLatest(hwspec *admin20231115.HardwareSpec, rootDiskSiz
}
}

func convertRegionConfigSliceToLatest(slice *[]admin20231115.CloudRegionConfig, rootDiskSizeGB float64) *[]admin.CloudRegionConfig20240710 {
func convertRegionConfigSliceToLatest(slice *[]admin20231115.CloudRegionConfig, rootDiskSizeGB float64) *[]admin.CloudRegionConfig20250101 {
if slice == nil {
return nil
}
cloudRegionSlice := *slice
results := make([]admin.CloudRegionConfig20240710, len(cloudRegionSlice))
results := make([]admin.CloudRegionConfig20250101, len(cloudRegionSlice))
for i := range len(cloudRegionSlice) {
cloudRegion := cloudRegionSlice[i]
results[i] = admin.CloudRegionConfig20240710{
results[i] = admin.CloudRegionConfig20250101{
ElectableSpecs: convertHardwareSpecToLatest(cloudRegion.ElectableSpecs, rootDiskSizeGB),
Priority: cloudRegion.Priority,
ProviderName: cloudRegion.ProviderName,
Expand All @@ -298,8 +298,8 @@ func convertRegionConfigSliceToLatest(slice *[]admin20231115.CloudRegionConfig,
return &results
}

func convertClusterDescToLatestExcludeRepSpecs(oldClusterDesc *admin20231115.AdvancedClusterDescription) *admin.ClusterDescription20240710 {
return &admin.ClusterDescription20240710{
func convertClusterDescToLatestExcludeRepSpecs(oldClusterDesc *admin20231115.AdvancedClusterDescription) *admin.ClusterDescription20250101 {
return &admin.ClusterDescription20250101{
BackupEnabled: oldClusterDesc.BackupEnabled,
AcceptDataRisksAndForceReplicaSetReconfig: oldClusterDesc.AcceptDataRisksAndForceReplicaSetReconfig,
ClusterType: oldClusterDesc.ClusterType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.
rootDiskSizeGB = conversion.Pointer(v.(float64))
}

params := &admin.ClusterDescription20240710{
params := &admin.ClusterDescription20250101{
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),
Expand Down Expand Up @@ -505,7 +505,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di
projectID := ids["project_id"]
clusterName := ids["cluster_name"]

var clusterResp *admin.ClusterDescription20240710
var clusterResp *admin.ClusterDescription20250101

var replicationSpecs []map[string]any
if isUsingOldAPISchemaStructure(d) {
Expand Down Expand Up @@ -570,7 +570,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di
}

// TODO: CLOUDP-259838 this can likely be unified with data source function setRootFields
func setResourceRootFields(d *schema.ResourceData, cluster *admin.ClusterDescription20240710) diag.Diagnostics {
func setResourceRootFields(d *schema.ResourceData, cluster *admin.ClusterDescription20250101) diag.Diagnostics {
clusterName := *cluster.Name

if err := d.Set("cluster_id", cluster.GetId()); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ func DataSource() *schema.Resource {
}

func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
connV2 := meta.(*config.MongoDBClient).AtlasV2
connV220231115 := meta.(*config.MongoDBClient).AtlasV220231115

projectID := d.Get("project_id").(string)
clusterName := d.Get("cluster_name").(string)

backupPolicy, _, err := connV2.CloudBackupsApi.GetBackupSchedule(ctx, projectID, clusterName).Execute()
backupPolicy, _, err := connV220231115.CloudBackupsApi.GetBackupSchedule(ctx, projectID, clusterName).Execute()
if err != nil {
return diag.Errorf(cluster.ErrorSnapshotBackupPolicyRead, clusterName, err)
}
Expand Down
Loading
Loading