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: Allow multiple resources of the same object grant #824

Merged

Conversation

daniepett
Copy link
Contributor

@daniepett daniepett commented Jan 19, 2022

  • Filtering grants on read to only return those managed by the resource.
  • Updated grantID to contain a list of all the roles in the current grant resource.

These changes allows grants to multiple roles to be done in different resources.

This change comes with the caveat that grants applied OUTSIDE Terraform will not be revoked. This is because the resource won't know if it's maintained by another resource or created elsewhere

Previously the resource id had the structure:
resourceName|schemaName|ObjectName|Privilege|GrantOption
For example: DWH|TEST||USAGE|FALSE

New structure:
resourceName|schemaName|ObjectName|Privilege|Roles|GrantOption

# id = DWH|TEST||USAGE|ROLE_A,ROLE_B|FALSE
resource "snowflake_schema_grant" "grant_a_b" {
  database_name = "DWH"
  schema_name   = "TEST"

  privilege = "USAGE"
  roles     = ["ROLE_A", "ROLE_B"]
  with_grant_option = false
}

# id = DWH|TEST||USAGE|ROLE_C|FALSE
resource "snowflake_schema_grant" "grant_c" {
  database_name = "DWH"
  schema_name   = "TEST"

  privilege = "USAGE"
  roles     = ["ROLE_C"]
  with_grant_option = false
}

Test Plan

  • acceptance tests
  • unit tests

References

@daniepett
Copy link
Contributor Author

@alldoami Any idea of if this will be merged in? If not we'll have to plan workarounds for our RBAC solution.

@alldoami
Copy link
Contributor

alldoami commented Feb 2, 2022

/ok-to-test sha=7e77feb

@github-actions
Copy link

github-actions bot commented Feb 2, 2022

Integration tests success for 7e77feb

Copy link
Contributor

@alldoami alldoami left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ChrisIsidora
Copy link
Contributor

ChrisIsidora commented Mar 14, 2022

@daniepett and @alldoami This change broke my existing Terraform(state) any fix for this or could this be reverted? I keep getting 5 or 6 fields allowed error for my existing snowflake_role_grants resources

@ChrisIsidora
Copy link
Contributor

@alldoami @daniepett We would like to move to version > 0.25.x but this mayor breaking change is blocking, with this change all grant ID's are changed meaning when you run Terraform with has an existing state with the generated ids that predates this commit you can't continue or deploy your resources. Is there an automatic fix for this? If not please revert until there is one

@robbruce
Copy link
Contributor

@alldoami @daniepett @ChrisIsidora - we’re facing the exact same issue. I maybe a state migration function should have been included?

@daniepett
Copy link
Contributor Author

@ChrisIsidora @robbruce I’ll open a PR for a fix in the next couple of days 👍

@daniepett
Copy link
Contributor Author

@alldoami @ChrisIsidora @robbruce PR with a fix is available here #923

@alldoami
Copy link
Contributor

@daniepett just merged! I'll create a release today. @robbruce @ChrisIsidora try out the new release and let us know if you have the same issue!

@ChrisIsidora
Copy link
Contributor

@daniepett Thanks for the quick fix waiting for it to be released to test it.

@ChrisIsidora
Copy link
Contributor

@daniepett and @alldoami This change broke my existing Terraform(state) any fix for this or could this be reverted? I keep getting 5 or 6 fields allowed error for my existing snowflake_role_grants resources

@alldoami @robbruce @daniepett The issue that I pointed up previously with role grants is still not solved in 0.28.7 Please solve and release asap, we are blocked for quite some time now because of this.

@alldoami
Copy link
Contributor

alldoami commented Mar 16, 2022

@daniepett could you take a further look? If we can't get this fixed, wondering if we should revert the changes and test further before merging.

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.

4 participants