Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'pause' during cluster and advanced_cluster update #1248

Merged
merged 6 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mongodbatlas/resource_mongodbatlas_advanced_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 51 additions & 1 deletion mongodbatlas/resource_mongodbatlas_advanced_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions mongodbatlas/resource_mongodbatlas_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
48 changes: 47 additions & 1 deletion mongodbatlas/resource_mongodbatlas_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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]
Expand Down