Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Exporter] Add listing for databricks_permissions so we can emit permissions for tokens #4402

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/guides/experimental-exporter.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Services are just logical groups of resources used for filtering and organizatio
-> **Note**
Please note that for services not marked with **listing**, we'll export resources only if they are referenced from other resources.

* `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).
* `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!*
* `alerts` - **listing** [databricks_alert](../resources/alert.md).
* `compute` - **listing** [databricks_cluster](../resources/cluster.md).
* `dashboards` - **listing** [databricks_dashboard](../resources/dashboard.md).
Expand Down
9 changes: 9 additions & 0 deletions exporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,13 @@ var meAdminFixture = qa.HTTPFixture{
},
}

var getTokensPermissionsFixture = qa.HTTPFixture{
Method: "GET",
Resource: "/api/2.0/permissions/authorization/tokens?",
Response: getJSONObject("test-data/get-tokens-permissions.json"),
ReuseRequest: true,
}

var emptyPipelines = qa.HTTPFixture{
Method: "GET",
ReuseRequest: true,
Expand Down Expand Up @@ -737,6 +744,7 @@ func TestImportingUsersGroupsSecretScopes(t *testing.T) {
Key: "b",
},
},
getTokensPermissionsFixture,
}, func(ctx context.Context, client *common.DatabricksClient) {
tmpDir := fmt.Sprintf("/tmp/tf-%s", qa.RandomName())
defer os.RemoveAll(tmpDir)
Expand Down Expand Up @@ -1830,6 +1838,7 @@ func TestImportingIPAccessLists(t *testing.T) {
emptyWorkspaceConf,
dummyWorkspaceConf,
allKnownWorkspaceConfs,
getTokensPermissionsFixture,
{
Method: "GET",
Resource: "/api/2.0/global-init-scripts",
Expand Down
10 changes: 10 additions & 0 deletions exporter/importables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,16 @@ var resourcesMap map[string]importable = map[string]importable{
s := strings.Split(d.Id(), "/")
return s[len(s)-1]
},
List: func(ic *importContext) error {
if ic.meAdmin {
ic.Emit(&resource{
Resource: "databricks_permissions",
ID: "/authorization/tokens",
Name: "tokens_usage",
})
}
return nil
},
Depends: []reference{
{Path: "job_id", Resource: "databricks_job"},
{Path: "pipeline_id", Resource: "databricks_pipeline"},
Expand Down
15 changes: 15 additions & 0 deletions exporter/test-data/get-tokens-permissions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"access_control_list": [
{
"all_permissions": [
{
"inherited":false,
"permission_level":"CAN_MANAGE"
}
],
"group_name":"admins"
}
],
"object_id":"/authorization/tokens",
"object_type":"tokens"
}
Loading