Skip to content

Commit ea66fb8

Browse files
authored
Set id attribute of databricks_metastore data source (#3503)
In addition to filling `metastore_id` we set `id` to the same value
1 parent 89fcf94 commit ea66fb8

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

catalog/data_metastore.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,21 @@ import (
1212

1313
func DataSourceMetastore() common.Resource {
1414
type AccountMetastoreByID struct {
15-
Id string `json:"metastore_id,omitempty" tf:"computed"`
16-
Name string `json:"name,omitempty" tf:"computed"`
17-
Region string `json:"region,omitempty" tf:"computed"`
18-
Metastore *catalog.MetastoreInfo `json:"metastore_info,omitempty" tf:"computed" `
15+
Id string `json:"id,omitempty" tf:"computed"`
16+
MetastoreId string `json:"metastore_id,omitempty" tf:"computed"`
17+
Name string `json:"name,omitempty" tf:"computed"`
18+
Region string `json:"region,omitempty" tf:"computed"`
19+
Metastore *catalog.MetastoreInfo `json:"metastore_info,omitempty" tf:"computed" `
1920
}
2021
return common.AccountData(func(ctx context.Context, data *AccountMetastoreByID, acc *databricks.AccountClient) error {
21-
if data.Id == "" && data.Name == "" && data.Region == "" {
22+
if data.MetastoreId == "" && data.Name == "" && data.Region == "" {
2223
return fmt.Errorf("one of metastore_id, name or region must be provided")
2324
}
24-
if (data.Id != "" && data.Name != "") || (data.Region != "" && data.Id != "") || (data.Region != "" && data.Name != "") {
25+
if (data.MetastoreId != "" && data.Name != "") || (data.Region != "" && data.MetastoreId != "") || (data.Region != "" && data.Name != "") {
2526
return fmt.Errorf("only one of metastore_id, name or region must be provided")
2627
}
27-
if data.Id != "" {
28-
minfo, err := acc.Metastores.GetByMetastoreId(ctx, data.Id)
28+
if data.MetastoreId != "" {
29+
minfo, err := acc.Metastores.GetByMetastoreId(ctx, data.MetastoreId)
2930
if err != nil {
3031
return err
3132
}
@@ -58,6 +59,7 @@ func DataSourceMetastore() common.Resource {
5859
data.Metastore = &minfos[0]
5960
}
6061
data.Id = data.Metastore.MetastoreId
62+
data.MetastoreId = data.Metastore.MetastoreId
6163
data.Name = data.Metastore.Name
6264
data.Region = data.Metastore.Region
6365
return nil

catalog/data_metastore_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func TestMetastoreByRegion(t *testing.T) {
130130
region = "westus"
131131
`,
132132
}.ApplyAndExpectData(t, map[string]any{
133+
"id": "abc",
133134
"name": "xyz",
134135
"region": "westus",
135136
"metastore_info.0.name": "xyz",

docs/data-sources/metastore.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ output "some_metastore" {
3636

3737
Provide one of the arguments to get information about a metastore:
3838

39-
* `metastore_id` - Id of the metastore
39+
* `metastore_id` - ID of the metastore
4040
* `name` - Name of the metastore
4141
* `region` - Region of the metastore
4242

@@ -45,6 +45,7 @@ Provide one of the arguments to get information about a metastore:
4545

4646
This data source exports the following attributes:
4747

48+
* `id` - ID of the metastore
4849
* `metastore_info` - MetastoreInfo object for a [databricks_metastore](../resources/metastore.md). This contains the following attributes:
4950
* `name` - Name of metastore.
5051
* `storage_root` - Path on cloud storage account, where managed `databricks_table` are stored.

0 commit comments

Comments
 (0)