terraform-provider-snowflake
terraform-provider-snowflake copied to clipboard
Terraform chrash then we are deploying javascript based stored procedure
Provider Version
VERSION
0.46.0
PUBLISHED
7 days ago
SOURCE CODE
Snowflake-Labs/terraform-provider-snowflake
The provider version you are using.
VERSION
0.46.0
PUBLISHED
7 days ago
SOURCE CODE
Terraform Version
0.15.0
The version of Terraform you were using when the bug was encountered.
0.14
Describe the bug
21:51:05 + /home/jenkins/tools/org.jenkinsci.plugins.terraform.TerraformInstallation/Terraform-14/terraform apply tfplan
21:51:08 snowflake_procedure.get_user_netpolicy: Creating...
21:51:08
21:51:08 Error: rpc error: code = Unavailable desc = transport is closing
21:51:08
21:51:08
21:51:08 panic: runtime error: index out of range [1] with length 0
21:51:08 2022-10-06T18:51:07.972Z [DEBUG] plugin.terraform-provider-snowflake_v0.46.0:
21:51:08 2022-10-06T18:51:07.972Z [DEBUG] plugin.terraform-provider-snowflake_v0.46.0: goroutine 131 [running]:
21:51:08 2022-10-06T18:51:07.972Z [DEBUG] plugin.terraform-provider-snowflake_v0.46.0: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources.ReadProcedure(0xc000748b00, {0x125f9e0?, 0xc000871790})
21:51:08 2022-10-06T18:51:07.972Z [DEBUG] plugin.terraform-provider-snowflake_v0.46.0: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources/procedure.go:274 +0x11c9
21:51:08 2022-10-06T18:51:07.972Z [DEBUG] plugin.terraform-provider-snowflake_v0.46.0: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources.CreateProcedure(0x0?, {0x125f9e0?, 0xc000871790})
21:51:08 2022-10-06T18:51:07.972Z [DEBUG] plugin.terraform-provider-snowflake_v0.46.0: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources/procedure.go:200 +0x5e5
21:51:08 2022-10-06T18:51:07.972Z [DEBUG] plugin.terraform-provider-snowflake_v0.46.0: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0x14b3a80?, {0x14b3a80?, 0xc0004c3c80?}, 0xd?, {0x125f9e0?, 0xc000871790?})
21:51:08 2022-10-06T18:51:07.972Z [DEBUG] plugin.terraform-provider-snowflake_v0.46.0: github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:695 +0x178
21:51:08 2022-10-06T18:51:07.972Z [DEBUG] plugin.terraform-provider-snowflake_v0.46.0: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0003f57a0, {0x14b3a80, 0xc0004c3c80}, 0xc0009841a0, 0xc000748980, {0x125f9e0, 0xc000871790})
21:51:08 2022-10-06T18:51:07.972Z [DEBUG] plugin.terraform-provider-snowflake_v0.46.0: github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:837 +0xa85
21:51:08 2022-10-06T18:51:07.972Z [DEBUG] plugin.terraform-provider-snowflake_v0.46.0: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc00038ff08, {0x14b3a80?, 0xc0004c3b60?}, 0xc00036de00)
21:51:08 2022-10-06T18:51:07.972Z [DEBUG] plugin.terraform-provider-snowflake_v0.46.0: github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1021 +0xe8d
21:51:08 2022-10-06T18:51:07.972Z [DEBUG] plugin.terraform-provider-snowflake_v0.46.0: github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc00071bae0, {0x14b3a80?, 0xc0004c3350?}, 0xc00074c0e0)
21:51:08 2022-10-06T18:51:07.972Z [DEBUG] plugin.terraform-provider-snowflake_v0.46.0: github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:818 +0x574
21:51:08 2022-10-06T18:51:07.972Z [DEBUG] plugin.terraform-provider-snowflake_v0.46.0: github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x122c740?, 0xc00071bae0}, {0x14b3a80, 0xc0004c3350}, 0xc00074c070, 0x0)
21:51:08 2022-10-06T18:51:07.972Z [DEBUG] plugin.terraform-provider-snowflake_v0.46.0: github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170
21:51:08 2022-10-06T18:51:07.972Z [DEBUG] plugin.terraform-provider-snowflake_v0.46.0: google.golang.org/grpc.(*Server).processUnaryRPC(0xc00046a000, {0x14b9440, 0xc0004aa1a0}, 0xc0008ac120, 0xc0003fbbf0, 0x1c19200, 0x0)
21:51:08 2022-10-06T18:51:07.972Z [DEBUG] plugin.terraform-provider-snowflake_v0.46.0: google.golang.org/[email protected]/server.go:1295 +0xb2b
21:51:08 2022-10-06T18:51:07.972Z [DEBUG] plugin.terraform-provider-snowflake_v0.46.0: google.golang.org/grpc.(*Server).handleStream(0xc00046a000, {0x14b9440, 0xc0004aa1a0}, 0xc0008ac120, 0x0)
21:51:08 2022-10-06T18:51:07.972Z [DEBUG] plugin.terraform-provider-snowflake_v0.46.0: google.golang.org/[email protected]/server.go:1636 +0xa2f
21:51:08 2022-10-06T18:51:07.972Z [DEBUG] plugin.terraform-provider-snowflake_v0.46.0: google.golang.org/grpc.(*Server).serveStreams.func1.2()
21:51:08 2022-10-06T18:51:07.972Z [DEBUG] plugin.terraform-provider-snowflake_v0.46.0: google.golang.org/[email protected]/server.go:932 +0x98
21:51:08 2022-10-06T18:51:07.972Z [DEBUG] plugin.terraform-provider-snowflake_v0.46.0: created by google.golang.org/grpc.(*Server).serveStreams.func1
21:51:08 2022-10-06T18:51:07.972Z [DEBUG] plugin.terraform-provider-snowflake_v0.46.0: google.golang.org/[email protected]/server.go:930 +0x28a
21:51:08 2022-10-06T18:51:07.974Z [WARN] plugin.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = transport is closing"
21:51:08 2022/10/06 18:51:07 [DEBUG] snowflake_procedure.get_user_netpolicy: apply errored, but we're indicating that via the Error pointer rather than returning it: rpc error: code = Unavailable desc = transport is closing
21:51:08 2022-10-06T18:51:07.974Z [DEBUG] plugin: plugin process exited: path=.terraform/providers/registry.terraform.io/snowflake-labs/snowflake/0.46.0/linux_amd64/terraform-provider-snowflake_v0.46.0 pid=1009 error="exit status 2"
21:51:08 2022/10/06 18:51:07 [TRACE] EvalMaybeTainted: snowflake_procedure.get_user_netpolicy encountered an error during creation, so it is now marked as tainted
21:51:08 2022/10/06 18:51:07 [TRACE] EvalWriteState: removing state object for snowflake_procedure.get_user_netpolicy
21:51:08 2022/10/06 18:51:07 [TRACE] EvalApplyProvisioners: snowflake_procedure.get_user_netpolicy has no state, so skipping provisioners
21:51:08 2022/10/06 18:51:07 [TRACE] EvalMaybeTainted: snowflake_procedure.get_user_netpolicy encountered an error during creation, so it is now marked as tainted
21:51:08 2022/10/06 18:51:07 [TRACE] EvalWriteState: removing state object for snowflake_procedure.get_user_netpolicy
21:51:08 2022/10/06 18:51:07 [TRACE] vertex "snowflake_procedure.get_user_netpolicy": visit complete
21:51:08 2022/10/06 18:51:07 [TRACE] dag/walk: upstream of "snowflake_procedure_grant.GRANT_CONTROL_DBs_Schemas_UTILITY_get_user_netpolicy" errored, so skipping
21:51:08 2022/10/06 18:51:07 [TRACE] dag/walk: upstream of "provider["registry.terraform.io/snowflake-labs/snowflake"] (close)" errored, so skipping
21:51:08 2022/10/06 18:51:07 [TRACE] dag/walk: upstream of "meta.count-boundary (EachMode fixup)" errored, so skipping
21:51:08 2022/10/06 18:51:07 [TRACE] dag/walk: upstream of "root" errored, so skipping
21:51:08 2022-10-06T18:51:08.172Z [DEBUG] plugin: plugin exited
A clear and concise description of what the bug is.
21:51:08 !!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!
21:51:08
21:51:08 Terraform crashed! This is always indicative of a bug within Terraform.
21:51:08 A crash log has been placed at "crash.log" relative to your current
21:51:08 working directory. It would be immensely helpful if you could please
21:51:08 report the crash with Terraform[1] so that we can fix this.
21:51:08
21:51:08 When reporting bugs, please include your terraform version. That
21:51:08 information is available on the first line of crash.log. You can also
21:51:08 get it by running 'terraform --version' on the command line.
21:51:08
21:51:08 SECURITY WARNING: the "crash.log" file that was created may contain
21:51:08 sensitive information that must be redacted before it is safe to share
21:51:08 on the issue tracker.
21:51:08
21:51:08 [1]: https://github.com/hashicorp/terraform/issues
21:51:08
21:51:08 !!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!
Expected behavior
Stored procedures creating correctly.
A clear and concise description of what you expected to happen.
Code samples and commands resource "snowflake_procedure" "get_user_netpolicy" { name = "GET_USER_NETPOLICY" database = snowflake_database.CONTROL_DB.name schema = snowflake_schema.CONTROL_DBs_Schemas["UTILITY"].name language = "JAVASCRIPT" comment = "List All Users With Assigned Network Policy" return_type = "VARIANT NOT NULL" execute_as = "CALLER" return_behavior = "IMMUTABLE" null_input_behavior = "RETURNS NULL ON NULL INPUT" statement = <<EOT // This variable will hold a JSON data structure that holds ONE row. var rowAsJson = {}; // This array will contain all the rows. var arrayOfRows = []; // This variable will hold a JSON data structure that we can return as // a VARIANT. // This will contain ALL the rows in a single "value". var tableAsJson = {};
// Define initial command to get all user names
var selectUsers = "SELECT name FROM snowflake.account_usage.users where deleted_on is null and name != 'SNOWFLAKE';";
var selectUsersCommand = snowflake.createStatement( {sqlText: selectUsers} );
// Execute the SQL command var userNames = selectUsersCommand.execute();
// Loop through the results, processing one row at a time... while (userNames.next()) { var userName = userNames.getColumnValue(1);
// Add result to json of rows rowAsJson = {}; rowAsJson["name"] = userName;
// Create SQL statement to show network policy
var showPolicy = SHOW PARAMETERS like 'NETWORK_POLICY' for user "
+ userName + ";
;
var showPolicyCommand = snowflake.createStatement( {sqlText: showPolicy} );
showPolicyCommand.execute();
// Use result scan to get the data and account for not truly null values.
// This SQL uses the UNICODE function to workaround a user with no network
// policy not returning a true null value
var getPolicy = SELECT case when unicode("value") = '0' then 'no_policy' else "value" end FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
;
var getPolicyCommand = snowflake.createStatement( {sqlText: getPolicy} );
// Excute command to get network policy var netPolicy = getPolicyCommand.execute(); netPolicy.next(); var netPolicyName = netPolicy.getColumnValue(1);
// Add network policy to JSON rowAsJson["network_policy"] = netPolicyName;
// Add the result to the array of rows arrayOfRows.push(rowAsJson) } tableAsJson = { "users": arrayOfRows } return tableAsJson EOT } Please add code examples and commands that were run to cause the problem.
Additional context
Add any other context about the problem here.
snowflake_procedure
return_behavior = "VOLATILE"
https://docs.snowflake.com/en/sql-reference/sql/create-procedure.html
VOLATILE | IMMUTABLE Deprecated
Attention
These keywords are deprecated for stored procedures. These keywords are not intended to apply to stored procedures. In a future release, these keywords will be removed from the documentation.
@systematics78 : Try changing to return_type = "VARIANT"
(remove the NOT NULL).
@DennGag it is already addressed in provider version 0.47.0