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

[Bug]: terraform import crashing for one of our Snowflake accounts #3402

Open
1 task
polarn opened this issue Feb 20, 2025 · 3 comments
Open
1 task

[Bug]: terraform import crashing for one of our Snowflake accounts #3402

polarn opened this issue Feb 20, 2025 · 3 comments
Labels
bug Used to mark issues with provider's incorrect behavior

Comments

@polarn
Copy link

polarn commented Feb 20, 2025

Terraform CLI Version

1.10.5

Terraform Provider Version

1.0.3

Company Name

Validio AB

Terraform Configuration

resource "snowflake_account" "demo" {
  name                 = "DEMO"
  admin_name           = "terraform"
  admin_rsa_public_key = "removed"
  admin_user_type      = "SERVICE"
  email                = "hello@example.com"
  edition              = "ENTERPRISE"
  region_group         = "PUBLIC"
  region               = "GCP_EUROPE_WEST4"
  # comment              = "SNOWFLAKE" # Not possible to change
  is_org_admin         = "true"
  grace_period_in_days = 7

  lifecycle {
    ignore_changes = [
      region_group,
    ]
  }
}

Category

category:import

Object type(s)

resource:account

Expected Behavior

Expected account to be imported in state when running:

terraform import snowflake_account.demo "<masked>.DEMO"

Actual Behavior

The provider crashes without importing, here is a log output:

