Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
fix: ALL implicit privileges equality check #339
fix: ALL implicit privileges equality check #339
Changes from 4 commits
09a9f30
edacad1
e3b92a0
add228c
f58fbb3
8dfcf90
db54bfc
54fc593
c64e956
a091370
30d4b45
d288aaf
55875e9
0393157
c35441d
4f65139
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Cool 👍
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.
Why the
SetId
is in theif
? It's not the case forpostgresql_grant
and I think we want to set it in any cases.Currently this works anyway because the ID is based on fields that recreate the resource if they change so it will never change here, but this is still totally unrelated to 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.
you are right, this was probably just a slip.
changed this with c35441d
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.
granted
no ? as this function read the state of the database. Otherwise there will never be any diff as you set in the state what's in the state already.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 am not quite sure about that. We check whats on the DB...
if the state on the DB does not equal whats requested via terraform, we want to set the privileges that are requested.
granted
is what we already have. this would then probably also apply to your other comment.Also, that would be strange because that would be a fundamental bug in the "feature". Since i tested the changes with a database locally and had great success with the former implementation, I would be very much surprised if this was wrong all the way
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 only thing that is weird to me right now is the fact, that I fetch the required privileges from the resourcedata and then put it back there again. this call is quite superflous but still won't hurt.
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.
Indeed, but that's not exactly how this function works.
The goal of a resource read function (in this case
resourcePostgreSQLGrantRead
) is to refresh the Terraform state with the current status of what's in Postgres.Then Terraform will compare the resource as it's defined in your code with how it is in the state (so in Postgres).
So the goal of this line is to set the privileges as it is in the dabase so it will be compared with what's defined in you resource definition.
It's because you haven't tested all the use cases (if I dare 😅 )
You think you fully fix that because there's no more diff in
terraform plan
compared to before, but actually there will now never be any diff because you say that the current state in the database is what's defined in your code, so Terraform will always say that everything is already correct.Easy to demonstrate with this simple code:
that you can apply:
Then, you manually remove a permission in Postgres:
And next
terraform plan
will not show any diff when it should say that it needs to fix the permissions.If I rebuild my provider with the suggestion I did above (set
granted
instead of wanted), if I manually remove a permission from the database, I will have this plan:And once applied, thanks to your fix, there will not be any diff in the next 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.
.. that sounds reasonable 😅 i adjusted that with 54fc593 and provided an acceptance test for it. would be cool if you could check again @cyrilgdn
thanks in advance