databricks / terraform-provider-databricks

Databricks Terraform Provider
https://registry.terraform.io/providers/databricks/databricks/latest
Other
456 stars 393 forks source link

[ISSUE] Issue with `databricks_metastore_assignment ` resource cannot be deleted #2303

Open puneetloya opened 1 year ago

puneetloya commented 1 year ago
Terraform will perform the following actions:

  # module.databricks_metastore.databricks_metastore.this will be destroyed
  - resource "databricks_metastore" "this" {
      - cloud                                             = "aws" -> null
      - created_at                                        = 1683937854812 -> null
      - created_by                                        = "xyz@something.ai" -> null
      - delta_sharing_recipient_token_lifetime_in_seconds = 0 -> null
      - delta_sharing_scope                               = "INTERNAL" -> null
      - force_destroy                                     = true -> null
      - global_metastore_id                               = "aws:us-east-2:<UUID>" -> null
      - id                                                = "<UUID>" -> null
      - name                                              = "my-workspace" -> null
      - owner                                             = "xyz@something.ai" -> null
      - region                                            = "us-east-2" -> null
      - storage_root                                      = "s3://my-workspace-rootbucket20230513001300725800000001/metastore/<UUID>" -> null
      - updated_at                                        = 1683937854812 -> null
      - updated_by                                        = "xyz@something.ai" -> null
    }

  # module.databricks_metastore.databricks_metastore_assignment.this will be destroyed
  - resource "databricks_metastore_assignment" "this" {
      - default_catalog_name = "hive_metastore" -> null
      - id                   = "WS_ID|<UUID>" -> null
      - metastore_id         = "<UUID>" -> null
      - workspace_id         = WS_ID -> null
    }

Plan: 0 to add, 0 to change, 2 to destroy.

error running Destroy: exit status 1

Error: cannot delete metastore assignment: Missing required field: metastore_id

Expected Behavior

Databricks metastore assignment should get deleted

Actual Behavior

Its erroring with

Error: cannot delete metastore assignment: Missing required field: metastore_id

Steps to Reproduce

Terraform and provider versions

Debug Output

Important Factoids

nkvuong commented 1 year ago

@puneetloya could you collect debug logs as suggested in the issue template

puneetloya commented 1 year ago

Logs for the TF run: https://gist.github.com/puneetloya/5a15456b7c84fe0d76723545fe937287

Noticed this in the logs:

