Skip to content

Commit

Permalink
fix: Fixes disk_iops attribute for Azure cloud provider in `mongodb…
Browse files Browse the repository at this point in the history
…atlas_advanced_cluster` resource (#2396)

* fix disk_iops in Azure

* expand

* tests for disk_iops
  • Loading branch information
lantoli authored Jul 11, 2024
1 parent ec5424b commit 9f78a9e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/2396.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/mongodbatlas_advanced_cluster: Fixes `disk_iops` attribute for Azure cloud provider
```
8 changes: 6 additions & 2 deletions internal/service/advancedcluster/model_advanced_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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))
}
Expand Down
12 changes: 10 additions & 2 deletions internal/service/advancedcluster/resource_advanced_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 9f78a9e

Please sign in to comment.