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

feat: Ensures asymmetric auto-scaling is not defined in the cluster when using the old sharding configuration in mongodbatlas_advanced_cluster #2836

Merged
merged 5 commits into from
Dec 2, 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
3 changes: 3 additions & 0 deletions .changelog/2836.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
oarbusi marked this conversation as resolved.
Show resolved Hide resolved
resource/mongodbatlas_advanced_cluster: Adjusts create operation to support cluster tier auto scaling per shard.
```
155 changes: 155 additions & 0 deletions internal/service/advancedcluster/model_sdk_version_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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"
Expand Down Expand Up @@ -324,3 +325,157 @@ func convertClusterDescToLatestExcludeRepSpecs(oldClusterDesc *admin20240530.Adv
Labels: convertLabelsToLatest(oldClusterDesc.Labels),
}
}

func ConvertClusterDescription20241023to20240805(clusterDescription *admin.ClusterDescription20240805) *admin20240805.ClusterDescription20240805 {
return &admin20240805.ClusterDescription20240805{
Name: clusterDescription.Name,
ClusterType: clusterDescription.ClusterType,
ReplicationSpecs: convertReplicationSpecs20241023to20240805(clusterDescription.ReplicationSpecs),
BackupEnabled: clusterDescription.BackupEnabled,
BiConnector: convertBiConnector20241023to20240805(clusterDescription.BiConnector),
EncryptionAtRestProvider: clusterDescription.EncryptionAtRestProvider,
Labels: convertLabels20241023to20240805(clusterDescription.Labels),
Tags: convertTag20241023to20240805(clusterDescription.Tags),
MongoDBMajorVersion: clusterDescription.MongoDBMajorVersion,
PitEnabled: clusterDescription.PitEnabled,
RootCertType: clusterDescription.RootCertType,
TerminationProtectionEnabled: clusterDescription.TerminationProtectionEnabled,
VersionReleaseSystem: clusterDescription.VersionReleaseSystem,
GlobalClusterSelfManagedSharding: clusterDescription.GlobalClusterSelfManagedSharding,
ReplicaSetScalingStrategy: clusterDescription.ReplicaSetScalingStrategy,
RedactClientLogData: clusterDescription.RedactClientLogData,
ConfigServerManagementMode: clusterDescription.ConfigServerManagementMode,
}
}

func convertReplicationSpecs20241023to20240805(replicationSpecs *[]admin.ReplicationSpec20240805) *[]admin20240805.ReplicationSpec20240805 {
if replicationSpecs == nil {
return nil
}
result := make([]admin20240805.ReplicationSpec20240805, len(*replicationSpecs))
for i, replicationSpec := range *replicationSpecs {
result[i] = admin20240805.ReplicationSpec20240805{
Id: replicationSpec.Id,
ZoneName: replicationSpec.ZoneName,
ZoneId: replicationSpec.ZoneId,
RegionConfigs: convertCloudRegionConfig20241023to20240805(replicationSpec.RegionConfigs),
}
}
return &result
}

func convertCloudRegionConfig20241023to20240805(cloudRegionConfig *[]admin.CloudRegionConfig20240805) *[]admin20240805.CloudRegionConfig20240805 {
if cloudRegionConfig == nil {
return nil
}
result := make([]admin20240805.CloudRegionConfig20240805, len(*cloudRegionConfig))
for i, regionConfig := range *cloudRegionConfig {
result[i] = admin20240805.CloudRegionConfig20240805{
ProviderName: regionConfig.ProviderName,
RegionName: regionConfig.RegionName,
BackingProviderName: regionConfig.BackingProviderName,
Priority: regionConfig.Priority,
ElectableSpecs: convertHardwareSpec20241023to20240805(regionConfig.ElectableSpecs),
ReadOnlySpecs: convertDedicatedHardwareSpec20241023to20240805(regionConfig.ReadOnlySpecs),
AnalyticsSpecs: convertDedicatedHardwareSpec20241023to20240805(regionConfig.AnalyticsSpecs),
AutoScaling: convertAdvancedAutoScalingSettings20241023to20240805(regionConfig.AutoScaling),
AnalyticsAutoScaling: convertAdvancedAutoScalingSettings20241023to20240805(regionConfig.AnalyticsAutoScaling),
}
}
return &result
}

func convertAdvancedAutoScalingSettings20241023to20240805(advancedAutoScalingSettings *admin.AdvancedAutoScalingSettings) *admin20240805.AdvancedAutoScalingSettings {
if advancedAutoScalingSettings == nil {
return nil
}
return &admin20240805.AdvancedAutoScalingSettings{
Compute: convertAdvancedComputeAutoScaling20241023to20240805(advancedAutoScalingSettings.Compute),
DiskGB: convertDiskGBAutoScaling20241023to20240805(advancedAutoScalingSettings.DiskGB),
}
}

func convertDiskGBAutoScaling20241023to20240805(diskGBAutoScaling *admin.DiskGBAutoScaling) *admin20240805.DiskGBAutoScaling {
if diskGBAutoScaling == nil {
return nil
}
return &admin20240805.DiskGBAutoScaling{
Enabled: diskGBAutoScaling.Enabled,
}
}

func convertAdvancedComputeAutoScaling20241023to20240805(advancedComputeAutoScaling *admin.AdvancedComputeAutoScaling) *admin20240805.AdvancedComputeAutoScaling {
if advancedComputeAutoScaling == nil {
return nil
}
return &admin20240805.AdvancedComputeAutoScaling{
Enabled: advancedComputeAutoScaling.Enabled,
MaxInstanceSize: advancedComputeAutoScaling.MaxInstanceSize,
MinInstanceSize: advancedComputeAutoScaling.MinInstanceSize,
ScaleDownEnabled: advancedComputeAutoScaling.ScaleDownEnabled,
}
}

func convertHardwareSpec20241023to20240805(hardwareSpec *admin.HardwareSpec20240805) *admin20240805.HardwareSpec20240805 {
if hardwareSpec == nil {
return nil
}
return &admin20240805.HardwareSpec20240805{
DiskSizeGB: hardwareSpec.DiskSizeGB,
NodeCount: hardwareSpec.NodeCount,
DiskIOPS: hardwareSpec.DiskIOPS,
EbsVolumeType: hardwareSpec.EbsVolumeType,
InstanceSize: hardwareSpec.InstanceSize,
}
}

func convertDedicatedHardwareSpec20241023to20240805(hardwareSpec *admin.DedicatedHardwareSpec20240805) *admin20240805.DedicatedHardwareSpec20240805 {
if hardwareSpec == nil {
return nil
}
return &admin20240805.DedicatedHardwareSpec20240805{
DiskSizeGB: hardwareSpec.DiskSizeGB,
NodeCount: hardwareSpec.NodeCount,
DiskIOPS: hardwareSpec.DiskIOPS,
EbsVolumeType: hardwareSpec.EbsVolumeType,
InstanceSize: hardwareSpec.InstanceSize,
}
}

func convertBiConnector20241023to20240805(biConnector *admin.BiConnector) *admin20240805.BiConnector {
if biConnector == nil {
return nil
}
return &admin20240805.BiConnector{
ReadPreference: biConnector.ReadPreference,
Enabled: biConnector.Enabled,
}
}

func convertLabels20241023to20240805(labels *[]admin.ComponentLabel) *[]admin20240805.ComponentLabel {
if labels == nil {
return &[]admin20240805.ComponentLabel{}
}
result := make([]admin20240805.ComponentLabel, len(*labels))
for i, label := range *labels {
result[i] = admin20240805.ComponentLabel{
Key: label.Key,
Value: label.Value,
}
}
return &result
}

func convertTag20241023to20240805(tags *[]admin.ResourceTag) *[]admin20240805.ResourceTag {
if tags == nil {
return &[]admin20240805.ResourceTag{}
}
result := make([]admin20240805.ResourceTag, len(*tags))
for i, tag := range *tags {
result[i] = admin20240805.ResourceTag{
Key: tag.Key,
Value: tag.Value,
}
}
return &result
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
package advancedcluster_test

import (
"testing"

"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
"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 TestConvertClusterDescription20241023to20240805(t *testing.T) {
var (
clusterName = "clusterName"
clusterType = "REPLICASET"
earProvider = "AWS"
booleanValue = true
mongoDBMajorVersion = "7.0"
rootCertType = "rootCertType"
replicaSetScalingStrategy = "WORKLOAD_TYPE"
configServerManagementMode = "ATLAS_MANAGED"
readPreference = "primary"
zoneName = "z1"
id = "id1"
regionConfigProvider = "AWS"
region = "EU_WEST_1"
priority = 7
instanceSize = "M10"
nodeCount = 3
diskSizeGB = 30.3
ebsVolumeType = "STANDARD"
diskIOPS = 100
)
testCases := []struct {
input *admin.ClusterDescription20240805
expectedOutput *admin20240805.ClusterDescription20240805
name string
}{
{
name: "Converts cluster description from 20241023 to 20240805",
input: &admin.ClusterDescription20240805{
Name: conversion.StringPtr(clusterName),
ClusterType: conversion.StringPtr(clusterType),
ReplicationSpecs: &[]admin.ReplicationSpec20240805{
{
Id: conversion.StringPtr(id),
ZoneName: conversion.StringPtr(zoneName),
RegionConfigs: &[]admin.CloudRegionConfig20240805{
{
ProviderName: conversion.StringPtr(regionConfigProvider),
RegionName: conversion.StringPtr(region),
BackingProviderName: conversion.StringPtr(regionConfigProvider),
Priority: conversion.IntPtr(priority),
AnalyticsSpecs: &admin.DedicatedHardwareSpec20240805{
InstanceSize: conversion.StringPtr(instanceSize),
NodeCount: conversion.IntPtr(nodeCount),
DiskSizeGB: conversion.Pointer(diskSizeGB),
EbsVolumeType: conversion.StringPtr(ebsVolumeType),
DiskIOPS: conversion.IntPtr(diskIOPS),
},
ElectableSpecs: &admin.HardwareSpec20240805{
InstanceSize: conversion.StringPtr(instanceSize),
NodeCount: conversion.IntPtr(nodeCount),
DiskSizeGB: conversion.Pointer(diskSizeGB),
EbsVolumeType: conversion.StringPtr(ebsVolumeType),
DiskIOPS: conversion.IntPtr(diskIOPS),
},
AutoScaling: &admin.AdvancedAutoScalingSettings{
Compute: &admin.AdvancedComputeAutoScaling{
Enabled: conversion.Pointer(booleanValue),
MaxInstanceSize: conversion.Pointer(instanceSize),
MinInstanceSize: conversion.Pointer(instanceSize),
ScaleDownEnabled: conversion.Pointer(booleanValue),
},
DiskGB: &admin.DiskGBAutoScaling{
Enabled: conversion.Pointer(booleanValue),
},
},
},
},
},
},
BackupEnabled: conversion.Pointer(booleanValue),
BiConnector: &admin.BiConnector{
Enabled: conversion.Pointer(booleanValue),
ReadPreference: conversion.StringPtr(readPreference),
},
EncryptionAtRestProvider: conversion.StringPtr(earProvider),
Labels: &[]admin.ComponentLabel{
{Key: conversion.StringPtr("key1"), Value: conversion.StringPtr("value1")},
{Key: conversion.StringPtr("key2"), Value: conversion.StringPtr("value2")},
},
Tags: &[]admin.ResourceTag{
{Key: "key1", Value: "value1"},
{Key: "key2", Value: "value2"},
},
MongoDBMajorVersion: conversion.StringPtr(mongoDBMajorVersion),
PitEnabled: conversion.Pointer(booleanValue),
RootCertType: conversion.StringPtr(rootCertType),
TerminationProtectionEnabled: conversion.Pointer(booleanValue),
VersionReleaseSystem: conversion.StringPtr(""),
GlobalClusterSelfManagedSharding: conversion.Pointer(booleanValue),
ReplicaSetScalingStrategy: conversion.StringPtr(replicaSetScalingStrategy),
RedactClientLogData: conversion.Pointer(booleanValue),
ConfigServerManagementMode: conversion.StringPtr(configServerManagementMode),
},
expectedOutput: &admin20240805.ClusterDescription20240805{
Name: conversion.StringPtr(clusterName),
ClusterType: conversion.StringPtr(clusterType),
ReplicationSpecs: &[]admin20240805.ReplicationSpec20240805{
{
Id: conversion.StringPtr(id),
ZoneName: conversion.StringPtr(zoneName),
RegionConfigs: &[]admin20240805.CloudRegionConfig20240805{
{
ProviderName: conversion.StringPtr(regionConfigProvider),
RegionName: conversion.StringPtr(region),
BackingProviderName: conversion.StringPtr(regionConfigProvider),
Priority: conversion.IntPtr(priority),
AnalyticsSpecs: &admin20240805.DedicatedHardwareSpec20240805{
InstanceSize: conversion.StringPtr(instanceSize),
NodeCount: conversion.IntPtr(nodeCount),
DiskSizeGB: conversion.Pointer(diskSizeGB),
EbsVolumeType: conversion.StringPtr(ebsVolumeType),
DiskIOPS: conversion.IntPtr(diskIOPS),
},
ElectableSpecs: &admin20240805.HardwareSpec20240805{
InstanceSize: conversion.StringPtr(instanceSize),
NodeCount: conversion.IntPtr(nodeCount),
DiskSizeGB: conversion.Pointer(diskSizeGB),
EbsVolumeType: conversion.StringPtr(ebsVolumeType),
DiskIOPS: conversion.IntPtr(diskIOPS),
},
AutoScaling: &admin20240805.AdvancedAutoScalingSettings{
Compute: &admin20240805.AdvancedComputeAutoScaling{
Enabled: conversion.Pointer(booleanValue),
MaxInstanceSize: conversion.Pointer(instanceSize),
MinInstanceSize: conversion.Pointer(instanceSize),
ScaleDownEnabled: conversion.Pointer(booleanValue),
},
DiskGB: &admin20240805.DiskGBAutoScaling{
Enabled: conversion.Pointer(booleanValue),
},
},
},
},
},
},
BackupEnabled: conversion.Pointer(booleanValue),
BiConnector: &admin20240805.BiConnector{
Enabled: conversion.Pointer(booleanValue),
ReadPreference: conversion.StringPtr(readPreference),
},
EncryptionAtRestProvider: conversion.StringPtr(earProvider),
Labels: &[]admin20240805.ComponentLabel{
{Key: conversion.StringPtr("key1"), Value: conversion.StringPtr("value1")},
{Key: conversion.StringPtr("key2"), Value: conversion.StringPtr("value2")},
},
Tags: &[]admin20240805.ResourceTag{
{Key: "key1", Value: "value1"},
{Key: "key2", Value: "value2"},
},
MongoDBMajorVersion: conversion.StringPtr(mongoDBMajorVersion),
PitEnabled: conversion.Pointer(booleanValue),
RootCertType: conversion.StringPtr(rootCertType),
TerminationProtectionEnabled: conversion.Pointer(booleanValue),
VersionReleaseSystem: conversion.StringPtr(""),
GlobalClusterSelfManagedSharding: conversion.Pointer(booleanValue),
ReplicaSetScalingStrategy: conversion.StringPtr(replicaSetScalingStrategy),
RedactClientLogData: conversion.Pointer(booleanValue),
ConfigServerManagementMode: conversion.StringPtr(configServerManagementMode),
},
},
{
name: "Converts cluster description from 20241023 to 20240805 with nil values",
input: &admin.ClusterDescription20240805{},
expectedOutput: &admin20240805.ClusterDescription20240805{
ReplicationSpecs: nil,
BiConnector: nil,
Labels: &[]admin20240805.ComponentLabel{},
Tags: &[]admin20240805.ResourceTag{},
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := advancedcluster.ConvertClusterDescription20241023to20240805(tc.input)
assert.Equal(t, tc.expectedOutput, result)
})
}
}
Loading
Loading