databricks / terraform-provider-databricks

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

[ISSUE] Empty lines or tabs inside SQL query of view definition will trigger redeployment of `databricks_sql_table` resource #3865

Open p-venclovas opened 1 month ago

p-venclovas commented 1 month ago

Configuration

resource "databricks_sql_table" "test_view" {
  provider                = databricks.workspace
  cluster_id              = data.databricks_cluster.test_cluster.id
  catalog_name            = "test"
  schema_name             = "test"
  name                    = "view_test"
  table_type              = "VIEW"
  view_definition = "select 1,\n\n\n\2,\t3"
}

Expected Behavior

After initial terraform apply, resource would be deployed. Running terraform plan afterwards, no changes should be detected in the resource.

Actual Behavior

After initial terraform apply, resource was deployed. Running terraform plan afterwards, changes were detected in the view definition.

View definition read and returned by the provider looks like: "select 1,\n2, 3" thus changes in the view_definition are detected.

Steps to Reproduce

  1. terraform apply
  2. After successfully creating resource, run terraform plan

Terraform and provider versions

Terraform v1.5.7. Databricks latest release.

Debug Output

After debugging databricks terraform provider,it became clear that when databricks terraform provider is reading the state of view, view definition is returned with the following formatting applied:

Would you like to implement a fix?

Yes, I would be happy to share the fix with the community.

There was an attempt to resolve this for empty new lines specifically, but it was never merged.

p-venclovas commented 2 weeks ago

Raised PR https://github.com/databricks/terraform-provider-databricks/pull/4003