Snowflake-Labs / terraform-provider-snowflake

Terraform provider for managing Snowflake accounts
https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest
MIT License
548 stars 419 forks source link

[Bug]: Import snowflake function results in panic #3043

Closed mvecchionespringhealth closed 2 weeks ago

mvecchionespringhealth commented 1 month ago

Terraform CLI Version

1.4.7

Terraform Provider Version

0.92.0

Terraform Configuration

terraform {
  required_version = "~> 1.4.0"
  backend "s3" {
    bucket  = "{bucketName}"
    key     = "{key}"
    region  = "{region}"
    encrypt = true
  }
  required_providers {
    snowflake = {
      source  = "Snowflake-Labs/snowflake"
      version = "0.92.0"
    }
  }
}

provider "snowflake" {
  alias                  = "security_admin"
  ... omitted ...
}

resource "snowflake_function" "function" {
  provider = snowflake.security_admin
  name     = "{functionName}"
  database = "{dbName}"
  schema   = "{schemaName}"
  arguments {
    name = "arg1"
    type = "variant"
  }
  return_type         = "variant"
  null_input_behavior = "RETURNS NULL ON NULL INPUT"
  return_behavior     = "VOLATILE"
  language            = "python"
  runtime_version     = "3.8"
  handler             = "func"
  statement           = <<-EOF
def func(arg1):
  return None
EOF
}

Category

category:import

Object type(s)

resource:function

Expected Behavior

import the resource

Actual Behavior

panic

Steps to Reproduce

Try to import a snowflake_function resource to your state

How much impact is this issue causing?

Medium

Logs

snowflake_function.function: Importing from ID "{dbName}|{schemaName}|FUNC(VARIANT)"...
snowflake_function.function: Import prepared!
  Prepared snowflake_function for import
snowflake_function.function: Refreshing state... [id={dbName}|{schemaName}|FUNC(VARIANT)]
╷
│ 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.92.0 plugin:

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

goroutine 84 [running]:
github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk.NewSchemaObjectIdentifierFromFullyQualifiedName({0x14000a761e0?, 0x104a1bc54?})
        github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/identifier_helpers.go:251 +0x344
github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources.ReadContextFunction({0x10667f8c0, 0x14000d6c9a0}, 0x14000c60c80, {0x1062822c0?, 0x14000119e90?})
        github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources/function.go:521 +0xfc
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0x14000680620, {0x10667f818, 0x14000fdb380}, 0xd?, {0x1062822c0, 0x14000119e90})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.33.0/helper/schema/resource.go:795 +0xe8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0x14000680620, {0x10667f818, 0x14000fdb380}, 0x14000cdaea0, {0x1062822c0, 0x14000119e90})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.33.0/helper/schema/resource.go:1089 +0x430
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0x14000e310c8, {0x10667f818?, 0x14000fdb230?}, 0x14000c3c8c0)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.33.0/helper/schema/grpc_provider.go:667 +0x3e4
github.com/hashicorp/terraform-plugin-mux/tf5to6server.v5tov6Server.ReadResource({{0x106695cf8?, 0x14000e310c8?}}, {0x10667f818?, 0x14000fdb230?}, 0x14000c3c740?)
        github.com/hashicorp/terraform-plugin-mux@v0.15.0/tf5to6server/tf5to6server.go:215 +0x228
github.com/hashicorp/terraform-plugin-mux/tf6muxserver.(*muxServer).ReadResource(0x10667f850?, {0x10667f818?, 0x14000fdaf00?}, 0x14000c3c740)
        github.com/hashicorp/terraform-plugin-mux@v0.15.0/tf6muxserver/mux_server_ReadResource.go:35 +0x184
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ReadResource(0x14000e445a0, {0x10667f818?, 0x14000fda420?}, 0x14000e27260)
        github.com/hashicorp/terraform-plugin-go@v0.22.2/tfprotov6/tf6server/server.go:776 +0x3c4
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ReadResource_Handler({0x1065e6580?, 0x14000e445a0}, {0x10667f818, 0x14000fda420}, 0x14000c60700, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.22.2/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:482 +0x164
google.golang.org/grpc.(*Server).processUnaryRPC(0x14000e32e00, {0x10667f818, 0x14000fda390}, {0x1066911c0, 0x14000026300}, 0x140006f7b00, 0x1400093be00, 0x107487b08, 0x0)
        google.golang.org/grpc@v1.63.2/server.go:1369 +0xba0
google.golang.org/grpc.(*Server).handleStream(0x14000e32e00, {0x1066911c0, 0x14000026300}, 0x140006f7b00)
        google.golang.org/grpc@v1.63.2/server.go:1780 +0xc80
google.golang.org/grpc.(*Server).serveStreams.func2.1()
        google.golang.org/grpc@v1.63.2/server.go:1019 +0x8c
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 72
        google.golang.org/grpc@v1.63.2/server.go:1030 +0x150

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

Additional Information

No response

Would you like to implement a fix?

sfc-gh-asawicki commented 1 month ago

Hey @mvecchionespringhealth. Thanks for reaching out to us.

Your import statement seems incorrect. Please check https://registry.terraform.io/providers/Snowflake-Labs/snowflake/0.92.0/docs/resources/function#import (this resource does not use | for import).

sfc-gh-asawicki commented 2 weeks ago

Closing the issue due to inactivity. Please create a new one if the issue persists in the newest version of the provider.