-
Notifications
You must be signed in to change notification settings - Fork 427
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
[General Usage]: Why do I need to fully qualify snowflake_grant_privileges_to_account_role.account_role_name? #2982
Comments
Hey @jamiekt 👋 import {
for_each = local.monitor_usage_task_roles
to = snowflake_grant_privileges_to_account_role.monitor_usage_task[each.key]
id = "\"${each.key}\"|false|false|MONITOR USAGE|OnAccount"
} wouldn't work. After I take care of other pending cases, I'll take a closer look at this, but it seems like a typical case of quote mismatch case that we have in some of the other resources we're currently fixing. |
Hi @sfc-gh-jcieslak , thank you very much that is much appreciated. Just to clarify, this code: import {
for_each = local.monitor_usage_task_roles
to = snowflake_grant_privileges_to_account_role.monitor_usage_task[each.key]
id = "\"${each.key}\"|false|false|MONITOR USAGE|OnAccount"
} does work. The issue is that I need to use embedded quotes in the value assigned to |
Hi @sfc-gh-jcieslak , Thanks in advance. |
Yeah, I'm currently working on it, and after that change the quoting should not matter. It'll most likely be a part of the next release (somewhere around next week). |
@sfc-gh-jcieslak Awesome, thank you so much. |
@sfc-gh-jcieslak When you release this fix will you also do a patch release for 0.92.X? The reason for my asking is that in my PR which is currently blocked by this I am using removed blocks to remove deprecated resources such as removed {
from = snowflake_account_grant.monitor_task_execution
lifecycle {
destroy = false
}
} For that reason I need to use provider version
However, in the same PR I'm also importing the objects created by the resources that are being removed. import {
for_each = local.monitor_task_execution_roles
to = snowflake_grant_privileges_to_account_role.monitor_task_execution[each.key]
id = "\"${each.key}\"|false|false|MONITOR EXECUTION|OnAccount"
} and this is what is causing the problem that we've discussed above. Hence we'd need a new version of the provider with the fix you're working on now but which is still |
Hey |
Great, thanks @sfc-gh-jcieslak . I'll close this issue and re-open if I find any issues in v.0.95.0 |
Hi @sfc-gh-jcieslak ,
The old code looks like this: resource "snowflake_grant_privileges_to_role" "warehouse_usage_grant" {
for_each = toset(
# logic to determine a list of roles
)
on_account_object {
object_type = "WAREHOUSE"
object_name = snowflake_warehouse.warehouse.name
}
privileges = ["USAGE"]
role_name = each.key
with_grant_option = false
} The new code looks like this: resource "snowflake_grant_privileges_to_account_role" "warehouse_usage_grant" {
for_each = toset(
# logic to determine a list of roles
)
account_role_name = each.key
on_account_object {
object_type = "WAREHOUSE"
object_name = snowflake_warehouse.warehouse.name
}
privileges = ["USAGE"]
with_grant_option = false
}
removed {
from = snowflake_grant_privileges_to_role.warehouse_usage_grant
lifecycle {
destroy = false
}
}
# in consuming root module:
import {
for_each = toset(
# logic to determine roles
)
to = module.resources.module.warehouse[0].snowflake_grant_privileges_to_account_role.warehouse_usage_grant[each.key]
id = "${each.key}|false|false|USAGE|OnAccountObject|WAREHOUSE|WAREHOUSE_NAME"
} There are a lot of resources that we're having to do this for. The aim here is to produce a plan with zero changes but the plan currently looks like this:
and the reason is this quoted identifier problem that we discussed above. We have 205 resources that appear in the plan like this:
Notice that the provider regards these resources as having been changed because of the quoted identifiers. We do not want the grants to be dropped and recreated because that would require downtime, which we absolutely cannot have. Thus, we attempted to upgrade to 0.95.0 (which contains your fix for the quoted identifiers) but that failed with:
which is because resource type hence we're between a rock and a hard place. We can't use 0.92.0 because it would cause all of our resources to be dropped and recreated. We can't use 0.95 because it no longer contains the definition of resource types that are in the state file. Do you have any advice about how to tackle this? |
Hey @jamiekt 👋 |
Thx @sfc-gh-jcieslak , we'll look into doing that. |
Hi @sfc-gh-jcieslak, I'm the Data Ops engineer working with Jamie on this.
This can't work, since these lifecycle arguments just cause the plan to throw errors. From the terraform language docs:
so essentially, if there would be any changes that would destroy assets, the plan and the apply would just fail. I've still tested it (the commit you see above), and confirmed this. Similarly, I think
Can I make a plea for the team to reconsider this decision? Because 0.92.0 -> 0.93.0 introduced a big breaking change with the grants, and also a bug, patching 0.92 with a fix to the bug would allow for a much smoother, one-step upgrade. For context: my team maintains a set of modules and an onboarding template used by >30 teams spread from US to Australia. A 2-step process essentially doubles the effort needed for all of them, you're essentially guaranteeing my team won't get much sleep because someone broke their grants in the middle of the (central Europe) night 😅 Have any SF clients reported issues due to these extraneous quotes? Do we know for sure whether or not this will create duplicate roles with quotes in the actual role name? In other words: if ignore this bug and just leave the extraneous quotes there in the code, will my customers suddenly have e.g. both |
Hey 👋
Then, in this case,
Yes, but in 0.95.0, that's handled, and you can remove the
Yes, that's why we planned to refactor them for a long time, and only recently did we find time to do so. Unfortunately, as the refactoring was concluded recently, only the latest version (0.95.0) has all the changes regarding identifier rework (documented here).
If you refer to Also, I wanted to ask if migrating straight to 0.95.0 is possible? I know that it's not with I hope I addressed all the concerns. Please, try to proceed with migration without the |
That is very good news, thank you @sfc-gh-jcieslak |
@jamiekt Just to show how it behaves I did a simple test resource "snowflake_account_role" "test" {
name = "TEST_ROLE_ONE" # results in TEST_ROLE_ONE (in Snowflake)
}
resource "snowflake_account_role" "test2" {
name = "\"TEST_ROLE_TWO\"" # results in TEST_ROLE_TWO (in Snowflake)
} Adding a third role with role name quoted internally would cause a naming clash with the one that is not quoted resulting in SQL compilation error: resource "snowflake_account_role" "test" {
name = "TEST_ROLE_ONE"
}
resource "snowflake_account_role" "test2" {
name = "\"TEST_ROLE_TWO\""
}
resource "snowflake_account_role" "test3" {
name = "\"TEST_ROLE_ONE\"" # this is the same as the first one
} Hope that helps. |
Closing due to long inactivity. |
Terraform CLI Version
1.9.3
Terraform Provider Version
0.94.1
Terraform Configuration
I have some Snowflake role grants that I want to bring under the control of terraform, so I need to import them. Here is my code:
The resulting plan looks like this for all those roles:
Obviously
# Warning: this will destroy the imported resource
is very worrying, I definitely don't want to do that.I note from https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/resources/grant_privileges_to_account_role#import that
So I change my import block to this (note the new escaped quotes in the id of the import):
The new plan is:
Note the warning, my resource is still going to be destroyed due to the altered
account_role_name
Hence I add the same escaping to
account_role_name
This time my plan looks better
This doesn't feel right though. If I was defining brand new privileges for a role I wouldn't have to wrap
account_role_name
with escaped quotes, so why do I have to do it when importing? That import block will be removed after the objects are imported so I'm left with escaped quotes aroundaccount_role_name
with no real reason for them being there (other than they were required for importing). Moreover, I'm concerned that the role refered to when this gets applied will be"MY_ROLE1"
as opposed to
MY_ROLE1
This seems like a strange stipulation. What is the peculiar circumstance that requires me to use escaped quotes when importing?
Category
category:resource
Object type(s)
resource:grant_privileges_to_account_role
Expected Behavior
I would have expected this code to be sufficient
Actual Behavior
I'm required to use
Steps to Reproduce
Create a role in the Snowflake UI
Use the code provided above to try to import it
How much impact is this issue causing?
Low
Logs
No response
Additional Information
I don't think so, but if other info is required please let me know
The text was updated successfully, but these errors were encountered: