Closed jrobison-sb closed 1 month ago
Here is how to reproduce this on-demand with minimal moving parts.
terraform {
required_providers {
snowflake = {
source = "Snowflake-Labs/snowflake"
version = "0.92.0"
}
}
}
resource "snowflake_role" "foo" {
name = "ROLE_ISSUE_3132"
}
resource "snowflake_database" "foo" {
name = "DATABASE_ISSUE_3132"
}
resource "snowflake_schema" "foo" {
database = snowflake_database.foo.name
name = "SCHEMA_ISSUE_3132"
}
resource "snowflake_procedure" "foo" {
name = "PROCEDURE_ISSUE_3132"
database = snowflake_database.foo.name
schema = snowflake_schema.foo.name
language = "JAVASCRIPT"
arguments {
name = "arg1"
type = "varchar"
}
comment = "Procedure with 1 argument"
return_type = "VARCHAR"
execute_as = "OWNER"
statement = <<EOT
var X=1
return X
EOT
}
# terraform state rm snowflake_procedure_grant.foo
resource "snowflake_procedure_grant" "foo" {
database_name = snowflake_procedure.foo.database
schema_name = snowflake_procedure.foo.schema
procedure_name = snowflake_procedure.foo.name
privilege = "USAGE"
argument_data_types = ["string"]
roles = [
snowflake_role.foo.name,
]
}
# terraform import snowflake_grant_privileges_to_account_role.foo[\"ROLE_ISSUE_3132\"] "\"ROLE_ISSUE_3132\"|false|false|USAGE|OnSchemaObject|PROCEDURE|\"DATABASE_ISSUE_3132\".\"SCHEMA_ISSUE_3132\".\"PROCEDURE_ISSUE_3132\""
# resource "snowflake_grant_privileges_to_account_role" "foo" {
# for_each = toset([
# snowflake_role.foo.name,
# ])
# privileges = ["USAGE", ]
# account_role_name = each.key
# on_schema_object {
# object_type = "PROCEDURE"
# object_name = "${snowflake_procedure.foo.database}.${snowflake_procedure.foo.schema}.${snowflake_procedure.foo.name}"
# }
# }
terraform init
.snowflake_procedure_grant.foo
snowflake_grant_privileges_to_account_role.foo
terraform state rm snowflake_procedure_grant.foo
terraform import snowflake_grant_privileges_to_account_role.foo[\"ROLE_ISSUE_3132\"] "\"ROLE_ISSUE_3132\"|false|false|USAGE|OnSchemaObject|PROCEDURE|\"DATABASE_ISSUE_3132\".\"SCHEMA_ISSUE_3132\".\"PROCEDURE_ISSUE_3132\""
(you can try this one with or without slashy escape quotes, it's the same both ways).snowflake_grant_privileges_to_account_role.foo["ROLE_ISSUE_3132"]: Importing from ID "\"ROLE_ISSUE_3132\"|false|false|USAGE|OnSchemaObject|PROCEDURE|\"DATABASE_ISSUE_3132\".\"SCHEMA_ISSUE_3132\".\"PROCEDURE_ISSUE_3132\""...
╷
│ Error: [grant_privileges_to_account_role_identifier.go:196] invalid OnSchemaObjectGrantKind: PROCEDURE
│
│
╵
Hi @jrobison-sb 👋
Thanks for the detailed description. There are two problems here:
fully_qualified_name
field, which is suited for referencing in other resources. Please try something like
object_name = snowflake_procedure.foo.fully_qualified_name
"<account_role_name>|<with_grant_option>|<always_apply>|<privileges>|OnSchemaObject|OnObject|<object_type>|<object_name>"
(see docs). You are missing OnObject
part in your import statements.
@sfc-gh-jmichalak thanks.
I was able to get this to import using:
terraform import snowflake_grant_privileges_to_account_role.foo[\"ROLE_ISSUE_3132\"] "\"ROLE_ISSUE_3132\"|false|false|USAGE|OnSchemaObject|OnObject|PROCEDURE|\"DATABASE_ISSUE_3132\".\"SCHEMA_ISSUE_3132\".\"PROCEDURE_ISSUE_3132\"(VARCHAR)"
In case anyone stumbles upon this from google, the name of the procedure needed to include the argument type ((VARCHAR)
), otherwise the import crashed the provider.
Terraform CLI Version
v1.9.1
Terraform Provider Version
v0.96.0
Terraform Configuration
Old HCL from version 0.92 of the provider:
New resource in 0.96 of the provider:
Category
category:resource
Object type(s)
resource:grant_privileges_to_account_role
Expected Behavior
I should be able to migrate this grant from version 0.92 to version 0.96 by way of
terraform state rm ... && terraform state import ...
as generally described here.Actual Behavior
I have also tried the import using slashy escape quotes around the role name and the object names, but with the same error:
Steps to Reproduce
Try to replace an old
snowflake_procedure_grant
resource with a newsnowflake_grant_privileges_to_account_role
resource by way ofterraform state rm ... && terraform import ...
.How much impact is this issue causing?
Medium
Logs
No response
Additional Information
Here is the old resource as seen in the terraform state:
And as seen in Snowflake:
Would you like to implement a fix?