2023-05-17T00:38:50.406Z [DEBUG] provider: using plugin: version=5
2023-05-17T00:38:50.868Z [WARN]  ValidateProviderConfig from "provider[\"registry.terraform.io/databricks/databricks\"]" changed the config value, but that value is unused
2023-05-17T00:38:50.875Z [INFO]  provider.terraform-provider-databricks_v1.15.0: Explicit and implicit attributes: host, token: timestamp=2023-05-17T00:38:50.875Z
2023-05-17T00:38:50.890Z [INFO]  Starting apply for module.databricks_metastore.databricks_metastore_assignment.this
2023-05-17T00:38:50.890Z [DEBUG] module.databricks_metastore.databricks_metastore_assignment.this: applying the planned Delete change
2023-05-17T00:38:51.476Z [DEBUG] provider.terraform-provider-databricks_v1.15.0: DELETE /api/2.1/unity-catalog/workspaces/3416610697718891/metastore?metastore_id=bdf99cfb-5e7d-47e9-ba0c-631f149c8fc9
< HTTP/2.0 400 Bad Request
< {
<   "details": [
<     {
<       "@type": "type.googleapis.com/google.rpc.RequestInfo",
<       "request_id": "adb256db-ae26-4b58-92d6-791eced5924e",
<       "serving_data": ""
<     }
<   ],
<   "error_code": "INVALID_PARAMETER_VALUE",
<   "message": "Missing required field: metastore_id"
< }: timestamp=2023-05-17T00:38:51.475Z
2023-05-17T00:38:51.479Z [ERROR] provider.terraform-provider-databricks_v1.15.0: Response contains error diagnostic: @module=sdk.proto diagnostic_detail= diagnostic_severity=ERROR tf_rpc=ApplyResourceChange @caller=/home/runner/work/terraform-provider-databricks/terraform-provider-databricks/vendor/github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/diag/diagnostics.go:55 diagnostic_summary="cannot delete metastore assignment: Missing required field: metastore_id" tf_proto_version=5.3 tf_provider_addr=registry.terraform.io/databricks/databricks tf_req_id=99edf2fe-2fa3-9226-822f-653b92565098 tf_resource_type=databricks_metastore_assignment timestamp=2023-05-17T00:38:51.478Z
2023-05-17T00:38:51.487Z [ERROR] vertex "module.databricks_metastore.databricks_metastore_assignment.this (destroy)" error: cannot delete metastore assignment: Missing required field: metastore_id
╷
│ Error: cannot delete metastore assignment: Missing required field: metastore_id
│
│
╵
2023-05-17T00:38:51.509Z [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = transport is closing"
2023-05-17T00:38:51.525Z [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/databricks/databricks/1.15.0/linux_amd64/terraform-provider-databricks_v1.15.0 pid=457
2023-05-17T00:38:51.525Z [DEBUG] provider: plugin exited
sveerella commented 1 year ago

I do see the same error while deleting the databricks with terraform. We're manually deleting the metastore and also unchecking the checkbox for group entitlements everytime then rerunning the "terraform destroy" to work.

_Error: cannot delete metastore assignment: Missing required field: metastoreid Error: cannot delete entitlements: invalidPath No such attribute with the name : entitlements in the current resource

DEBUG logs

2023-05-18T11:59:19.316-0500 [DEBUG] provider.terraform-provider-databricks_v1.16.0: DELETE /api/2.1/unity-catalog/workspaces/8207462683106352/metastore?metastore_id=1a978eca-7522-482e-898b-145ef923246f < HTTP/2.0 400 Bad Request < { < "details": [ < { < "@type": "type.googleapis.com/google.rpc.RequestInfo", < "request_id": "635d766e-e775-4ebf-9510-6773e0522136", < "serving_data": "" < } < ], < "error_code": "INVALID_PARAMETER_VALUE", < "message": "Missing required field: metastore_id" < }: timestamp=2023-05-18T11:59:19.316-0500 2023-05-18T11:59:19.316-0500 [ERROR] provider.terraform-provider-databricks_v1.16.0: Response contains error diagnostic: diagnostic_detail= tf_provider_addr=registry.terraform.io/databricks/databricks tf_resource_type=databricks_metastore_assignment @caller=/home/runner/work/terraform-provider-databricks/terraform-provider-databricks/vendor/github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/diag/diagnostics.go:55 @module=sdk.proto tf_req_id=b7d28541-22f9-5ddd-ff29-ac4b79a446e7 tf_rpc=ApplyResourceChange diagnostic_severity=ERROR diagnostic_summary="cannot delete metastore assignment: Missing required field: metastore_id" tf_proto_version=5.3 timestamp=2023-05-18T11:59:19.316-0500 2023-05-18T11:59:19.339-0500 [ERROR] vertex "module.coreservices_metastore.databricks_metastore_assignment.this (destroy)" error: cannot delete metastore assignment: Missing required field: metastore_id 2023-05-18T11:59:19.346-0500 [DEBUG] provider.terraform-provider-databricks_v1.16.0: DELETE /api/2.0/accounts/327b1264-2c52-45e4-8742-b3b317a454aa/scim/v2/Users/6783412078989103

nkvuong commented 1 year ago

@puneetloya @sveerella could you upgrade to the latest version of the provider and see if the error goes away

sveerella commented 1 year ago

@nkvuong I see that its deleting the _databricks_metastoreassignment resource now, but its still failing at removing the entitlements for the groups. Below are the debug logs for it. I'm using provider version 1.16.1

Error: cannot delete entitlements: invalidPath No such attribute with the name : entitlements in the current resource

Work around: When I see the entitlements for the group, they're already deselected. I need to enable atleast one entitlement for that group and rerun terraform destroy to delete the resource.

_DEBUG_LOGS:_ 2023-05-19T10:38:00.528-0500 [DEBUG] provider.terraform-provider-databricks_v1.16.1: PATCH /api/2.0/preview/scim/v2/Groups/328896840340603

{ "Operations": [ { "op": "remove", "path": "entitlements", "value": [ { "value": "allow-instance-pool-create" }, { "value": "databricks-sql-access" }, { "value": "workspace-access" } ] } ], "schemas": [ "urn:ietf:params:scim:api:messages:2.0:PatchOp" ] } < HTTP/2.0 400 Bad Request < { < "detail": "No such attribute with the name : entitlements in the current resource", < "schemas": [ < "urn:ietf:params:scim:api:messages:2.0:Error" < ], < "scimType": "invalidPath", < "status": "400" < }: timestamp=2023-05-19T10:38:00.528-0500 2023-05-19T10:38:00.528-0500 [ERROR] provider.terraform-provider-databricks_v1.16.1: Response contains error diagnostic: @module=sdk.proto diagnostic_severity=ERROR diagnostic_summary="cannot delete entitlements: invalidPath No such attribute with the name : entitlements in the current resource" tf_proto_version=5.3 tf_rpc=ApplyResourceChange diagnostic_detail= tf_provider_addr=registry.terraform.io/databricks/databricks tf_req_id=9aa5adc9-213f-f4f5-3dd5-131f9b68995a tf_resource_type=databricks_entitlements @caller=/home/runner/work/terraform-provider-databricks/terraform-provider-databricks/vendor/github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/diag/diagnostics.go:55 timestamp=2023-05-19T10:38:00.528-0500 2023-05-19T10:38:00.550-0500 [ERROR] vertex "databricks_entitlements.group_access (destroy)" error: cannot delete entitlements: invalidPath No such attribute with the name : entitlements in the current resource 2023-05-19T10:38:00.672-0500 [INFO] provider.terraform-provider-aws_v3.49.0_x5: 2023/05/19 10:38:00 [DEBUG] [aws-sdk-go] DEBUG: Response sts/GetCallerIdentity Details: ---[ RESPONSE ]-------------------------------------- HTTP/1.1 200 OK Connection: close Content-Length: 406 Content-Type: text/xml Date: Fri, 19 May 2023 15:38:00 GMT X-Amzn-Requestid: 8955745d-ce6e-41b8-89d5-4c939c51f6db