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

snowflake_grant_ownership fails to operate on database roles #2700

Closed
sgrzemski opened this issue Apr 11, 2024 · 5 comments
Closed

snowflake_grant_ownership fails to operate on database roles #2700

sgrzemski opened this issue Apr 11, 2024 · 5 comments
Labels
bug Used to mark issues with provider's incorrect behavior category:grants resource:grant_ownership Issue connected to the snowflake_grant_ownership resource

Comments

@sgrzemski
Copy link

Terraform CLI and Provider Versions

terraform cli:

Terraform v1.6.0
on darwin_arm64

provider versions: 0.88.0

Terraform Configuration

resource "snowflake_grant_ownership" "ownership" {
  provider = snowflake.SYSADMIN_ER

  for_each = { for key, role in snowflake_database_role.this : key => role }

  account_role_name   = data.snowflake_current_role.USERADMIN_ER.name
  outbound_privileges = "COPY"

  on {
    object_type = "DATABASE ROLE"
    object_name = "\"${each.value.database}\".\"${each.value.name}\""
  }
}

Expected Behavior

Ownership of a database role is properly changed.

Actual Behavior

The ownership of a database role is in fact changed, but then the provider fails to verify the ownership:

module.existing_raw_schemas["REDACTED"].snowflake_grant_ownership.read_ownership: Creating...
╷
│ Warning: Applied changes may be incomplete
│ 
│ The plan was created with the -target option in effect, so some changes requested in the configuration may have been ignored and the output values may not be fully
│ updated. Run the following command to verify that no other changes are pending:
│     terraform plan
│       
│ Note that the -target option is not suitable for routine use, and is provided only for exceptional situations such as recovering from errors or mistakes, or when
│ Terraform specifically suggests to use it as part of an error message.
╵
╷
│ Warning: Couldn't find OWNERSHIP privilege on the target object. Marking the resource as removed.

│   with module.existing_raw_schemas["REDACTED"].snowflake_grant_ownership.read_ownership,
│   on .terraform/modules/existing_raw_schemas/readonly_privilege_grants.tf line 1, in resource "snowflake_grant_ownership" "read_ownership":
│    1: resource "snowflake_grant_ownership" "read_ownership" {

│ Id: 


│ Error: Provider produced inconsistent result after apply

│ When applying changes to module.existing_raw_schemas["REDACTED"].snowflake_grant_ownership.read_ownership, provider
│ "provider[\"registry.terraform.io/snowflake-labs/snowflake\"].SYSADMIN_ER" produced an unexpected new value: Root object was present, but now absent.

│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

The issue clearly comes from https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/pkg/resources/grant_ownership.go#L392, which is executed here: https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/pkg/resources/grant_ownership.go#L237. The providers fails to properly read the grants of the database role. The query to retrieve the grants is being formatted properly (show grants on database role...).

Steps to Reproduce

Just run the ownership change on a database role.

How much impact is this issue causing?

High

Logs

No response

Additional Information

I am using two providers, one env oriented sysadmin, one env oriented useradmin. I am trying to change an ownership of a database role from sysadmin (who created it) to useradmin. It changes the ownership, but it fails to verify the changes afterwards.
I think the problem is here: https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/pkg/resources/grant_ownership.go#L377, the GranteeName does not have the Name() method, in opposition to AccountRoleName.

@sgrzemski sgrzemski added the bug Used to mark issues with provider's incorrect behavior label Apr 11, 2024
sgrzemski added a commit to sgrzemski/terraform-provider-snowflake that referenced this issue Apr 11, 2024
The Grants.Show returns GrantedOn == "ROLE" (same in Snowflake UI), but this checks compares "DATABASE ROLE" to "ROLE" and it fails to create the ownership resource.
sgrzemski added a commit to sgrzemski/terraform-provider-snowflake that referenced this issue Apr 11, 2024
The Grants.Show returns GrantedOn == "ROLE" (same in Snowflake UI), but this checks compares "DATABASE ROLE" to "ROLE" and it fails to create the ownership resource.
@sfc-gh-jcieslak
Copy link
Collaborator

@sgrzemski The fix will be most likely released tomorrow

sfc-gh-jcieslak added a commit that referenced this issue Apr 16, 2024
A fix for #2700. Changed expected granted_on when it's equal to the
database role. Acceptance test added.
@sfc-gh-jcieslak
Copy link
Collaborator

Hey, we released a new provider version: https://github.com/Snowflake-Labs/terraform-provider-snowflake/releases/tag/v0.89.0. Please bump and confirm that it works.

@sfc-gh-jcieslak sfc-gh-jcieslak added resource:grant_ownership Issue connected to the snowflake_grant_ownership resource category:grants labels May 20, 2024
@sfc-gh-jcieslak
Copy link
Collaborator

Hey @sgrzemski
Did you have a chance to try the new version with the fix ?

@sgrzemski
Copy link
Author

Sure thing, works like a charm.

@sfc-gh-jcieslak
Copy link
Collaborator

Great, closing the ticket then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Used to mark issues with provider's incorrect behavior category:grants resource:grant_ownership Issue connected to the snowflake_grant_ownership resource
Projects
None yet
Development

No branches or pull requests

2 participants