Skip to content

Commit

Permalink
INTMDB-203: Fix IOPS restriction on NVME clusters (#574)
Browse files Browse the repository at this point in the history
* restrict iops parameter in nvme instance size

* fix lint

* fixes

* fix

* fix
  • Loading branch information
abner-dou committed Oct 1, 2021
1 parent fd9edb3 commit f712520
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 39 deletions.
7 changes: 4 additions & 3 deletions mongodbatlas/resource_mongodbatlas_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func resourceMongoDBAtlasClusterCreate(ctx context.Context, d *schema.ResourceDa

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

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

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

providerSettings.EncryptEBSVolume = pointy.Bool(true)
}

Expand Down
48 changes: 12 additions & 36 deletions mongodbatlas/resource_mongodbatlas_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
matlas "go.mongodb.org/atlas/mongodbatlas"
)

func TestAccResourceMongoDBAtlasCluster_basicAWS(t *testing.T) {
func TestAccResourceMongoDBAtlasCluster_basicAWS_simple(t *testing.T) {
var (
cluster matlas.Cluster
resourceName = "mongodbatlas_cluster.test"
Expand Down Expand Up @@ -61,7 +61,6 @@ func TestAccResourceMongoDBAtlasCluster_basicAWS(t *testing.T) {
}

func TestAccResourceMongoDBAtlasCluster_basicAWS_instanceScale(t *testing.T) {
SkipTest(t) // Skipped for now because of paramater provider_disk_iops breaks the terraform flow
var (
cluster matlas.Cluster
resourceName = "mongodbatlas_cluster.test"
Expand All @@ -75,33 +74,25 @@ func TestAccResourceMongoDBAtlasCluster_basicAWS_instanceScale(t *testing.T) {
CheckDestroy: testAccCheckMongoDBAtlasClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccMongoDBAtlasClusterConfigAWS(projectID, name, true, false),
Config: testAccMongoDBAtlasClusterConfigAWSNVMEInstance(projectID, name, "M40_NVME"),
Check: resource.ComposeTestCheckFunc(
testAccCheckMongoDBAtlasClusterExists(resourceName, &cluster),
testAccCheckMongoDBAtlasClusterAttributes(&cluster, name),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "disk_size_gb", "100"),
resource.TestCheckResourceAttr(resourceName, "pit_enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "provider_instance_size_name", "M40_NVME"),
resource.TestCheckResourceAttrSet(resourceName, "mongo_uri"),
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.#"),
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.regions_config.#"),
),
},
{
Config: testAccMongoDBAtlasClusterConfigAWSNVMEInstance(projectID, name, "true"),
Config: testAccMongoDBAtlasClusterConfigAWSNVMEInstance(projectID, name, "M50_NVME"),
Check: resource.ComposeTestCheckFunc(
testAccCheckMongoDBAtlasClusterExists(resourceName, &cluster),
testAccCheckMongoDBAtlasClusterAttributes(&cluster, name),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "disk_size_gb", "100"),
resource.TestCheckResourceAttr(resourceName, "pit_enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "provider_backup_enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "provider_instance_size_name", "M40_NVME"),
resource.TestCheckResourceAttr(resourceName, "provider_instance_size_name", "M50_NVME"),
resource.TestCheckResourceAttrSet(resourceName, "mongo_uri"),
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.#"),
resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.regions_config.#"),
),
},
},
Expand Down Expand Up @@ -1189,7 +1180,6 @@ func testAccMongoDBAtlasClusterConfigAWS(projectID, name string, backupEnabled,
project_id = "%[1]s"
name = "%[2]s"
disk_size_gb = 100
cluster_type = "REPLICASET"
replication_specs {
num_shards = 1
Expand All @@ -1200,47 +1190,33 @@ func testAccMongoDBAtlasClusterConfigAWS(projectID, name string, backupEnabled,
read_only_nodes = 0
}
}
cloud_backup = %[3]t
pit_enabled = %[3]t
auto_scaling_disk_gb_enabled = %[4]t
mongo_db_major_version = "4.0"
// Provider Settings "block"
provider_name = "AWS"
provider_instance_size_name = "M30"
}
`, projectID, name, backupEnabled, autoDiskGBEnabled)
}

func testAccMongoDBAtlasClusterConfigAWSNVMEInstance(projectID, name, backupEnabled string) string {
func testAccMongoDBAtlasClusterConfigAWSNVMEInstance(projectID, name, instanceName string) string {
return fmt.Sprintf(`
resource "mongodbatlas_cluster" "test" {
project_id = "%[1]s"
name = "%[2]s"
disk_size_gb = 100
cluster_type = "REPLICASET"
replication_specs {
num_shards = 1
regions_config {
region_name = "EU_CENTRAL_1"
electable_nodes = 3
priority = 7
read_only_nodes = 0
}
}
provider_backup_enabled = %[3]s
pit_enabled = %[3]s
mongo_db_major_version = "4.0"
cloud_backup = true
mongo_db_major_version = "4.4"
// Provider Settings "block"
provider_region_name = "US_EAST_1"
provider_name = "AWS"
provider_instance_size_name = "%[3]s"
provider_volume_type = "PROVISIONED"
provider_instance_size_name = "M40_NVME"
}
`, projectID, name, backupEnabled)
`, projectID, name, instanceName)
}

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

0 comments on commit f712520

Please sign in to comment.