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_privileges_to_role crashing when importing #2187

Closed
bert-ciandt opened this issue Nov 10, 2023 · 3 comments
Closed

snowflake_grant_privileges_to_role crashing when importing #2187

bert-ciandt opened this issue Nov 10, 2023 · 3 comments
Labels
bug Used to mark issues with provider's incorrect behavior category:grants

Comments

@bert-ciandt
Copy link

Provider Version

0.75.0

Terraform Version

1.6.3

Describe the bug
When importing a resource with this command (obfuscated):

terraform import 'module.subset_of_developers["USERNAME"].snowflake_grant_privileges_to_role.role_name_with_underscores["<object type plural>"]' "PRE_FIX__ENV_USERNAME_SUF_FIX|USAGE|false|false|false|false|false|true|false|true|||<object type plural>|true|<schema>|false|"

I get this error:

Stack trace from the terraform-provider-snowflake_v0.75.0 plugin:

panic: runtime error: index out of range [1] with length 1

goroutine 240 [running]:
github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk.NewDatabaseObjectIdentifierFromFullyQualifiedName({0x140009ac13f?, 0xc?})
github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/identifier_helpers.go:159 +0xb8
github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources.ReadGrantPrivilegesToRole(0x14000650900, {0x103dacd20?, 0x14000636c30?})
github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources/grant_privileges_to_role.go:562 +0x8dc
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0x103ded840?, {0x103ded840?, 0x14001265ce0?}, 0xd?, {0x103dacd20?, 0x14000636c30?})
github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:783 +0x134
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0x140005f2c40, {0x103ded840, 0x14001265ce0}, 0x14000fa8dd0, {0x103dacd20, 0x14000636c30})
github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:1089 +0x494
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0x140001ea210, {0x103ded840?, 0x14001087770?}, 0x14000c141c0)
github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:649 +0x400
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0x140007ee640, {0x103ded840?, 0x140010869f0?}, 0x14000e82300)
github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:789 +0x3e8
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0x103d5cee0?, 0x140007ee640}, {0x103ded840, 0x140010869f0}, 0x14000ccc0e0, 0x0)
github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:431 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0x1400054d2c0, {0x103dfcee0, 0x140004bc680}, 0x14000fffc20, 0x140005e6a80, 0x104a00ec8, 0x0)
google.golang.org/[email protected]/server.go:1376 +0xbe0
google.golang.org/grpc.(*Server).handleStream(0x1400054d2c0, {0x103dfcee0, 0x140004bc680}, 0x14000fffc20, 0x0)
google.golang.org/[email protected]/server.go:1753 +0x82c
google.golang.org/grpc.(*Server).serveStreams.func1.1()
google.golang.org/[email protected]/server.go:998 +0x84
created by google.golang.org/grpc.(*Server).serveStreams.func1
google.golang.org/[email protected]/server.go:996 +0x16c

Error: The terraform-provider-snowflake_v0.75.0 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

Expected behavior

Successful import of the resource

Code samples and commands

terraform import 'module.subset_of_developers["USERNAME"].snowflake_grant_privileges_to_role.role_name_with_underscores["<object type plural>"]' "PRE_FIX__ENV_USERNAME_SUF_FIX|USAGE|false|false|false|false|false|true|false|true|||<object type plural>|true|<schema>|false|"

Additional context

Changing the object type plural doesn't make a difference. The equivalent SQL command that I'm attempting to replicate is:

grant usage on future <object type plural> in database <db name> to role <user role>

Plenty of other grant_privileges_to_role resources that I've written have worked fine, but this one fails every time. In the code, it's called with a for_each, but it fails whether I run the import in a for loop or as an individual resource.

@bert-ciandt bert-ciandt added the bug Used to mark issues with provider's incorrect behavior label Nov 10, 2023
@antondziubin
Copy link

We have same issue when trying to import snowflake_grant_privileges_to_role.SCHEMA_GRANT

@sfc-gh-jcieslak
Copy link
Collaborator

Hey @bert-ciandt @antondziubin
As snowflake_grant_privileges_to_role is now deprecated could you give us feedback on importing snowflake_grant_privileges_to_account_role? We're not supporting deprecated resources and recommend to use the latest provider version and resources. I propose to close this one and try to use snowflake_grant_privileges_to_account_role and If it has the same issue, open a new ticket.

@sfc-gh-jcieslak
Copy link
Collaborator

Hey 👋
Closing the issue as it's referring to the deprecated resource and we're not supporting them. Please, try to use the latest provider version with the non-deprecated resources. If the issue persists on the non-deprecated resource, please create a new GitHub issue. The migration guide may help during migration to the latest resources.

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
Projects
None yet
Development

No branches or pull requests

3 participants