Skip to content

Commit f712520

Browse files
authored
INTMDB-203: Fix IOPS restriction on NVME clusters (#574)
* restrict iops parameter in nvme instance size * fix lint * fixes * fix * fix
1 parent fd9edb3 commit f712520

File tree

2 files changed

+16
-39
lines changed

2 files changed

+16
-39
lines changed

mongodbatlas/resource_mongodbatlas_cluster.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ func resourceMongoDBAtlasClusterCreate(ctx context.Context, d *schema.ResourceDa
392392

393393
if providerName != "AWS" {
394394
if _, ok := d.GetOk("provider_disk_iops"); ok {
395-
return diag.FromErr(fmt.Errorf("`provider_disk_iops` shouldn't be set when provider name is `GCP` or `AZURE`"))
395+
return diag.Errorf("`provider_disk_iops` shouldn't be set when provider name is `GCP` or `AZURE`")
396396
}
397397

398398
if _, ok := d.GetOk("provider_volume_type"); ok {
@@ -1107,11 +1107,12 @@ func expandProviderSetting(d *schema.ResourceData) (*matlas.ProviderSettings, er
11071107
}
11081108

11091109
if d.Get("provider_name") == "AWS" {
1110-
// Check if the Provider Disk IOS sets in the Terraform configuration.
1110+
// Check if the Provider Disk IOS sets in the Terraform configuration and if the instance size name is not NVME.
11111111
// If it didn't, the MongoDB Atlas server would set it to the default for the amount of storage.
1112-
if v, ok := d.GetOk("provider_disk_iops"); ok {
1112+
if v, ok := d.GetOk("provider_disk_iops"); ok && !strings.Contains(providerSettings.InstanceSizeName, "NVME") {
11131113
providerSettings.DiskIOPS = pointy.Int64(cast.ToInt64(v))
11141114
}
1115+
11151116
providerSettings.EncryptEBSVolume = pointy.Bool(true)
11161117
}
11171118

mongodbatlas/resource_mongodbatlas_cluster_test.go

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
matlas "go.mongodb.org/atlas/mongodbatlas"
1616
)
1717

18-
func TestAccResourceMongoDBAtlasCluster_basicAWS(t *testing.T) {
18+
func TestAccResourceMongoDBAtlasCluster_basicAWS_simple(t *testing.T) {
1919
var (
2020
cluster matlas.Cluster
2121
resourceName = "mongodbatlas_cluster.test"
@@ -61,7 +61,6 @@ func TestAccResourceMongoDBAtlasCluster_basicAWS(t *testing.T) {
6161
}
6262

6363
func TestAccResourceMongoDBAtlasCluster_basicAWS_instanceScale(t *testing.T) {
64-
SkipTest(t) // Skipped for now because of paramater provider_disk_iops breaks the terraform flow
6564
var (
6665
cluster matlas.Cluster
6766
resourceName = "mongodbatlas_cluster.test"
@@ -75,33 +74,25 @@ func TestAccResourceMongoDBAtlasCluster_basicAWS_instanceScale(t *testing.T) {
7574
CheckDestroy: testAccCheckMongoDBAtlasClusterDestroy,
7675
Steps: []resource.TestStep{
7776
{
78-
Config: testAccMongoDBAtlasClusterConfigAWS(projectID, name, true, false),
77+
Config: testAccMongoDBAtlasClusterConfigAWSNVMEInstance(projectID, name, "M40_NVME"),
7978
Check: resource.ComposeTestCheckFunc(
8079
testAccCheckMongoDBAtlasClusterExists(resourceName, &cluster),
8180
testAccCheckMongoDBAtlasClusterAttributes(&cluster, name),
8281
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
8382
resource.TestCheckResourceAttr(resourceName, "name", name),
84-
resource.TestCheckResourceAttr(resourceName, "disk_size_gb", "100"),
85-
resource.TestCheckResourceAttr(resourceName, "pit_enabled", "true"),
83+
resource.TestCheckResourceAttr(resourceName, "provider_instance_size_name", "M40_NVME"),
8684
resource.TestCheckResourceAttrSet(resourceName, "mongo_uri"),
87-
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.#"),
88-
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.regions_config.#"),
8985
),
9086
},
9187
{
92-
Config: testAccMongoDBAtlasClusterConfigAWSNVMEInstance(projectID, name, "true"),
88+
Config: testAccMongoDBAtlasClusterConfigAWSNVMEInstance(projectID, name, "M50_NVME"),
9389
Check: resource.ComposeTestCheckFunc(
9490
testAccCheckMongoDBAtlasClusterExists(resourceName, &cluster),
9591
testAccCheckMongoDBAtlasClusterAttributes(&cluster, name),
9692
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
9793
resource.TestCheckResourceAttr(resourceName, "name", name),
98-
resource.TestCheckResourceAttr(resourceName, "disk_size_gb", "100"),
99-
resource.TestCheckResourceAttr(resourceName, "pit_enabled", "true"),
100-
resource.TestCheckResourceAttr(resourceName, "provider_backup_enabled", "true"),
101-
resource.TestCheckResourceAttr(resourceName, "provider_instance_size_name", "M40_NVME"),
94+
resource.TestCheckResourceAttr(resourceName, "provider_instance_size_name", "M50_NVME"),
10295
resource.TestCheckResourceAttrSet(resourceName, "mongo_uri"),
103-
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.#"),
104-
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.regions_config.#"),
10596
),
10697
},
10798
},
@@ -1189,7 +1180,6 @@ func testAccMongoDBAtlasClusterConfigAWS(projectID, name string, backupEnabled,
11891180
project_id = "%[1]s"
11901181
name = "%[2]s"
11911182
disk_size_gb = 100
1192-
11931183
cluster_type = "REPLICASET"
11941184
replication_specs {
11951185
num_shards = 1
@@ -1200,47 +1190,33 @@ func testAccMongoDBAtlasClusterConfigAWS(projectID, name string, backupEnabled,
12001190
read_only_nodes = 0
12011191
}
12021192
}
1203-
12041193
cloud_backup = %[3]t
12051194
pit_enabled = %[3]t
12061195
auto_scaling_disk_gb_enabled = %[4]t
12071196
mongo_db_major_version = "4.0"
1208-
12091197
// Provider Settings "block"
1198+
12101199
provider_name = "AWS"
12111200
provider_instance_size_name = "M30"
12121201
}
12131202
`, projectID, name, backupEnabled, autoDiskGBEnabled)
12141203
}
12151204

1216-
func testAccMongoDBAtlasClusterConfigAWSNVMEInstance(projectID, name, backupEnabled string) string {
1205+
func testAccMongoDBAtlasClusterConfigAWSNVMEInstance(projectID, name, instanceName string) string {
12171206
return fmt.Sprintf(`
12181207
resource "mongodbatlas_cluster" "test" {
12191208
project_id = "%[1]s"
12201209
name = "%[2]s"
1221-
disk_size_gb = 100
1222-
1223-
cluster_type = "REPLICASET"
1224-
replication_specs {
1225-
num_shards = 1
1226-
regions_config {
1227-
region_name = "EU_CENTRAL_1"
1228-
electable_nodes = 3
1229-
priority = 7
1230-
read_only_nodes = 0
1231-
}
1232-
}
1233-
1234-
provider_backup_enabled = %[3]s
1235-
pit_enabled = %[3]s
1236-
mongo_db_major_version = "4.0"
12371210
1211+
cloud_backup = true
1212+
mongo_db_major_version = "4.4"
12381213
// Provider Settings "block"
1214+
provider_region_name = "US_EAST_1"
12391215
provider_name = "AWS"
1216+
provider_instance_size_name = "%[3]s"
12401217
provider_volume_type = "PROVISIONED"
1241-
provider_instance_size_name = "M40_NVME"
12421218
}
1243-
`, projectID, name, backupEnabled)
1219+
`, projectID, name, instanceName)
12441220
}
12451221

12461222
func testAccMongoDBAtlasClusterConfigAdvancedConf(projectID, name, autoscalingEnabled string, p *matlas.ProcessArgs) string {

0 commit comments

Comments
 (0)