From 037911c2e716e1b2557ff06310b4009ba4c16ab3 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Wed, 20 Mar 2024 13:48:45 +0530 Subject: [PATCH] delete Operation for directory service --- .../resource_nutanix_directory_services_v2.go | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/nutanix/services/v2/iam/resource_nutanix_directory_services_v2.go b/nutanix/services/v2/iam/resource_nutanix_directory_services_v2.go index 1487dc6f0..014c36007 100644 --- a/nutanix/services/v2/iam/resource_nutanix_directory_services_v2.go +++ b/nutanix/services/v2/iam/resource_nutanix_directory_services_v2.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" import1 "github.com/nutanix-core/ntnx-api-golang-sdk-internal/iam-go-client/v16/models/iam/v4/authn" + errResp "github.com/nutanix-core/ntnx-api-golang-sdk-internal/iam-go-client/v16/models/iam/v4/error" conns "github.com/terraform-providers/terraform-provider-nutanix/nutanix" "github.com/terraform-providers/terraform-provider-nutanix/utils" @@ -308,6 +309,26 @@ func ResourceNutanixDirectoryServicesV4Update(ctx context.Context, d *schema.Res } func ResourceNutanixDirectoryServicesV4Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + conn := meta.(*conns.Client).IamAPI + + resp, err := conn.DirectoryServiceAPIInstance.DeleteDirectoryServiceById(utils.StringPtr(d.Id())) + if err != nil { + var errordata map[string]interface{} + e := json.Unmarshal([]byte(err.Error()), &errordata) + if e != nil { + return diag.FromErr(e) + } + data := errordata["data"].(map[string]interface{}) + errorList := data["error"].([]interface{}) + errorMessage := errorList[0].(map[string]interface{}) + return diag.Errorf("error while deleting directory services : %v", errorMessage["message"]) + } + + getResp := resp.Data.GetValue().(errResp.ErrorResponse) + + if getResp.Error != nil { + fmt.Println("Directory Services deleted successfully.") + } return nil }