terraform-provider-snowflake icon indicating copy to clipboard operation
terraform-provider-snowflake copied to clipboard

Crash when creating stream referencing only the schema and name

Open elventear opened this issue 1 year ago • 2 comments

Terraform CLI and Provider Versions

Terraform 1.3.9 Provider: 0.84.1

Terraform Configuration

resource "snowflake_stream" "stream" {
  ...
  on_view     = "SCHEMA.VIEW"
  ...
}

Expected Behavior

When trying to create a stream that references a view using the schema only it should be created.

Actual Behavior

Provider crashes:

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

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

goroutine 91 [running]:
github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources.CreateStream(0x0?, {0x2bc52a0?, 0xc000ca1040})
	github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources/stream.go:171 +0x1a87
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0x2f52a28?, {0x2f52a28?, 0xc000c6dcb0?}, 0xd?, {0x2bc52a0?, 0xc000ca1040?})
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:766 +0x163
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc000b1e9a0, {0x2f52a28, 0xc000c6dcb0}, 0xc000dfeea0, 0xc000df9000, {0x2bc52a0, 0xc000ca1040})
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:909 +0xa89
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc000b0a150, {0x2f52a28?, 0xc000c6db00?}, 0xc000deb720)
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1074 +0xdbc
github.com/hashicorp/terraform-plugin-mux/tf5to6server.v5tov6Server.ApplyResourceChange({{0x2f68080?, 0xc000b0a150?}}, {0x2f52a28, 0xc000c6db00}, 0x0?)
	github.com/hashicorp/[email protected]/tf5to6server/tf5to6server.go:37 +0x54
github.com/hashicorp/terraform-plugin-mux/tf6muxserver.(*muxServer).ApplyResourceChange(0x2f52a60?, {0x2f52a28?, 0xc000c6d800?}, 0xc000deb6d0)
	github.com/hashicorp/[email protected]/tf6muxserver/mux_server_ApplyResourceChange.go:36 +0x193
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ApplyResourceChange(0xc000a5a500, {0x2f52a28?, 0xc000c6ce10?}, 0xc000dd1180)
	github.com/hashicorp/[email protected]/tfprotov6/tf6server/server.go:857 +0x56b
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ApplyResourceChange_Handler({0x2b77380?, 0xc000a5a500}, {0x2f52a28, 0xc000c6ce10}, 0xc000df8800, 0x0)
	github.com/hashicorp/[email protected]/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:503 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000142d20, {0x2f52a28, 0xc000c6cd80}, {0x2f633e0, 0xc000682820}, 0xc000dfb440, 0xc000bed9e0, 0x3f11a38, 0x0)
	google.golang.org/[email protected]/server.go:1372 +0xe03
google.golang.org/grpc.(*Server).handleStream(0xc000142d20, {0x2f633e0, 0xc000682820}, 0xc000dfb440)
	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 49
	google.golang.org/[email protected]/server.go:1027 +0x115

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

Steps to Reproduce

  1. terraform apply

How much impact is this issue causing?

High

Logs

No response

Additional Information

No response

elventear avatar Jan 26 '24 17:01 elventear

Tested with version 0.82, it crashes too.

elventear avatar Jan 26 '24 17:01 elventear

Hey @elventear. Thanks for creating the issue.

This is expected behavior. Currently, the expected view name is a fully qualified one, so you have to write the view identifier as db.schema.view. We have the upcoming identifiers rework (https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/ROADMAP.md#19012024-roadmap-overview), and we will come up with easier usage or at least better errors for such cases.

sfc-gh-asawicki avatar Jan 29 '24 15:01 sfc-gh-asawicki

Hey @elventear 👋 So in v0.90.0 additional validations were added, and now the error messages should look something like this

│ Error: Invalid identifier type
│ 
│   with snowflake_grant_privileges_to_account_role.test,
│   on main.tf line 20, in resource "snowflake_grant_privileges_to_account_role" "test":
│   20:     object_name = "TEST_DATABASE.TEST_SCHEMA.TEST_TABLE.TOO_LONG_ID"
│ 
│ Expected SchemaObjectIdentifier identifier type, but got: sdk.TableColumnIdentifier. The correct form of the fully qualified name for this field is:
│ <database_name>.<schema_name>.<name>, but was <database_name>.<schema_name>.<table_name>.<column_name>

Please confirm and close the ticket, Thank You.

sfc-gh-jcieslak avatar Aug 15 '24 09:08 sfc-gh-jcieslak