From 9f78a9e41e45d86402e634818a53ef989a1bac9b Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Thu, 11 Jul 2024 09:37:52 +0200 Subject: [PATCH] fix: Fixes `disk_iops` attribute for Azure cloud provider in `mongodbatlas_advanced_cluster` resource (#2396) * fix disk_iops in Azure * expand * tests for disk_iops --- .changelog/2396.txt | 3 +++ .../advancedcluster/model_advanced_cluster.go | 8 ++++++-- .../resource_advanced_cluster_test.go | 12 ++++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 .changelog/2396.txt diff --git a/.changelog/2396.txt b/.changelog/2396.txt new file mode 100644 index 0000000000..5bb53f7fda --- /dev/null +++ b/.changelog/2396.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/mongodbatlas_advanced_cluster: Fixes `disk_iops` attribute for Azure cloud provider +``` diff --git a/internal/service/advancedcluster/model_advanced_cluster.go b/internal/service/advancedcluster/model_advanced_cluster.go index 0bd011c764..8f26c1312b 100644 --- a/internal/service/advancedcluster/model_advanced_cluster.go +++ b/internal/service/advancedcluster/model_advanced_cluster.go @@ -634,10 +634,12 @@ func flattenAdvancedReplicationSpecRegionConfigSpec(apiObject *admin.DedicatedHa if len(tfMapObjects) > 0 { tfMapObject := tfMapObjects[0].(map[string]any) - if providerName == "AWS" { + if providerName == constant.AWS || providerName == constant.AZURE { if cast.ToInt64(apiObject.GetDiskIOPS()) > 0 { tfMap["disk_iops"] = apiObject.GetDiskIOPS() } + } + if providerName == constant.AWS { if v, ok := tfMapObject["ebs_volume_type"]; ok && v.(string) != "" { tfMap["ebs_volume_type"] = apiObject.GetEbsVolumeType() } @@ -850,10 +852,12 @@ func expandRegionConfig(tfMap map[string]any) *admin.CloudRegionConfig { func expandRegionConfigSpec(tfList []any, providerName string) *admin.DedicatedHardwareSpec { tfMap, _ := tfList[0].(map[string]any) apiObject := new(admin.DedicatedHardwareSpec) - if providerName == "AWS" { + if providerName == constant.AWS || providerName == constant.AZURE { if v, ok := tfMap["disk_iops"]; ok && v.(int) > 0 { apiObject.DiskIOPS = conversion.Pointer(v.(int)) } + } + if providerName == constant.AWS { if v, ok := tfMap["ebs_volume_type"]; ok { apiObject.EbsVolumeType = conversion.StringPtr(v.(string)) } diff --git a/internal/service/advancedcluster/resource_advanced_cluster_test.go b/internal/service/advancedcluster/resource_advanced_cluster_test.go index 80823e1735..8f72ce42de 100644 --- a/internal/service/advancedcluster/resource_advanced_cluster_test.go +++ b/internal/service/advancedcluster/resource_advanced_cluster_test.go @@ -675,7 +675,9 @@ func checkSingleProvider(projectID, name string) resource.TestCheckFunc { "name": name}, resource.TestCheckResourceAttr(resourceName, "retain_backups_enabled", "true"), resource.TestCheckResourceAttrWith(resourceName, "replication_specs.0.region_configs.0.electable_specs.0.disk_iops", acc.IntGreatThan(0)), - resource.TestCheckResourceAttrWith(dataSourceName, "replication_specs.0.region_configs.0.electable_specs.0.disk_iops", acc.IntGreatThan(0))) + resource.TestCheckResourceAttrWith(resourceName, "replication_specs.0.region_configs.0.analytics_specs.0.disk_iops", acc.IntGreatThan(0)), + resource.TestCheckResourceAttrWith(dataSourceName, "replication_specs.0.region_configs.0.electable_specs.0.disk_iops", acc.IntGreatThan(0)), + resource.TestCheckResourceAttrWith(dataSourceName, "replication_specs.0.region_configs.0.analytics_specs.0.disk_iops", acc.IntGreatThan(0))) } func configIncorrectTypeGobalClusterSelfManagedSharding(projectID, name string) string { @@ -830,7 +832,13 @@ func checkMultiCloudSharded(name string) resource.TestCheckFunc { return checkAggr( []string{"project_id", "replication_specs.#", "replication_specs.0.region_configs.#"}, map[string]string{ - "name": name}) + "name": name}, + resource.TestCheckResourceAttrWith(resourceName, "replication_specs.0.region_configs.0.electable_specs.0.disk_iops", acc.IntGreatThan(0)), + resource.TestCheckResourceAttrWith(resourceName, "replication_specs.0.region_configs.0.analytics_specs.0.disk_iops", acc.IntGreatThan(0)), + resource.TestCheckResourceAttrWith(resourceName, "replication_specs.0.region_configs.1.electable_specs.0.disk_iops", acc.IntGreatThan(0)), + resource.TestCheckResourceAttrWith(dataSourceName, "replication_specs.0.region_configs.0.electable_specs.0.disk_iops", acc.IntGreatThan(0)), + resource.TestCheckResourceAttrWith(dataSourceName, "replication_specs.0.region_configs.0.analytics_specs.0.disk_iops", acc.IntGreatThan(0)), + resource.TestCheckResourceAttrWith(dataSourceName, "replication_specs.0.region_configs.1.electable_specs.0.disk_iops", acc.IntGreatThan(0))) } func configSingleProviderPaused(projectID, clusterName string, paused bool, instanceSize string) string {