Skip to content

Commit 833caf6

Browse files
author
Edgar López
committed
fix: added validation for autoscaling compute enabled and when true add the parameter autoscaling to request and its test
1 parent 70b45e3 commit 833caf6

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

mongodbatlas/resource_mongodbatlas_cluster.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,14 +1025,15 @@ func getInstanceSizeToInt(instanceSize string) int {
10251025

10261026
func expandProviderSetting(d *schema.ResourceData) (*matlas.ProviderSettings, error) {
10271027
var (
1028-
region, _ = valRegion(d.Get("provider_region_name"))
1029-
minInstanceSize = getInstanceSizeToInt(d.Get("provider_auto_scaling_compute_min_instance_size").(string))
1030-
maxInstanceSize = getInstanceSizeToInt(d.Get("provider_auto_scaling_compute_max_instance_size").(string))
1031-
instanceSize = getInstanceSizeToInt(d.Get("provider_instance_size_name").(string))
1032-
compute *matlas.Compute
1028+
region, _ = valRegion(d.Get("provider_region_name"))
1029+
minInstanceSize = getInstanceSizeToInt(d.Get("provider_auto_scaling_compute_min_instance_size").(string))
1030+
maxInstanceSize = getInstanceSizeToInt(d.Get("provider_auto_scaling_compute_max_instance_size").(string))
1031+
instanceSize = getInstanceSizeToInt(d.Get("provider_instance_size_name").(string))
1032+
compute *matlas.Compute
1033+
autoScalingEnabled = d.Get("auto_scaling_compute_enabled").(bool)
10331034
)
10341035

1035-
if minInstanceSize != 0 {
1036+
if minInstanceSize != 0 && autoScalingEnabled {
10361037
if instanceSize < minInstanceSize {
10371038
return nil, fmt.Errorf("`provider_auto_scaling_compute_min_instance_size` must be lower than `provider_instance_size_name`")
10381039
}
@@ -1042,7 +1043,7 @@ func expandProviderSetting(d *schema.ResourceData) (*matlas.ProviderSettings, er
10421043
}
10431044
}
10441045

1045-
if maxInstanceSize != 0 {
1046+
if maxInstanceSize != 0 && autoScalingEnabled {
10461047
if instanceSize > maxInstanceSize {
10471048
return nil, fmt.Errorf("`provider_auto_scaling_compute_max_instance_size` must be higher than `provider_instance_size_name`")
10481049
}
@@ -1060,7 +1061,10 @@ func expandProviderSetting(d *schema.ResourceData) (*matlas.ProviderSettings, er
10601061
RegionName: region,
10611062
VolumeType: cast.ToString(d.Get("provider_volume_type")),
10621063
DiskTypeName: cast.ToString(d.Get("provider_disk_type_name")),
1063-
AutoScaling: &matlas.AutoScaling{Compute: compute},
1064+
}
1065+
1066+
if autoScalingEnabled {
1067+
providerSettings.AutoScaling = &matlas.AutoScaling{Compute: compute}
10641068
}
10651069

10661070
if d.Get("provider_name") == "AWS" {

mongodbatlas/resource_mongodbatlas_cluster_test.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ func TestAccResourceMongoDBAtlasCluster_tenant(t *testing.T) {
797797
CheckDestroy: testAccCheckMongoDBAtlasClusterDestroy,
798798
Steps: []resource.TestStep{
799799
{
800-
Config: testAccMongoDBAtlasClusterConfigTenant(projectID, name, "M2"),
800+
Config: testAccMongoDBAtlasClusterConfigTenant(projectID, name, "M2", "2"),
801801
Check: resource.ComposeTestCheckFunc(
802802
testAccCheckMongoDBAtlasClusterExists(resourceName, &cluster),
803803
testAccCheckMongoDBAtlasClusterAttributes(&cluster, name),
@@ -834,7 +834,7 @@ func TestAccResourceMongoDBAtlasCluster_tenant_m5(t *testing.T) {
834834
CheckDestroy: testAccCheckMongoDBAtlasClusterDestroy,
835835
Steps: []resource.TestStep{
836836
{
837-
Config: testAccMongoDBAtlasClusterConfigTenant(projectID, name, "M5"),
837+
Config: testAccMongoDBAtlasClusterConfigTenant(projectID, name, "M5", "5"),
838838
Check: resource.ComposeTestCheckFunc(
839839
testAccCheckMongoDBAtlasClusterExists(resourceName, &cluster),
840840
testAccCheckMongoDBAtlasClusterAttributes(&cluster, name),
@@ -1140,20 +1140,24 @@ func testAccMongoDBAtlasClusterConfigGlobal(projectID, name, backupEnabled strin
11401140
`, projectID, name, backupEnabled)
11411141
}
11421142

1143-
func testAccMongoDBAtlasClusterConfigTenant(projectID, name, instanceSize string) string {
1143+
func testAccMongoDBAtlasClusterConfigTenant(projectID, name, instanceSize, diskSize string) string {
11441144
return fmt.Sprintf(`
11451145
resource "mongodbatlas_cluster" "tenant" {
11461146
project_id = "%s"
11471147
name = "%s"
11481148
11491149
provider_name = "TENANT"
11501150
backing_provider_name = "AWS"
1151-
provider_region_name = "EU_CENTRAL_1"
1151+
provider_region_name = "US_EAST_1"
1152+
//M2 must be 2, M5 must be 5
1153+
disk_size_gb = "%s"
11521154
11531155
provider_instance_size_name = "%s"
1156+
//These must be the following values
1157+
mongo_db_major_version = "4.2"
11541158
auto_scaling_disk_gb_enabled = false
11551159
}
1156-
`, projectID, name, instanceSize)
1160+
`, projectID, name, diskSize, instanceSize)
11571161
}
11581162

11591163
func testAccMongoDBAtlasClusterConfigTenantUpdated(projectID, name string) string {

0 commit comments

Comments
 (0)