Skip to content

Commit b8cf8fb

Browse files
authored
[Exporter] Add listing for databricks_permissions so we can emit permissions for tokens (#4402)
## Changes <!-- Summary of your changes that are easy to understand --> It was a missing functionality when we emitted all permissions on existing objects, but didn't do it for permissions of personal access tokens. Resolves #4389 ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [x] `make test` run locally - [x] relevant change in `docs/` folder - [ ] covered with integration tests in `internal/acceptance` - [ ] using Go SDK - [ ] using TF Plugin Framework
1 parent 8b63826 commit b8cf8fb

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

docs/guides/experimental-exporter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Services are just logical groups of resources used for filtering and organizatio
113113
-> **Note**
114114
Please note that for services not marked with **listing**, we'll export resources only if they are referenced from other resources.
115115

116-
* `access` - [databricks_permissions](../resources/permissions.md), [databricks_instance_profile](../resources/instance_profile.md), [databricks_ip_access_list](../resources/ip_access_list.md), [databricks_mws_permission_assignment](../resources/mws_permission_assignment.md) and [databricks_access_control_rule_set](../resources/access_control_rule_set.md).
116+
* `access` - **listing** [databricks_permissions](../resources/permissions.md), [databricks_instance_profile](../resources/instance_profile.md), [databricks_ip_access_list](../resources/ip_access_list.md), [databricks_mws_permission_assignment](../resources/mws_permission_assignment.md) and [databricks_access_control_rule_set](../resources/access_control_rule_set.md). *Please note that for `databricks_permissions` we list only `authorization = "tokens"`, the permissions for other objects (notebooks, ...) will be emitted when corresponding objects are processed!*
117117
* `alerts` - **listing** [databricks_alert](../resources/alert.md).
118118
* `compute` - **listing** [databricks_cluster](../resources/cluster.md).
119119
* `dashboards` - **listing** [databricks_dashboard](../resources/dashboard.md).

exporter/exporter_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,13 @@ var meAdminFixture = qa.HTTPFixture{
234234
},
235235
}
236236

237+
var getTokensPermissionsFixture = qa.HTTPFixture{
238+
Method: "GET",
239+
Resource: "/api/2.0/permissions/authorization/tokens?",
240+
Response: getJSONObject("test-data/get-tokens-permissions.json"),
241+
ReuseRequest: true,
242+
}
243+
237244
var emptyPipelines = qa.HTTPFixture{
238245
Method: "GET",
239246
ReuseRequest: true,
@@ -730,6 +737,7 @@ func TestImportingUsersGroupsSecretScopes(t *testing.T) {
730737
Key: "b",
731738
},
732739
},
740+
getTokensPermissionsFixture,
733741
}, func(ctx context.Context, client *common.DatabricksClient) {
734742
tmpDir := fmt.Sprintf("/tmp/tf-%s", qa.RandomName())
735743
defer os.RemoveAll(tmpDir)
@@ -1782,6 +1790,7 @@ func TestImportingIPAccessLists(t *testing.T) {
17821790
emptyRepos,
17831791
emptyWorkspaceConf,
17841792
allKnownWorkspaceConfsNoData,
1793+
getTokensPermissionsFixture,
17851794
{
17861795
Method: "GET",
17871796
Resource: "/api/2.0/global-init-scripts",

exporter/importables.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,16 @@ var resourcesMap map[string]importable = map[string]importable{
10241024
s := strings.Split(d.Id(), "/")
10251025
return s[len(s)-1]
10261026
},
1027+
List: func(ic *importContext) error {
1028+
if ic.meAdmin {
1029+
ic.Emit(&resource{
1030+
Resource: "databricks_permissions",
1031+
ID: "/authorization/tokens",
1032+
Name: "tokens_usage",
1033+
})
1034+
}
1035+
return nil
1036+
},
10271037
Depends: []reference{
10281038
{Path: "job_id", Resource: "databricks_job"},
10291039
{Path: "pipeline_id", Resource: "databricks_pipeline"},
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"access_control_list": [
3+
{
4+
"all_permissions": [
5+
{
6+
"inherited":false,
7+
"permission_level":"CAN_MANAGE"
8+
}
9+
],
10+
"group_name":"admins"
11+
}
12+
],
13+
"object_id":"/authorization/tokens",
14+
"object_type":"tokens"
15+
}

0 commit comments

Comments
 (0)