diff --git a/mongodbatlas/resource_mongodbatlas_advanced_cluster.go b/mongodbatlas/resource_mongodbatlas_advanced_cluster.go index 718f8c5e3b..dd5acdb20d 100644 --- a/mongodbatlas/resource_mongodbatlas_advanced_cluster.go +++ b/mongodbatlas/resource_mongodbatlas_advanced_cluster.go @@ -718,6 +718,10 @@ func resourceMongoDBAtlasAdvancedClusterUpdate(ctx context.Context, d *schema.Re cluster.VersionReleaseSystem = d.Get("version_release_system").(string) } + if d.HasChange("paused") && !d.Get("paused").(bool) { + cluster.Paused = pointy.Bool(d.Get("paused").(bool)) + } + timeout := d.Timeout(schema.TimeoutUpdate) // Has changes diff --git a/mongodbatlas/resource_mongodbatlas_advanced_cluster_test.go b/mongodbatlas/resource_mongodbatlas_advanced_cluster_test.go index db840537b9..fb387a293f 100644 --- a/mongodbatlas/resource_mongodbatlas_advanced_cluster_test.go +++ b/mongodbatlas/resource_mongodbatlas_advanced_cluster_test.go @@ -230,7 +230,7 @@ func TestAccClusterAdvancedCluster_multicloudSharded(t *testing.T) { }) } -func TestAccClusterAdvancedCluster_Paused(t *testing.T) { +func TestAccClusterAdvancedCluster_UnpausedToPaused(t *testing.T) { SkipTest(t) var ( cluster matlas.AdvancedCluster @@ -280,6 +280,56 @@ func TestAccClusterAdvancedCluster_Paused(t *testing.T) { }) } +func TestAccClusterAdvancedCluster_PausedToUnpaused(t *testing.T) { + SkipTest(t) + var ( + cluster matlas.AdvancedCluster + resourceName = "mongodbatlas_advanced_cluster.test" + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") + rName = acctest.RandomWithPrefix("test-acc") + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, + ProviderFactories: testAccProviderFactories, + CheckDestroy: testAccCheckMongoDBAtlasAdvancedClusterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccMongoDBAtlasAdvancedClusterConfigSingleProviderPaused(orgID, projectName, rName, true), + Check: resource.ComposeTestCheckFunc( + testAccCheckMongoDBAtlasAdvancedClusterExists(resourceName, &cluster), + testAccCheckMongoDBAtlasAdvancedClusterAttributes(&cluster, rName), + resource.TestCheckResourceAttrSet(resourceName, "project_id"), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttrSet(resourceName, "replication_specs.#"), + resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.region_configs.#"), + resource.TestCheckResourceAttr(resourceName, "paused", "true"), + ), + }, + { + Config: testAccMongoDBAtlasAdvancedClusterConfigSingleProviderPaused(orgID, projectName, rName, false), + Check: resource.ComposeTestCheckFunc( + testAccCheckMongoDBAtlasAdvancedClusterExists(resourceName, &cluster), + testAccCheckMongoDBAtlasAdvancedClusterAttributes(&cluster, rName), + resource.TestCheckResourceAttrSet(resourceName, "project_id"), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttrSet(resourceName, "replication_specs.#"), + resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.region_configs.#"), + resource.TestCheckResourceAttr(resourceName, "paused", "false"), + ), + }, + { + ResourceName: resourceName, + ImportStateIdFunc: testAccCheckMongoDBAtlasClusterImportStateIDFunc(resourceName), + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"replication_specs"}, + }, + }, + }) +} + func TestAccClusterAdvancedCluster_advancedConf(t *testing.T) { var ( cluster matlas.AdvancedCluster diff --git a/mongodbatlas/resource_mongodbatlas_cluster.go b/mongodbatlas/resource_mongodbatlas_cluster.go index 428d8a0da7..9e20c66b89 100644 --- a/mongodbatlas/resource_mongodbatlas_cluster.go +++ b/mongodbatlas/resource_mongodbatlas_cluster.go @@ -932,6 +932,10 @@ func resourceMongoDBAtlasClusterUpdate(ctx context.Context, d *schema.ResourceDa } } + if d.HasChange("paused") && !d.Get("paused").(bool) { + cluster.Paused = pointy.Bool(d.Get("paused").(bool)) + } + timeout := d.Timeout(schema.TimeoutUpdate) if isUpgradeRequired(d) { diff --git a/mongodbatlas/resource_mongodbatlas_cluster_test.go b/mongodbatlas/resource_mongodbatlas_cluster_test.go index da7595ab09..53539bd510 100644 --- a/mongodbatlas/resource_mongodbatlas_cluster_test.go +++ b/mongodbatlas/resource_mongodbatlas_cluster_test.go @@ -1171,7 +1171,7 @@ func TestAccClusterRSCluster_RegionsConfig(t *testing.T) { }) } -func TestAccClusterRSCluster_basicAWS_paused(t *testing.T) { +func TestAccClusterRSCluster_basicAWS_UnpauseToPaused(t *testing.T) { var ( cluster matlas.Cluster resourceName = "mongodbatlas_cluster.test" @@ -1224,6 +1224,52 @@ func TestAccClusterRSCluster_basicAWS_paused(t *testing.T) { }) } +func TestAccClusterRSCluster_basicAWS_PausedToUnpaused(t *testing.T) { + var ( + cluster matlas.Cluster + resourceName = "mongodbatlas_cluster.test" + orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") + projectName = acctest.RandomWithPrefix("test-acc") + name = fmt.Sprintf("test-acc-%s", acctest.RandString(10)) + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheckBasic(t) }, + ProviderFactories: testAccProviderFactories, + CheckDestroy: testAccCheckMongoDBAtlasClusterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccMongoDBAtlasClusterConfigAWSPaused(orgID, projectName, name, true, true), + 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.TestCheckResourceAttrSet(resourceName, "mongo_uri"), + resource.TestCheckResourceAttrSet(resourceName, "replication_specs.#"), + resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.regions_config.#"), + resource.TestCheckResourceAttr(resourceName, "paused", "true"), + ), + }, + { + Config: testAccMongoDBAtlasClusterConfigAWSPaused(orgID, projectName, name, false, false), + 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.TestCheckResourceAttrSet(resourceName, "mongo_uri"), + resource.TestCheckResourceAttrSet(resourceName, "replication_specs.#"), + resource.TestCheckResourceAttrSet(resourceName, "replication_specs.0.regions_config.#"), + resource.TestCheckResourceAttr(resourceName, "paused", "false"), + ), + }, + }, + }) +} + func testAccCheckMongoDBAtlasClusterImportStateIDFunc(resourceName string) resource.ImportStateIdFunc { return func(s *terraform.State) (string, error) { rs, ok := s.RootModule().Resources[resourceName]