Skip to content

Commit a8ad3fa

Browse files
Surface table_id in databricks_sql_table (#5058)
## Changes Surfacing `table_id` in the `databricks_sql_table` resource. The [API already supports this](https://docs.databricks.com/api/workspace/tables/get#table_id), so this change is to surface it in Terraform so other resources can leverage it. The change is to add TableID into [SqlTableInfo](https://github.com/databricks/terraform-provider-databricks/blob/main/catalog/resource_sql_table.go#L47). When reading the resource, the [getTable](https://github.com/databricks/terraform-provider-databricks/blob/main/catalog/resource_sql_table.go#L106) function is called to [fetch from the Get UC Table API](https://docs.databricks.com/api/workspace/tables/get#table_id), which should have the table_id field and will therefore be [copied to the tableInfo](https://github.com/databricks/terraform-provider-databricks/blob/main/catalog/resource_sql_table.go#L107). ## Tests `go test -v ./catalog -run "TestResourceSqlTable"` passes. --------- Co-authored-by: Miles Yucht <[email protected]>
1 parent fbacbd4 commit a8ad3fa

File tree

5 files changed

+11
-0
lines changed

5 files changed

+11
-0
lines changed

NEXT_CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
### New Features and Improvements
88

9+
* Add `table_id` to the output of `databricks_sql_table` resource ([#5058](https://github.com/databricks/terraform-provider-databricks/pull/5058)).
10+
911
### Bug Fixes
1012

1113
* Allow update `managed_services_customer_managed_key_id` in `databricks_mws_workspaces` ([#5034](https://github.com/databricks/terraform-provider-databricks/pull/5034))

catalog/resource_sql_table.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ type SqlTableInfo struct {
6464
ClusterID string `json:"cluster_id,omitempty" tf:"computed"`
6565
WarehouseID string `json:"warehouse_id,omitempty"`
6666
Owner string `json:"owner,omitempty" tf:"computed"`
67+
TableID string `json:"table_id" tf:"computed"`
6768

6869
exec common.CommandExecutor
6970
sqlExec sql.StatementExecutionInterface

catalog/resource_sql_table_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,6 +1779,7 @@ func TestResourceSqlTable_Diff_ExistingResource(t *testing.T) {
17791779
"",
17801780
map[string]string{
17811781
"effective_properties.%": "0",
1782+
"table_id": "test-table-id-123",
17821783
},
17831784
nil,
17841785
},
@@ -1789,6 +1790,7 @@ func TestResourceSqlTable_Diff_ExistingResource(t *testing.T) {
17891790
"effective_properties.%": "2",
17901791
"effective_properties.computedprop": "computedvalue",
17911792
"effective_properties.option.computedprop": "computedvalue",
1793+
"table_id": "test-table-id-123",
17921794
},
17931795
nil,
17941796
},
@@ -1811,6 +1813,7 @@ func TestResourceSqlTable_Diff_ExistingResource(t *testing.T) {
18111813
"effective_properties.myprop": "myval",
18121814
"effective_properties.option.myopt": "myval",
18131815
"effective_properties.spark.sql.dataSourceOptions.multiLine": "true",
1816+
"table_id": "test-table-id-123",
18141817
},
18151818
nil,
18161819
},
@@ -1832,6 +1835,7 @@ func TestResourceSqlTable_Diff_ExistingResource(t *testing.T) {
18321835
"effective_properties.computedprop": "computedval",
18331836
"effective_properties.option.myopt": "myval",
18341837
"effective_properties.option.computedopt": "computedval",
1838+
"table_id": "test-table-id-123",
18351839
},
18361840
nil,
18371841
},
@@ -1852,6 +1856,7 @@ func TestResourceSqlTable_Diff_ExistingResource(t *testing.T) {
18521856
"effective_properties.%": "2",
18531857
"effective_properties.myprop": "otherval",
18541858
"effective_properties.option.myopt": "otherval",
1859+
"table_id": "test-table-id-123",
18551860
},
18561861
map[string]*terraform.ResourceAttrDiff{
18571862
"effective_properties.myprop": {New: "myval", Old: "otherval"},

docs/data-sources/table.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ This data source exports the following attributes:
4545
* `columns` - Array of ColumnInfo objects of the table's columns
4646
* `owner` - Current owner of the table
4747
* `comment` - Free-form text description
48+
* `table_id` - The unique identifier of the table.
49+
4850

4951
## Related Resources
5052

docs/resources/sql_table.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ Currently, changing the column definitions for a table will require dropping and
204204
In addition to all the arguments above, the following attributes are exported:
205205

206206
* `id` - ID of this table in the form of `<catalog_name>.<schema_name>.<name>`.
207+
* `table_id` - The unique identifier of the table.
207208

208209
## Import
209210

0 commit comments

Comments
 (0)