databricks / terraform-provider-databricks

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

[ISSUE] Can't add new tables to `databricks_share` resource #3517

Open keyunjie96 opened 5 months ago

keyunjie96 commented 5 months ago

Hello, it seems Terraform doesn't support adding new tables to an existing delta share, please the diff and stack trace below:

  # databricks_share.created_share_data_sdi_db_ingest_aws_prod_ca_central_1 will be updated in-place
  ~ resource "databricks_share" "share_name" {
        id         = "share_id"
        name       = "share_name"
        # (3 unchanged attributes hidden)

      ~ object {
          ~ name                        = "main.schema_name.c" -> "main.schema_name.a"
            # (8 unchanged attributes hidden)
        }
      + object {
          + data_object_type = "TABLE"
          + name             = "main.schema_name.b"
        }
      + object {
          + data_object_type = "TABLE"
          + name             = "main.schema_name.c"
        }
    }

Plan: 0 to add, 1 to change, 0 to destroy.
databricks_share.share_name: Modifying... [id=share_id]
╷
│ Error: cannot update share: UpdateShare duplicate updates on the same data object with data object type: TABLE, names: [schema_name.c].
│ 
│   with databricks_share.share_name,
│   on main.tf.json line 863, in resource[21].databricks_share.share_name:
│  863:             }
│ 
╵

And we are following the suggestion from https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/share#example-usage to sort objects alphabetically

In Terraform configuration, it is recommended to define objects in alphabetical order of their name arguments, so that you get consistent and readable diff. Whenever objects are added or removed, or name is renamed, you'll observe a change in the majority of tasks. It's related to the fact that the current version of the provider treats object blocks as an ordered list. Alternatively, object block could have been an unordered set, though end-users would see the entire block replaced upon a change in single property of the task.

Configuration

We first deployed

            "databricks_share": {
                "share_name": {
                    "name": "share_name",
                    "object": [
                        {
                            "data_object_type": "TABLE",
                            "name": "main.schema_name.c"
                        }
                    ],
                    "owner": "owner@databricks.com"
                }
            }

Then we added a few more tables then it looks like

            "databricks_share": {
                "share_name": {
                    "name": "share_name",
                    "object": [
                        {
                            "data_object_type": "TABLE",
                            "name": "main.schema_name.a"
                        },
                        {
                            "data_object_type": "TABLE",
                            "name": "main.schema_name.b"
                        },
                        {
                            "data_object_type": "TABLE",
                            "name": "main.schema_name.c"
                        }
                    ],
                    "owner": "owner@databricks.com"
                }
            }

Expected Behavior

Users should be able to add new tables if needed.

Actual Behavior

I assume it treats main.schema_name.c as a new table then tried to add it but it find it is duplicated with the existing one.

Steps to Reproduce

1.41.0

Is it a regression?

Probably no.

Debug Output

Please check the ticket

Important Factoids

This is also tracked internally at https://databricks.atlassian.net/browse/ES-1110321. You can see more debugging logs there

Would you like to implement a fix?

alexott commented 5 months ago

please collect logs as per troubleshooting guide...

keyunjie96 commented 5 months ago

@alexott I add to go/zerobin. I don't think I can share full logs publicly

alexott commented 5 months ago

You can post it internally, without pasting link here

keyunjie96 commented 5 months ago

The Jenkins run has been included in the ticket since the beginning