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

fix: Legacy role grantID to work with new grant functionality #941

Merged
merged 17 commits into from
Mar 23, 2022

Conversation

daniepett
Copy link
Contributor

@daniepett daniepett commented Mar 21, 2022

These changes will allow legacy grantID for role grants (Just role name), to work with the new grantID structure/functionality.

Implementing these changes requires less stringent testing on the IDs, but gives flexibility that allows legacy roleGrantIDs to be using the same function, therefore limiting code duplication.

  • acceptance tests
  • unit tests

References

@daniepett daniepett mentioned this pull request Mar 21, 2022
2 tasks
@ChrisIsidora
Copy link
Contributor

@alldoami can this be reviewed, merged and released asap? Thanks in advance

@ChrisIsidora
Copy link
Contributor

@daniepett Does this change comes with the caveat that grants applied OUTSIDE Terraform will not be revoked. If so is there a reason why this behavior is changed? This would mean I can never achieve a desired state with this new behavior

@daniepett
Copy link
Contributor Author

daniepett commented Mar 21, 2022

@ChrisIsidora The behaviour was changed to allow similar grants to be created in different resources. Resource A won't know if the grant is being applied through Resource B (Or outside Terraform), and therefore Terraform won't revoke it. It will however check that all the roles specified in that resource has the right grants applied.

@ChrisIsidora
Copy link
Contributor

@daniepett For this case I don't understand why you would want to have role to role grant distributed in different places. One of the point of IAC and terraform is reaching a desired state after applying a resource. Changing this behavior means terraform doesn't have control anymore over said resource, while the whole point is that this should be the case. When a resource is managed by terraform every change that is made outside of terraform will be corrected according to desired state you apply via terraform. This change to the grants means that if someone manually add a grant to a specific role that is managed by terraform then at the next apply terraform won't revoke that grant, while I do expect it to revoke that grant because it's not the desired state that I have in terraform.

@daniepett
Copy link
Contributor Author

I do agree, but for implementation of this functionality it was a trade off. It was clearly stated in the original PR that this would be the case, I left it up to maintainers to make that call. It can be reverted if need be.

@ChrisIsidora
Copy link
Contributor

@daniepett Furthermore this changes the behavior of what people expect that this resource will do and also for people like me that have been using these resources for ages and expect it to work a specific way. If the community wants this new behavior i would rather see it be implemented with a feature flag / switch rather than a full behavior change without introducing new resources

@ChrisIsidora
Copy link
Contributor

ChrisIsidora commented Mar 21, 2022

I do agree, but for implementation of this functionality it was a trade off. It was clearly stated in the original PR that this would be the case, I left it up to maintainers to make that call. It can be reverted if need be.

@alldoami @edulop91 @robbruce What do you think?

@daniepett
Copy link
Contributor Author

@ChrisIsidora I've pushed some changes as an example of a feature flag implementation. Is there a better way to implement this than on a resource level?

@ChrisIsidora
Copy link
Contributor

@ChrisIsidora I've pushed some changes as an example of a feature flag implementation. Is there a better way to implement this than on a resource level?

@daniepett I think it's a good implementation. Normally this is implemented a different way but in this case I think it's fine. Usually for these partial/multiple cases you see that some providers chose to introduce a new resources with only that specific functionality. A fair example is for instance azurerm_keyvault and azurerm_keyvault_access_policy. Access policy is also defined on azurerm_keyvault.

Thanks for the changes :-)

@daniepett
Copy link
Contributor Author

@ChrisIsidora It will potentially force replacement of a few grant resources as some of the grant resources don't have update functions and the config for them has changed. Should hopefully be a compromise everyone can live with.

Thanks for the feedback, do appreciate that :)

@alldoami
Copy link
Contributor

@daniepett I want to say we should error on reverting as this is causing issues. Sorry we didn't do enough testing to see whether or not this would cause issues. Is that possible to do until we have more ways to test this?

@ChrisIsidora
Copy link
Contributor

ChrisIsidora commented Mar 21, 2022

@alldoami I think with the new changes and the feature flag set by default to false it should have the same way of working as before. So i think now it should be ok. I can do a test on my side when you release.

@robbruce
Copy link
Contributor

@daniepett @alldoami @ChrisIsidora - Can a StateMigration function be added? With different schema versions? So that the the provider know's how to migrate the old id format to the new id format? I'm not sure if can be used with the id, I've never done it myself.

https://www.terraform.io/plugin/sdkv2/resources/state-migration

@alldoami
Copy link
Contributor

/ok-to-test sha=4a19ffd

@github-actions
Copy link

Integration tests failure for 4a19ffd

@ChrisIsidora
Copy link
Contributor

@daniepett Can you fix the tests?

@daniepett
Copy link
Contributor Author

Hi @ChrisIsidora, I don't have time until later today. Seems to be all import steps that are failing, so need to figure out the best way to deal with these. Feel free to have a go at them.

@daniepett
Copy link
Contributor Author

@ChrisIsidora @alldoami I've ignored the feature flag for imports, won't affect functionality. It can't be read from current state, so better to use the default false once it's imported.

@ChrisIsidora
Copy link
Contributor

Can we have a ok-to-test @alldoami?

@alldoami
Copy link
Contributor

/ok-to-test sha=0ff1779

@github-actions
Copy link

Integration tests success for 0ff1779

@ChrisIsidora
Copy link
Contributor

@alldoami Can we release a new version? Thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error: 5 or 6 fields allowed (using snowflake_role_grants)
8 participants