2025-02-20T09:43:00.217+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3: 2025/02/20 09:43:00 [DEBUG] sql-conn-query: [query SELECT IS_ROLE_IN_SESSION('"ORGADMIN"') AS IS_ROLE_IN_SESSION --terraform_provider_usage_tracking {"json_schema_version":"1","version":"v1.0.3","resource":"snowflake_account","operation":"import"} err <nil> duration 184.42044ms args {}] (EW61508)
2025-02-20T09:43:00.503+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3: 2025/02/20 09:43:00 [DEBUG] sql-conn-query: [query SHOW ACCOUNTS LIKE 'DEMO' --terraform_provider_usage_tracking {"json_schema_version":"1","version":"v1.0.3","resource":"snowflake_account","operation":"import"} err <nil> duration 284.412593ms args {}] (EW61508)
2025-02-20T09:43:00.504+0100 [TRACE] provider.terraform-provider-snowflake_v1.0.3: Served request: @module=sdk.proto tf_provider_addr=registry.terraform.io/Snowflake-Labs/snowflake tf_req_id=5810f692-d975-ed37-3797-9b4cde18c7d7 @caller=runtime/panic.go:914 tf_proto_version=6.4 tf_resource_type=snowflake_account tf_rpc=ImportResourceState timestamp="2025-02-20T09:43:00.504+0100"
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3: panic: runtime error: invalid memory address or nil pointer dereference
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3: [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1b48093]
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3: goroutine 97 [running]:
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources.ImportAccount({0x273ce18, 0xc001704f60}, 0xc000183380, {0x1ee0ec0?, 0xc000ed97e0?})
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3:      github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources/account.go:210 +0x333
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources.Account.TrackingImportWrapper.func10({0x273ce18, 0xc001704db0}, 0x231d58b?, {0x1ee0ec0, 0xc000ed97e0})
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3:      github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources/common.go:123 +0xeb
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Provider).ImportState(0xc0006e5b60, {0x273ce18, 0xc001704db0}, 0xc001441590, {0xc001710030, 0xc})
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3:      github.com/hashicorp/terraform-plugin-sdk/v2@v2.33.0/helper/schema/provider.go:394 +0x20c
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ImportResourceState(0xc0010a0690, {0x273ce18?, 0xc001704cc0?}, 0xc0017180a0)
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3:      github.com/hashicorp/terraform-plugin-sdk/v2@v2.33.0/helper/schema/grpc_provider.go:1148 +0xe5
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3: github.com/hashicorp/terraform-plugin-mux/tf5to6server.v5tov6Server.ImportResourceState({{0x2755dc0?, 0xc0010a0690?}}, {0x273ce18?, 0xc001704cc0?}, 0xc001718080?)
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3:      github.com/hashicorp/terraform-plugin-mux@v0.15.0/tf5to6server/tf5to6server.go:144 +0xc5
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3: github.com/hashicorp/terraform-plugin-mux/tf6muxserver.(*muxServer).ImportResourceState(0x273ce50?, {0x273ce18?, 0xc0017049c0?}, 0xc001718080)
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3:      github.com/hashicorp/terraform-plugin-mux@v0.15.0/tf6muxserver/mux_server_ImportResourceState.go:36 +0x193
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3: github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ImportResourceState(0xc000c5e6e0, {0x273ce18?, 0xc001704090?}, 0xc00170e000)
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3:      github.com/hashicorp/terraform-plugin-go@v0.22.2/tfprotov6/tf6server/server.go:875 +0x1f3
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3: github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ImportResourceState_Handler({0x227a300?, 0xc000c5e6e0}, {0x273ce18, 0xc001704090}, 0xc000182500, 0x0)
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3:      github.com/hashicorp/terraform-plugin-go@v0.22.2/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:536 +0x169
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3: google.golang.org/grpc.(*Server).processUnaryRPC(0xc000f5de00, {0x273ce18, 0xc001704000}, {0x2751000, 0xc000020300}, 0xc00150fd40, 0xc000c80990, 0x381f830, 0x0)
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3:      google.golang.org/grpc@v1.63.2/server.go:1369 +0xe23
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3: google.golang.org/grpc.(*Server).handleStream(0xc000f5de00, {0x2751000, 0xc000020300}, 0xc00150fd40)
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3:      google.golang.org/grpc@v1.63.2/server.go:1780 +0x1016
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3: google.golang.org/grpc.(*Server).serveStreams.func2.1()
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3:      google.golang.org/grpc@v1.63.2/server.go:1019 +0x8b
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3: created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 68
2025-02-20T09:43:00.508+0100 [DEBUG] provider.terraform-provider-snowflake_v1.0.3:      google.golang.org/grpc@v1.63.2/server.go:1030 +0x135
2025-02-20T09:43:00.509+0100 [ERROR] provider: plugin process exited: plugin=.terraform/providers/registry.terraform.io/snowflake-labs/snowflake/1.0.3/linux_amd64/terraform-provider-snowflake_v1.0.3 id=41714 error="exit status 2"
2025-02-20T09:43:00.509+0100 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2025-02-20T09:43:00.509+0100 [ERROR] plugin6.(*GRPCProvider).ImportResourceState: error="rpc error: code = Unavailable desc = error reading from server: EOF"
2025-02-20T09:43:00.509+0100 [ERROR] vertex "snowflake_account.demo (import id \"<masked>.DEMO\")" error: Plugin did not respond
2025-02-20T09:43:00.509+0100 [TRACE] vertex "snowflake_account.demo (import id \"<masked>.DEMO\")": visit complete, with errors
2025-02-20T09:43:00.509+0100 [TRACE] dag/walk: upstream of "root" errored, so skipping
2025-02-20T09:43:00.509+0100 [TRACE] vertex "snowflake_account.demo (expand)": dynamic subgraph encountered errors: Plugin did not respond
2025-02-20T09:43:00.509+0100 [ERROR] vertex "snowflake_account.demo (expand)" error: Plugin did not respond
2025-02-20T09:43:00.509+0100 [TRACE] vertex "snowflake_account.demo (expand)": visit complete, with errors
2025-02-20T09:43:00.509+0100 [TRACE] dag/walk: upstream of "provider[\"registry.terraform.io/snowflake-labs/snowflake\"] (close)" errored, so skipping
2025-02-20T09:43:00.509+0100 [TRACE] dag/walk: upstream of "root" errored, so skipping
╷
│ Error: Plugin did not respond
│
│ The plugin encountered an error, and failed to respond to the plugin6.(*GRPCProvider).ImportResourceState call. The plugin logs may contain more details.
╵


Stack trace from the terraform-provider-snowflake_v1.0.3 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1b48093]

goroutine 97 [running]:
github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources.ImportAccount({0x273ce18, 0xc001704f60}, 0xc000183380, {0x1ee0ec0?, 0xc000ed97e0?})
        github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources/account.go:210 +0x333
