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

Importing a procedure no longer works as described in the docs #2722

Closed
VenelinMartinov opened this issue Apr 17, 2024 · 6 comments
Closed
Labels
bug Used to mark issues with provider's incorrect behavior

Comments

@VenelinMartinov
Copy link

VenelinMartinov commented Apr 17, 2024

Terraform CLI and Provider Versions

terraform version
Terraform v1.7.0-dev
on darwin_arm64
+ provider registry.terraform.io/snowflake-labs/snowflake v0.88.0

Terraform Configuration

terraform {
  required_providers {
    snowflake = {
      source  = "Snowflake-Labs/snowflake"
      version = "0.88.0"
    }
  }
}

provider "snowflake" {
}

resource "snowflake_database" "db" {
  name                = "MYDB-2"
}

resource "snowflake_schema" "schema" {
  database            = snowflake_database.db.name
  name                = "MYSCHEMA-2"
  data_retention_days = 1
}

resource "snowflake_procedure" "proc" {
  name     = "SAMPLEPROC3"
  database = snowflake_database.db.name
  schema   = snowflake_schema.schema.name
  language = "JAVASCRIPT"
  arguments {
    name = "arg1"
    type = "varchar"
  }
  arguments {
    name = "arg2"
    type = "DATE"
  }
  comment             = "Procedure with 2 arguments"
  return_type         = "VARCHAR"
  execute_as          = "CALLER"
  null_input_behavior = "RETURNS NULL ON NULL INPUT"
  statement           = <<EOT
var X=1
return X
EOT
}

# import {
#   to = snowflake_procedure.example
#   id = "MYDB-2|MYSCHEMA-2|SAMPLEPROC3|VARCHAR-DATE"
# }

Expected Behavior

Importing the procedure works.

Actual Behavior

It panics with:

snowflake_procedure.example: Preparing import... [id=MYDB-2|MYSCHEMA-2|SAMPLEPROC3|VARCHAR-DATE]
snowflake_database.db: Refreshing state... [id=MYDB-2]
snowflake_procedure.example: Refreshing state... [id=MYDB-2|MYSCHEMA-2|SAMPLEPROC3|VARCHAR-DATE]

Planning failed. Terraform encountered an error while generating this plan.

╷
│ Warning: Argument is deprecated
│
│   with provider["registry.terraform.io/snowflake-labs/snowflake"],
│   on main.tf line 10, in provider "snowflake":
│   10: provider "snowflake" {
│
│ Specify the region as part of the account parameter
╵
╷
│ 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.88.0 plugin:

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

goroutine 44 [running]:
github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk.NewSchemaObjectIdentifierFromFullyQualifiedName({0x14000047ef0?, 0x100441098?})
	github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/identifier_helpers.go:215 +0x344
github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources.ReadContextProcedure({0x1020744b0, 0x140009df880}, 0x14000b7c280, {0x101c8ca00?, 0x140006b91a0?})
	github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources/procedure.go:531 +0xfc
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0x140002462a0, {0x102074408, 0x14000b6ec60}, 0xd?, {0x101c8ca00, 0x140006b91a0})
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.31.0/helper/schema/resource.go:795 +0xe8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0x140002462a0, {0x102074408, 0x14000b6ec60}, 0x140009d8d00, {0x101c8ca00, 0x140006b91a0})
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.31.0/helper/schema/resource.go:1089 +0x430
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0x14000c7e6a8, {0x102074408?, 0x14000b6eb10?}, 0x140007d7e40)
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.31.0/helper/schema/grpc_provider.go:663 +0x3e4
github.com/hashicorp/terraform-plugin-mux/tf5to6server.v5tov6Server.ReadResource({{0x102089b18?, 0x14000c7e6a8?}}, {0x102074408?, 0x14000b6eb10?}, 0x140007d7cc0?)
	github.com/hashicorp/terraform-plugin-mux@v0.13.0/tf5to6server/tf5to6server.go:176 +0x228
github.com/hashicorp/terraform-plugin-mux/tf6muxserver.(*muxServer).ReadResource(0x102074440?, {0x102074408?, 0x14000b6e810?}, 0x140007d7cc0)
	github.com/hashicorp/terraform-plugin-mux@v0.13.0/tf6muxserver/mux_server_ReadResource.go:35 +0x184
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ReadResource(0x14000a44960, {0x102074408?, 0x14000b6e060?}, 0x14000e0b320)
	github.com/hashicorp/terraform-plugin-go@v0.20.0/tfprotov6/tf6server/server.go:787 +0x390
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ReadResource_Handler({0x101fdd4c0?, 0x14000a44960}, {0x102074408, 0x14000b6e060}, 0x14000b7c000, 0x0)
	github.com/hashicorp/terraform-plugin-go@v0.20.0/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:467 +0x164
google.golang.org/grpc.(*Server).processUnaryRPC(0x14000144d20, {0x102074408, 0x14000b1df80}, {0x1020850a0, 0x14000242340}, 0x14000a5c900, 0x14000ccbd10, 0x102f37c88, 0x0)
	google.golang.org/grpc@v1.60.0/server.go:1372 +0xb8c
google.golang.org/grpc.(*Server).handleStream(0x14000144d20, {0x1020850a0, 0x14000242340}, 0x14000a5c900)
	google.golang.org/grpc@v1.60.0/server.go:1783 +0xc4c
google.golang.org/grpc.(*Server).serveStreams.func2.1()
	google.golang.org/grpc@v1.60.0/server.go:1016 +0x5c
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 28
	google.golang.org/grpc@v1.60.0/server.go:1027 +0x138

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

Error: exit status 1

Steps to Reproduce

  1. terraform apply
  2. terraform state rm snowflake_procedure.proc
  3. Uncomment the import, comment out the procedure
  4. terraform plan -generate-config-out=generated.tf
  5. Observe the panic.

How much impact is this issue causing?

High

Logs

No response

Additional Information

note that importing it as id = "MYDB-2.MYSCHEMA-2.SAMPLEPROC3(VARCHAR,DATE)" works, but that does not match the docs: https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/resources/procedure#import

@sfc-gh-asawicki
Copy link
Collaborator

Hey @VenelinMartinov. Thanks for reaching out to us.

This is a duplicate of the thread started here: #993 (comment). It is already fixed in #2697 and will be a part of tomorrow's release. Docs will be updated after the release, the note you attached at the end is the correct syntax after 0.85.0 version.

@VenelinMartinov
Copy link
Author

Thanks for your response @sfc-gh-asawicki, glad to hear the issue is addressed.

What about the panic? That's a pretty bad failure mode and really confusing for users - I only found the correct syntax after reading the code. Would it be possible to add a better error message on a malformed import statement?

@sfc-gh-asawicki
Copy link
Collaborator

This is a valid suggestion. We have it already (better error handling) on our roadmap as part of https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/ROADMAP.md#supporting-all-snowflake-ga-features.

@VenelinMartinov
Copy link
Author

Okay, much appreciated, thanks for your help.

@sfc-gh-asawicki
Copy link
Collaborator

Hey @VenelinMartinov. New version 0.89.0 was released. The docs were updated: https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/resources/procedure#import.

@sfc-gh-asawicki
Copy link
Collaborator

Closing as fixed. Please open a new issue if the problem persists in the newest provider version.

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