Skip to content

Commit 0bc7fe3

Browse files
authored
direct: Support configuration for unordered slices; use in permissions to ignore order (#4014)
## Changes - Extend structpath to support [key=‘value’] syntax. - Extend structdiff with extra parameter that maps path to keyFunc which is a function that returns key/value pair for a given slice element. They pair is used to identify the slice element.
 - Use this functionality on permissions resource in direct to solve drift due to backend reordering permissions. ## Why - Prevent remote drift due to backend reordering slice elements. - Make diffs more readable / precise. This is an alternative to always sorting the input, which destroys the references ($resources.jobs.foo.tasks[1] is not valid today because of sorting). In a follow up PR I’ll revert job tasks sorting #3212 and implement KeyedSlices instead.
1 parent d22a5ab commit 0bc7fe3

33 files changed

+871
-53
lines changed

acceptance/bundle/resources/permissions/jobs/delete_one/cloud/out.plan.direct.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

acceptance/bundle/resources/permissions/jobs/delete_one/cloud/out.plan.terraform.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

acceptance/bundle/resources/permissions/jobs/delete_one/cloud/output.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Updating deployment state...
88
Deployment complete!
99

1010
>>> [CLI] bundle plan
11+
Plan: 0 to add, 0 to change, 0 to delete, 2 unchanged
1112

1213
=== Delete one permission and deploy again
1314

acceptance/bundle/resources/permissions/jobs/delete_one/cloud/script

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ trace $CLI bundle deploy
3333
# although they are semantically the same. We're not doing the same transformation in direct, because permissions get endpoint uses a different order.
3434
print_requests | sort_acl_requests > out.requests_create.json
3535

36-
# Badness: because of remote reordering we have drift in direct there
37-
trace $CLI bundle plan > out.plan.$DATABRICKS_BUNDLE_ENGINE.txt
36+
trace $CLI bundle plan
3837

3938
job_id=$($CLI bundle summary --output json | jq -r '.resources.jobs.job_with_permissions.id')
4039

acceptance/bundle/resources/permissions/jobs/delete_one/local/out.plan_update.direct.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
},
101101
"changes": {
102102
"local": {
103-
"permissions": {
103+
"permissions[user_name='[email protected]']": {
104104
"action": "update"
105105
}
106106
}

acceptance/bundle/resources/permissions/jobs/deleted_remotely/out.plan_restore.direct.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@
8888
},
8989
"changes": {
9090
"remote": {
91-
"permissions": {
91+
"permissions[group_name='data-team']": {
92+
"action": "update"
93+
},
94+
"permissions[user_name='[email protected]']": {
9295
"action": "update"
9396
}
9497
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
bundle:
2+
name: test-bundle
3+
4+
resources:
5+
jobs:
6+
foo:
7+
name: job1
8+
tasks:
9+
- task_key: main
10+
notebook_task:
11+
notebook_path: /Workspace/Users/[email protected]/notebook
12+
source: WORKSPACE
13+
permissions:
14+
- {"level": "CAN_VIEW", "user_name": "[email protected]"}
15+
- level: CAN_MANAGE
16+
group_name: data-team
17+
- level: CAN_MANAGE
18+
service_principal_name: f37d18cd-98a8-4db5-8112-12dd0a6bfe38
19+
# PLACEHOLDER

acceptance/bundle/resources/permissions/jobs/reorder_locally/out.test.toml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
>>> [CLI] bundle deploy
3+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
4+
Deploying resources...
5+
Updating deployment state...
6+
Deployment complete!
7+
8+
>>> [CLI] bundle plan
9+
Plan: 0 to add, 0 to change, 0 to delete, 2 unchanged
10+
11+
>>> [CLI] bundle deploy
12+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
13+
Deploying resources...
14+
Updating deployment state...
15+
Deployment complete!
16+
17+
>>> [CLI] bundle plan
18+
Plan: 0 to add, 0 to change, 0 to delete, 2 unchanged
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
trace $CLI bundle deploy
2+
update_file.py databricks.yml '- {"level": "CAN_VIEW", "user_name": "[email protected]"}' ''
3+
update_file.py databricks.yml ' # PLACEHOLDER' '- {"level": "CAN_VIEW", "user_name": "[email protected]"}'
4+
5+
trace $CLI bundle plan
6+
trace $CLI bundle deploy
7+
trace $CLI bundle plan

0 commit comments

Comments
 (0)