Problem
You cannot delete the Unity Catalog metastore using Terraform.
Cause
The default catalog is auto-created with a metastore. As a result, you cannot delete the metastore without first wiping the catalog.
Solution
Set force_destory = true in the databricks_metastore section of the Terraform configuration to delete the metastore and the corresponding catalog.
Example code:
resource "databricks_metastore" "this" {
provider = databricks.workspace
name = "primary"
storage_root = "s3://${aws_s3_bucket.metastore.id}/metastore"
owner = var.unity_admin_group
force_destroy = true
}
resource "databricks_metastore_data_access" "this" {
provider = databricks.workspace
metastore_id = databricks_metastore.this.id
name = aws_iam_role.metastore_data_access.name
aws_iam_role {
role_arn = aws_iam_role.metastore_data_access.arn
}
is_default = true
}
resource "databricks_metastore_assignment" "default_metastore" {
provider = databricks.workspace
for_each = toset(var.databricks_workspace_ids)
workspace_id = each.key
metastore_id = databricks_metastore.this.id
default_catalog_name = "hive_metastore"
}