-
Notifications
You must be signed in to change notification settings - Fork 393
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
Handle UC Resource Grants with Spaces #3292
Conversation
Since the underlying "mapping" has gone away since I started on this, I've switched this behavior to match the API and just silently treat |
Does it work correctly? No configuration drift after apply? |
Sorry, I should have provided a little more detail originally. No, it does not work. If I define a resource like this: resource "databricks_grants" "external_location" {
external_location = "my_location"
grant {
principal = "user"
privileges = ["ALL PRIVILEGES"] # this should have an underscore between words
}
} The initial attempt fails with an error like this:
Retries fail with:
Which matches the behavior in the CLI:
The diff'ing logic doesn't take into consideration that "ALL PRIVILEGES" is the same as "ALL_PRIVILEGES" in the databricks API/CLI (it silently just accepts it without the underscore). |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3292 +/- ##
==========================================
- Coverage 83.59% 83.58% -0.01%
==========================================
Files 178 178
Lines 16759 16769 +10
==========================================
+ Hits 14009 14017 +8
- Misses 1899 1900 +1
- Partials 851 852 +1
|
@ledbutter Thanks for this contribution! We've discussed this problem and your approach seems to solve one half of the problem. The other half is making sure that there is no diff from TF perspective at plan time if the only difference is underscores. Can you add logic to |
I've pushed changes for just the singular grant resource so far, but I'm still trying to figure out how to test this properly: I can't find prior art for a scenario like this with the CustomizeDiff being tested like this. The closest I've found is validating the "health" attribute is cleared on sql endpoint, but that doesn't require any actual setup. I'll keep grinding on this as I get the time. |
After more research, it seems like |
@ledbutter the only test I've seen that test this behaviour is |
Right, and this is so trivial I don't see much value in it, but I will certainly add those tests if desired. What I'd really like to validate is the actual |
For unit testing, this is the way to test as we should validate that the |
I think I've done this with my latest commits, but I'm uncertain about how I'm trying to assert the integration tests... |
internal/acceptance/grant_test.go
Outdated
unityWorkspaceLevel(t, step{ | ||
Template: grantTemplateForUnderscoreChange("ALL_PRIVILEGES"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should suffice to just have a single step with ALL PRIVILEGES
, the test would fail if there is still a diff shown in the plan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, updated
@@ -138,6 +148,9 @@ func ResourceGrant() common.Resource { | |||
ConflictsWith: permissions.SliceWithoutString(allFields, field), | |||
} | |||
} | |||
|
|||
m["privileges"].DiffSuppressFunc = permissions.PrivilegesSuppressWhitespaceChange |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ledbutter integration test failed, so I looked at this in a bit more details. DiffSuppressFunc
only works for primitive, i.e. string-like attributes. For lists, we need to look at CustomizeDiff
instead.
@tanmay-db we probably need to re-add a lightweight version of CustomizeDiff
to handle this scenario, as it is causing permanent drifts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially tried using CustomizeDiff
, but that only works for computed keys, as I mentioned here. Are you saying that there needs to be a lower level change before this can be accomplished?
@nkvuong @mgyucht So I have half of the problem solved, but I'm not sure how--if at all, given the current tooling--to solve the other half: the suppression of any diffs during a plan operation. Thoughts? I see the options as:
|
@nkvuong Thanks for fixing this in a better way! I'll close this now since it is no longer needed |
Changes
In our (private) Terraform module we were trying to configure grants using the
databricks_grants
resource, but kept running into trouble on apply because it detected duplicate grants to add/remove (snippet from our CI/CD pipeline):This was because we were missing the
_
characters there (notice the format of the privs to add). I've confirmed that the Databricks CLI/API silently accepts this:databricks grants update external_location my_loc -p dev --json '{"changes": [{"principal": "user", "add": ["ALL PRIVILEGES"]}]}'
So here I add some tests showing the gap, and then added some invocations of the already-existing
validate
method onCREATE
/UPDATE
. I certainly am open to other approaches, just wanted to get this out here for discussion.I'd also be fine with instead updating the "diff" logic here to also look for and replace spaces with underscores, but the existing
validate
tests seem to already account for that, but I'm not sure where--if at all--validate
is called on the mapping in full system calls.Tests
make test
run locallydocs/
folderinternal/acceptance