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_schema crashing when importing #2449

Closed
jmkacz opened this issue Jan 30, 2024 · 9 comments
Closed

snowflake_schema crashing when importing #2449

jmkacz opened this issue Jan 30, 2024 · 9 comments
Labels
general-usage General help/usage questions

Comments

@jmkacz
Copy link

jmkacz commented Jan 30, 2024

Terraform CLI and Provider Versions

Terraform v1.7.1
on darwin_amd64
+ provider registry.terraform.io/hashicorp/tls v4.0.5
+ provider registry.terraform.io/snowflake-labs/snowflake v0.84.1

Terraform Configuration

data "snowflake_database" "mydb" {
  name    = "mydb"
}
import {
  to = snowflake_schema.myschema
  id = "MYSCHEMA"
}
resource "snowflake_schema" "myschema" {
  database   = data.snowflake_database.mydb.name
  name       = "MYSCHEMA"
}

Expected Behavior

terraform plan -generate-config-out generated.tf succeeds and there's a snowflake_schema resource specified in generated.tf

Actual Behavior

snowflake_schema.myschema: Refreshing state... [id=MYSCHEMA]
Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: Plugin did not respond
│
│ The plugin encountered an error, and failed to respond to the plugin6.(*GRPCProvider).ReadResource call. The plugin logs may contain more details.
╵
╷
│ Error: Plugin did not respond
│
│ The plugin encountered an error, and failed to respond to the plugin6.(*GRPCProvider).ReadResource call. The plugin logs may contain more details.
╵

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

panic: interface conversion: sdk.ObjectIdentifier is sdk.AccountObjectIdentifier, not sdk.DatabaseObjectIdentifier

goroutine 98 [running]:
github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources.ReadSchema(0xc000977500, {0x2bc52a0?, 0xc000b9f5f0?})
	github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources/schema.go:108 +0x84a
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0x2f52a28?, {0x2f52a28?, 0xc000d47950?}, 0xd?, {0x2bc52a0?, 0xc000b9f5f0?})
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:783 +0x163
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc000b9a380, {0x2f52a28, 0xc000d47950}, 0xc00091b6c0, {0x2bc52a0, 0xc000b9f5f0})
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:1089 +0x552
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0xc000957d10, {0x2f52a28?, 0xc000d47800?}, 0xc000927f80)
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:663 +0x48a
github.com/hashicorp/terraform-plugin-mux/tf5to6server.v5tov6Server.ReadResource({{0x2f68080?, 0xc000957d10?}}, {0x2f52a28?, 0xc000d47800?}, 0xc000927dc0?)
	github.com/hashicorp/[email protected]/tf5to6server/tf5to6server.go:176 +0x225
github.com/hashicorp/terraform-plugin-mux/tf6muxserver.(*muxServer).ReadResource(0x2f52a60?, {0x2f52a28?, 0xc000d47500?}, 0xc000927dc0)
	github.com/hashicorp/[email protected]/tf6muxserver/mux_server_ReadResource.go:35 +0x193
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ReadResource(0xc000b74280, {0x2f52a28?, 0xc000d46d50?}, 0xc00090b8c0)
	github.com/hashicorp/[email protected]/tfprotov6/tf6server/server.go:787 +0x48b
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ReadResource_Handler({0x2b77380?, 0xc000b74280}, {0x2f52a28, 0xc000d46d50}, 0xc000977200, 0x0)
	github.com/hashicorp/[email protected]/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:467 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0000ccd20, {0x2f52a28, 0xc000d46cc0}, {0x2f633e0, 0xc0006031e0}, 0xc000d4aa20, 0xc00081b440, 0x3f11a08, 0x0)
	google.golang.org/[email protected]/server.go:1372 +0xe03
google.golang.org/grpc.(*Server).handleStream(0xc0000ccd20, {0x2f633e0, 0xc0006031e0}, 0xc000d4aa20)
	google.golang.org/[email protected]/server.go:1783 +0xfec
google.golang.org/grpc.(*Server).serveStreams.func2.1()
	google.golang.org/[email protected]/server.go:1016 +0x59
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 26
	google.golang.org/[email protected]/server.go:1027 +0x115

Error: The terraform-provider-snowflake_v0.84.1 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.

Steps to Reproduce

  1. terraform plan -generate-config-out generated.tf

How much impact is this issue causing?

High

Logs

No response

Additional Information

No response

@jmkacz jmkacz added the bug Used to mark issues with provider's incorrect behavior label Jan 30, 2024
@jmkacz
Copy link
Author

jmkacz commented Jan 30, 2024

I've tested back to v0.74.0. This same error occurs all the way back to v0.76.0. There's a different SIGSEGV error in v0.75.0 and v0.74.0.

@sfc-gh-asawicki
Copy link
Collaborator

Hey @jmkacz. Thanks for reaching out.

You have to use the fully qualified name for the schema (db.schema). Please let me know if that helps.

@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 Jan 31, 2024
@sfc-gh-asawicki
Copy link
Collaborator

Hey @jmkacz. Did you have a chance to test the solution? Can we close the issue?

@gespinal
Copy link

Same issue with schema import on v0.86.0.

@sfc-gh-asawicki
Copy link
Collaborator

@gespinal did you try the above suggestion #2449 (comment)?

@gespinal
Copy link

@sfc-gh-asawicki yeah, it didn't work.

data "snowflake_database" "mydb" {
  name     = "MYDB"
}

import {
  to = snowflake_schema.myschema
  id = "MYDB.MYSCHEMA"
}

resource "snowflake_schema" "myschema" {
  database   = data.snowflake_database.mydb.name
  name       = "MYSCHEMA"
}

@sfc-gh-asawicki
Copy link
Collaborator

Hey @gespinal. I wasn't clear enough. If you check the documentation: https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/resources/schema#import you will see, that the id used for import is | separated. If you will change your code to:

data "snowflake_database" "mydb" {
  name     = "MYDB"
}

import {
  to = snowflake_schema.myschema
  id = "MYDB|MYSCHEMA"
}

resource "snowflake_schema" "myschema" {
  database   = data.snowflake_database.mydb.name
  name       = "MYSCHEMA"
}

it should work like a charm (I tested it myself to be sure).

@gespinal
Copy link

gespinal commented Feb 24, 2024

Thanks very much @sfc-gh-asawicki , validated.

@sfc-gh-asawicki
Copy link
Collaborator

@jmkacz I will close this issue. Please check the solution mentioned and open a new ticket if needed.

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

3 participants