diff --git a/nutanix/services/prismv2/resource_nutanix_unregister_cluster_v2.go b/nutanix/services/prismv2/resource_nutanix_unregister_cluster_v2.go index 8e3a7068..60d56a7b 100644 --- a/nutanix/services/prismv2/resource_nutanix_unregister_cluster_v2.go +++ b/nutanix/services/prismv2/resource_nutanix_unregister_cluster_v2.go @@ -52,6 +52,9 @@ func ResourceNutanixUnregisterClusterV2Create(ctx context.Context, d *schema.Res ExtId: utils.StringPtr(extID.(string)), } + aJSON, _ := json.MarshalIndent(body, "", " ") + log.Printf("[DEBUG] Unregister Cluster Request Body: %s", string(aJSON)) + resp, err := conn.DomainManagerAPIInstance.Unregister(utils.StringPtr(pcExtID.(string)), &body, args) if err != nil { @@ -80,7 +83,7 @@ func ResourceNutanixUnregisterClusterV2Create(ctx context.Context, d *schema.Res } rUUID := resourceUUID.Data.GetValue().(config.Task) - aJSON, _ := json.MarshalIndent(rUUID, "", " ") + aJSON, _ = json.MarshalIndent(rUUID, "", " ") log.Printf("[DEBUG] Unregister Cluster Task Details: %s", string(aJSON)) uuid := rUUID.EntitiesAffected[0].ExtId diff --git a/nutanix/services/prismv2/resource_nutanix_unregister_cluster_v2_test.go b/nutanix/services/prismv2/resource_nutanix_unregister_cluster_v2_test.go new file mode 100644 index 00000000..26572da8 --- /dev/null +++ b/nutanix/services/prismv2/resource_nutanix_unregister_cluster_v2_test.go @@ -0,0 +1,57 @@ +package prismv2_test + +import ( + "encoding/json" + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + acc "github.com/terraform-providers/terraform-provider-nutanix/nutanix/acctest" +) + +const resourceNameUnregisterCluster = "nutanix_unregister_cluster_v2.test" + +func TestAccV2NutanixUnregisterClusterResource_Basic(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccUnregisterClusterResourceConfig(), + Check: resource.ComposeTestCheckFunc( + func(s *terraform.State) error { + aJson, _ := json.MarshalIndent(s.RootModule().Resources[resourceNameUnregisterCluster].Primary.Attributes, "", " ") + fmt.Println("############################################") + fmt.Println(fmt.Sprintf("Resource Attributes: \n%v", string(aJson))) + fmt.Println("############################################") + + return nil + }, + resource.TestCheckResourceAttrSet(resourceNameUnregisterCluster, "pc_ext_id"), + resource.TestCheckResourceAttrSet(resourceNameUnregisterCluster, "ext_id"), + ), + }, + }, + }) +} + +func testAccUnregisterClusterResourceConfig() string { + return fmt.Sprintf(` +data "nutanix_clusters_v2" "clusters" {} + +locals { + pcExtID = [ + for cluster in data.nutanix_clusters_v2.clusters.cluster_entities : + cluster.ext_id if cluster.config[0].cluster_function[0] == "PRISM_CENTRAL" + ][0] + config = (jsondecode(file("%[1]s"))) + prism = local.config.prism +} + +resource "nutanix_unregister_cluster_v2" "test"{ + pc_ext_id = local.pcExtID + ext_id = local.prism.cluster_ext_id +} +`, filepath) +} diff --git a/test_config_v2.json b/test_config_v2.json index 6ba359cf..bc1f96ff 100644 --- a/test_config_v2.json +++ b/test_config_v2.json @@ -243,6 +243,7 @@ "domain_manager_ext_id": "" }, "prism": { + "cluster_ext_id": "", "bucket": { "name": "", "region": "",