github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources.Account.TrackingImportWrapper.func10({0x273ce18, 0xc001704db0}, 0x231d58b?, {0x1ee0ec0, 0xc000ed97e0})
        github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources/common.go:123 +0xeb
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Provider).ImportState(0xc0006e5b60, {0x273ce18, 0xc001704db0}, 0xc001441590, {0xc001710030, 0xc})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.33.0/helper/schema/provider.go:394 +0x20c
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ImportResourceState(0xc0010a0690, {0x273ce18?, 0xc001704cc0?}, 0xc0017180a0)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.33.0/helper/schema/grpc_provider.go:1148 +0xe5
github.com/hashicorp/terraform-plugin-mux/tf5to6server.v5tov6Server.ImportResourceState({{0x2755dc0?, 0xc0010a0690?}}, {0x273ce18?, 0xc001704cc0?}, 0xc001718080?)
        github.com/hashicorp/terraform-plugin-mux@v0.15.0/tf5to6server/tf5to6server.go:144 +0xc5
github.com/hashicorp/terraform-plugin-mux/tf6muxserver.(*muxServer).ImportResourceState(0x273ce50?, {0x273ce18?, 0xc0017049c0?}, 0xc001718080)
        github.com/hashicorp/terraform-plugin-mux@v0.15.0/tf6muxserver/mux_server_ImportResourceState.go:36 +0x193
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ImportResourceState(0xc000c5e6e0, {0x273ce18?, 0xc001704090?}, 0xc00170e000)
        github.com/hashicorp/terraform-plugin-go@v0.22.2/tfprotov6/tf6server/server.go:875 +0x1f3
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ImportResourceState_Handler({0x227a300?, 0xc000c5e6e0}, {0x273ce18, 0xc001704090}, 0xc000182500, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.22.2/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:536 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000f5de00, {0x273ce18, 0xc001704000}, {0x2751000, 0xc000020300}, 0xc00150fd40, 0xc000c80990, 0x381f830, 0x0)
        google.golang.org/grpc@v1.63.2/server.go:1369 +0xe23
google.golang.org/grpc.(*Server).handleStream(0xc000f5de00, {0x2751000, 0xc000020300}, 0xc00150fd40)
        google.golang.org/grpc@v1.63.2/server.go:1780 +0x1016
google.golang.org/grpc.(*Server).serveStreams.func2.1()
        google.golang.org/grpc@v1.63.2/server.go:1019 +0x8b
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 68
        google.golang.org/grpc@v1.63.2/server.go:1030 +0x135

Error: The terraform-provider-snowflake_v1.0.3 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.

2025-02-20T09:43:00.682+0100 [DEBUG] provider: plugin exited
❯ terraform --version
Terraform v1.10.5
on linux_amd64
+ provider registry.terraform.io/snowflake-labs/snowflake v1.0.3

Steps to Reproduce

Not sure, but maybe trying to import an account with COMMENT=null ?

How much impact is this issue causing?

High

Logs

No response

Additional Information

I have done this for 4 other accounts and it worked well. The only difference for this particular account is that COMMENT is null when issuing SHOW ACCOUNTS in Snowflake, and it's not possible to change that currently.

Would you like to implement a fix?

  • Yeah, I'll take it 😎
@polarn polarn added the bug Used to mark issues with provider's incorrect behavior label Feb 20, 2025
@sfc-gh-jcieslak
Copy link
Collaborator

Hey @polarn 👋
It seems there is an error happening when comment is empty. I'll provide a fix for it. It will be available in the next released version.

@sfc-gh-jcieslak
Copy link
Collaborator

sfc-gh-jcieslak commented Feb 25, 2025

Hi again 👋
The fix will be released tomorrow, it turns out you can create an account with comment being either empty or null by specifying: COMMENT = "" or COMMENT = null. Our code was prepared for the first case, now it should work properly for empty and null comment.

sfc-gh-jcieslak added a commit that referenced this issue Feb 26, 2025
## Changes
Fixes null comment case in the account resource described in
#3402.
Because of the limitation in the terraform testing framework, I couldn't
create an account externally and then import the created account as a
first step of the test (because the testing framework seems to be only
working on already existing objects that can be found in-state). That's
why I had to test this change manually by using `make install-tf` and
using a locally built provider. I confirm that before accounts created
with explicitly null comment `COMMENT = null` were failing and after
applying this change they are not failing anymore.
@sfc-gh-jcieslak
Copy link
Collaborator

Hey @polarn, yesterday we release a new version (1.0.4) that fixes this issue. Please bump and confirm the problem gone. Thanks.

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

No branches or pull requests

2 participants