Skip to content

Commit fe4db38

Browse files
authored
[Internal] Added integration test for METRIC_VIEW table type in databricks_grant and databricks_grants (#4927)
## Changes <!-- Summary of your changes that are easy to understand --> Verify that METRIC_VIEW table works for both grant and grants terraform resource ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> Integration tests
1 parent 415400f commit fe4db38

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@
2020
### Exporter
2121

2222
### Internal Changes
23+
* Added integration test for METRIC_VIEW table type in `databricks_grant` and `databricks_grants` ([#4927](https://github.com/databricks/terraform-provider-databricks/pull/4927))

catalog/grant_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ resource "databricks_schema" "things" {
3030
resource "databricks_table" "mytable" {
3131
catalog_name = databricks_catalog.sandbox.id
3232
schema_name = databricks_schema.things.name
33-
name = "bar"
33+
name = "managed-{var.STICKY_RANDOM}"
3434
table_type = "MANAGED"
3535
data_source_format = "DELTA"
3636
@@ -43,6 +43,22 @@ resource "databricks_table" "mytable" {
4343
}
4444
}
4545
46+
resource "databricks_table" "metric_view_grant" {
47+
catalog_name = databricks_catalog.sandbox.id
48+
schema_name = databricks_schema.things.name
49+
name = "metric-view-{var.STICKY_RANDOM}"
50+
table_type = "METRIC_VIEW"
51+
data_source_format = ""
52+
53+
column {
54+
name = "id"
55+
position = 0
56+
type_name = "INT"
57+
type_text = "int"
58+
type_json = "{\"name\":\"id\",\"type\":\"integer\",\"nullable\":true,\"metadata\":{}}"
59+
}
60+
}
61+
4662
resource "databricks_storage_credential" "external" {
4763
name = "cred-{var.STICKY_RANDOM}"
4864
aws_iam_role {
@@ -86,6 +102,12 @@ resource "databricks_grant" "table" {
86102
privileges = ["ALL_PRIVILEGES"]
87103
}
88104
105+
resource "databricks_grant" "metric_view_grant" {
106+
table = databricks_table.metric_view_grant.id
107+
principal = "%s"
108+
privileges = ["ALL_PRIVILEGES"]
109+
}
110+
89111
resource "databricks_grant" "cred" {
90112
storage_credential = databricks_storage_credential.external.id
91113

catalog/grants_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ resource "databricks_schema" "things" {
3030
resource "databricks_table" "mytable" {
3131
catalog_name = databricks_catalog.sandbox.id
3232
schema_name = databricks_schema.things.name
33-
name = "bar"
33+
name = "managed-{var.STICKY_RANDOM}"
3434
table_type = "MANAGED"
3535
data_source_format = "DELTA"
3636
@@ -43,6 +43,22 @@ resource "databricks_table" "mytable" {
4343
}
4444
}
4545
46+
resource "databricks_table" "metric_view_grants" {
47+
catalog_name = databricks_catalog.sandbox.id
48+
schema_name = databricks_schema.things.name
49+
name = "metric-view-{var.STICKY_RANDOM}"
50+
table_type = "METRIC_VIEW"
51+
data_source_format = ""
52+
53+
column {
54+
name = "id"
55+
position = 0
56+
type_name = "INT"
57+
type_text = "int"
58+
type_json = "{\"name\":\"id\",\"type\":\"integer\",\"nullable\":true,\"metadata\":{}}"
59+
}
60+
}
61+
4662
resource "databricks_storage_credential" "external" {
4763
name = "cred-{var.STICKY_RANDOM}"
4864
aws_iam_role {
@@ -90,6 +106,14 @@ resource "databricks_grants" "table" {
90106
}
91107
}
92108
109+
resource "databricks_grants" "metric_view_grants" {
110+
table = databricks_table.metric_view_grants.id
111+
grant {
112+
principal = "%s"
113+
privileges = ["ALL_PRIVILEGES"]
114+
}
115+
}
116+
93117
resource "databricks_grants" "cred" {
94118
storage_credential = databricks_storage_credential.external.id
95119
grant {

docs/resources/sql_table.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ The following arguments are supported:
174174
* `name` - Name of table relative to parent catalog and schema. Change forces the creation of a new resource.
175175
* `catalog_name` - Name of parent catalog. Change forces the creation of a new resource.
176176
* `schema_name` - Name of parent Schema relative to parent Catalog. Change forces the creation of a new resource.
177-
* `table_type` - Distinguishes a view vs. managed/external Table. `MANAGED`, `EXTERNAL`, or `VIEW`. Change forces the creation of a new resource.
177+
* `table_type` - Distinguishes a view vs. managed/external Table. `MANAGED`, `EXTERNAL`, `METRIC_VIEW` or `VIEW`. Change forces the creation of a new resource.
178178
* `storage_location` - (Optional) URL of storage location for Table data (required for EXTERNAL Tables). Not supported for `VIEW` or `MANAGED` table_type.
179179
* `data_source_format` - (Optional) External tables are supported in multiple data source formats. The string constants identifying these formats are `DELTA`, `CSV`, `JSON`, `AVRO`, `PARQUET`, `ORC`, and `TEXT`. Change forces the creation of a new resource. Not supported for `MANAGED` tables or `VIEW`.
180180
* `view_definition` - (Optional) SQL text defining the view (for `table_type == "VIEW"`). Not supported for `MANAGED` or `EXTERNAL` table_type.
@@ -258,7 +258,7 @@ The migration would look like this:
258258
```hcl
259259
# Leave this resource definition as-is.
260260
resource "databricks_table" "this" {
261-
# ...
261+
# ...
262262
}
263263
264264
# Remove the old resource without destroying the existing table.

0 commit comments

Comments
 (0)