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

COPY GRANTS option fails on new views #2519

Closed
scastria opened this issue Feb 17, 2024 · 4 comments
Closed

COPY GRANTS option fails on new views #2519

scastria opened this issue Feb 17, 2024 · 4 comments
Labels
general-usage General help/usage questions

Comments

@scastria
Copy link

Terraform CLI and Provider Versions

TF v1.5.2
Snowflake TF 0.80.0

Terraform Configuration

resource "snowflake_view" "CustomerView" {
  provider = snowflake.READER_ACCOUNTADMIN
  for_each = local.customer_views
  database = snowflake_database.CustomerDatabase[split(".", each.key)[0]].name
  schema = snowflake_schema.CustomerSchema[join(".", [split(".", each.key)[0], split(".", each.key)[1]])].name
  name = split(".", each.key)[2]
  statement = <<-SQL
    -- Force a change to the view so that it is recompiled ${timestamp()}
    SELECT * FROM DB_SHARE.${split(".", each.key)[1]}.${split(".", each.key)[2]}
  SQL
  is_secure = true
  copy_grants = true
}

Expected Behavior

View is created successfully

Actual Behavior

verbose TF_LOG shows that the CREATE VIEW statement includes the COPY GRANTS clause since copy_grants = true above. However, since this is a brand new view and NOT a CREATE OR REPLACE, COPY GRANTS is invalid and you get a SQL error of: "Invalid operation COPY GRANTS without specifying source object". Therefore, if the Snowflake provider knows this is a brand new view, then it should omit COPY GRANTS even if copy_grants = true so that valid SQL is produced.

Steps to Reproduce

  1. terraform apply

How much impact is this issue causing?

Medium

Logs

No response

Additional Information

No response

@scastria scastria added the bug Used to mark issues with provider's incorrect behavior label Feb 17, 2024
@sfc-gh-asawicki
Copy link
Collaborator

sfc-gh-asawicki commented Feb 19, 2024

Hey @scastria. Thanks for reaching out to us.

We will visit the topic of COPY GRANTS in general as a part of the upcoming resources redesign. I am not yet convinced which route we should take on this one. Also, the current behavior of the resource is different: when you change the statement, orReplace and copyGrants are added automatically. I think we may even remove these parameters completely from the resource. I will adjust the documentation.

For now, just don't set the copy_grants or set it together with or_replace.

@sfc-gh-asawicki sfc-gh-asawicki added general-usage General help/usage questions and removed bug Used to mark issues with provider's incorrect behavior labels Feb 19, 2024
@sfc-gh-asawicki
Copy link
Collaborator

Also, I see you are using "." splitting in your configurations. Snowflake identifiers are a bit more complex; it's possible to have the dot character as part of the identifier if you have a fully qualified part (wrapped in double quotes). We have the identifiers rework incoming. We want to address the issues our users have with identifiers.

This is just a FYI because these identifiers can really hurt sometimes.

sfc-gh-asawicki added a commit that referenced this issue Feb 23, 2024
sfc-gh-asawicki added a commit that referenced this issue Feb 26, 2024
- Fixed clustering for table_resource (clustering with nested functions
are parsed correctly now)
- Adjusted view resource (`copy_grants` require `or_replace`) and
corrected the documentation

References: #2110 #2495 #2519
@sfc-gh-asawicki
Copy link
Collaborator

Hey @scastria . We have released the fix as part of v0.87.0 release. Please follow the migration guide during the update. Please confirm that the issue is resolved in the newest version. Thanks!

@sfc-gh-asawicki
Copy link
Collaborator

Closing due to inactivity. Please create a new ticket with the newest provider version if the problem is still encountered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
general-usage General help/usage questions
Projects
None yet
Development

No branches or pull requests

2 participants