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_sql_table` resource #4250

Open beccar97 opened 1 day ago

beccar97 commented 1 day ago

Configuration

Create any view using the databricks_sql_table resource which includes a column comment, and then change this comment and try to re-apply terraform.

resource "databricks_sql_table" "my_view" {
  cluster_id = local.cluster_id

  name = "view"
  catalog_name = databricks_catalog.this.name
  schema_name = databricks_schema.this.name
  table_type = "VIEW"

  view_definition = format("SELECT name FROM %s WHERE id == 1", databricks_sql_table.table.id)

  comment = "A view managed by terraform"

  column {
     name = "name"
     comment = "This comment is changed after the view is created"
  }
}

Expected Behavior

When changing a column comment on a view and running terraform apply, the view would be successfully updated with the new comment.

Actual Behavior

When applying the change to a column comment, terraform tries to modify the resource and fails with an error like:

Error: cannot update sql table: cannot execute ALTER VIEW `my_catalog`.`my_schema`.`my_view` ALTER COLUMN `name` COMMENT 'An updated column comment.': [PARSE_SYNTAX_ERROR] Syntax error at or near 'ALTER'.(line 1, pos 72)

Steps to Reproduce

  1. Define a view in terraform which includes a column comment and run terraform apply to create
  2. Update the column comment in terraform code
  3. Run terraform apply again

Terraform and provider versions

$ tf version
Terraform v1.7.5
on windows_amd64
+ provider registry.terraform.io/azure/azapi v1.15.0
+ provider registry.terraform.io/databricks/databricks v1.58.0
+ provider registry.terraform.io/hashicorp/azurerm v3.109.0
+ provider registry.terraform.io/hashicorp/null v3.2.3

Is it a regression?

No

Important Factoids

This is partly a databricks issue, because you can't run ALTER VIEW at all - the same issue actually occurs if you try and edit column comments directly in the databricks UI. In the absence of databricks fixing this, would it be possible for the provider to be updated so that changes to column comments force replacement of views? There's no harm in replacing views, since they don't contain data so this would be safe to do, and would make it much easier to manage views with column comments using terraform. Currently we have to manually taint or delete views before applying whenever changing comments, which is quite frustrating