Skip to content

Commit 37c6c29

Browse files
authored
Explicitly set securable field when reading databricks_grants or databricks_grant (#3246)
The read method of corresponding resources was reading only a list of permissions, but it didn't set the securable field, so when doing the import, that field was empty and this lead to recreation of the resource after import. This PR explicitly sets that field on read. This fixes #3245
1 parent a3cc8a6 commit 37c6c29

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

catalog/resource_grant.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,11 @@ func ResourceGrant() common.Resource {
184184
if err != nil {
185185
return err
186186
}
187-
return common.StructToData(*grantsForPrincipal, s, d)
187+
err = common.StructToData(*grantsForPrincipal, s, d)
188+
if err != nil {
189+
return err
190+
}
191+
return d.Set(securable, name)
188192
},
189193
Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
190194
w, err := c.WorkspaceClient()

catalog/resource_grants.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,12 @@ func ResourceGrants() common.Resource {
351351
if len(grants.PrivilegeAssignments) == 0 {
352352
return apierr.NotFound("got empty permissions list")
353353
}
354-
return common.StructToData(sdkPermissionsListToPermissionsList(*grants), s, d)
354+
355+
err = common.StructToData(sdkPermissionsListToPermissionsList(*grants), s, d)
356+
if err != nil {
357+
return err
358+
}
359+
return d.Set(securable, name)
355360
},
356361
Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
357362
w, err := c.WorkspaceClient()

docs/resources/grant.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,12 @@ resource "databricks_grant" "some" {
345345
## Other access control
346346

347347
You can control Databricks General Permissions through [databricks_permissions](permissions.md) resource.
348+
349+
## Import
350+
351+
The resource can be imported using combination of securable type (`table`, `catalog`, `foreign_connection`, ...), it's name and `principal`:
352+
353+
```bash
354+
terraform import databricks_grant.this catalog/abc/user_name
355+
```
356+

docs/resources/grants.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,12 @@ resource "databricks_grants" "some" {
341341
## Other access control
342342

343343
You can control Databricks General Permissions through [databricks_permissions](permissions.md) resource.
344+
345+
## Import
346+
347+
The resource can be imported using combination of securable type (`table`, `catalog`, `foreign_connection`, ...) and it's name:
348+
349+
```bash
350+
terraform import databricks_grants.this catalog/abc
351+
```
352+

0 commit comments

Comments
 (0)