-
Notifications
You must be signed in to change notification settings - Fork 219
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
Update resource_builtin_role_assignment resource to ignore assignments defined in the server side #369
Conversation
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.
The solution seems like a good one to me and it's well tested. I can't test it on my side but it LGTM!
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: testAccProviderFactories, | ||
CheckDestroy: testAccBuiltInRoleAssignmentCheckDestroy(&br), |
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.
Should the CheckDestroy
function also check that the default assignements weren't destroyed?
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.
Really good catch. I actually just realized that testAccBuiltInRoleAssignmentCheckDestroy
checks nothing, as the pointer to &br
never updates to the created built-in role assignment, so we always pass an empty struct to the method, which returns success on it's turn as there is indeed no assignment for empty built-in role.
Working on a fix.
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.
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've just left a minor request. My initial review looks good, but I want to give it another round to fully understand what are we testing here.
Thank you so much for your hard work!
…s defined in the server side When Grafana starts, by default it creates built-in role assignments for fixed roles. Additionally, users can create built-in role assignments via API. In these scenarios, when the resource is not properly imported, terraform will try to destroy what is in server side, but not in the configuration. The change ensures that this does not happen as it can cause unintended behaviour for users.
Context
When Grafana starts, by default it creates built-in role assignments for fixed roles. Additionally, users can create built-in role assignments via API. In these scenarios, when the resource is not properly imported, terraform will try to destroy what is in server side, but not in the configuration.
The change ensures that this does not happen as it can cause unintended behaviour for users.
Implementation details
The only workaround, with the given resources is to do in advance check to see if the fetched assignments has been ever in the state, or is present in the configuration, otherwise ignore it.
Testing
I have manually tested the following scenarios:
Additionally, the newly added test covers the scenario mentioned in the issue.
Related issues
Fixes #362