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

[Bug]: Creating snowflake_stage resource fails when file format is specified #2995

Open
1 task
boseoladipo opened this issue Aug 14, 2024 · 3 comments
Open
1 task
Labels
bug Used to mark issues with provider's incorrect behavior

Comments

@boseoladipo
Copy link

boseoladipo commented Aug 14, 2024

Terraform CLI Version

1.9.4

Terraform Provider Version

0.94.1

Terraform Configuration

Terraform v1.9.4
on darwin_arm64
+ provider registry.terraform.io/hashicorp/aws v4.47.0
+ provider registry.terraform.io/hashicorp/null v3.2.2
+ provider registry.terraform.io/snowflake-labs/snowflake v0.94.1

Category

category:resource

Object type(s)

resource:stage

Expected Behavior

I should be able to create a stage object with a file format.

Actual Behavior

The terraform apply command fails with the error SQL compilation error: File format 'TOK_CONSTANT_LIST' does not exist or not authorized.

Steps to Reproduce

resource "snowflake_file_format" "default" {
name = "EXAMPLE_FILE_FORMAT"
database = "EXAMPLE_DB"
schema = "EXAMPLE_SCHEMA"
format_type = "PARQUET"
compression = "AUTO"
}

resource "snowflake_stage" "default" {
name = "EXAMPLE_STAGE"
url = "s3://EXAMPLE-BUCKET/"
database = "EXAMPLE_DB"
schema = "EXAMPLE_SCHEMA"
file_format = snowflake_file_format.default.name
}

Run terraform apply using the above configuration

How much impact is this issue causing?

Medium

Logs

No response

Additional Information

Looking at query logs in Snowflake, the provider is wrapping the file format name in parentheses and Snowflake interprets this as a list of length one, which is actually a syntax error.
CREATE STAGE "EXAMPLE_DB"."EXAMPLE_SCHEMA"."EXAMPLE_STAGE" URL = 's3://BUCKET/' FILE_FORMAT = (DEFAULT_FILE_FORMAT)

Would you like to implement a fix?

  • Yeah, I'll take it 😎
@boseoladipo boseoladipo added the bug Used to mark issues with provider's incorrect behavior label Aug 14, 2024
@sfc-gh-jmichalak
Copy link
Collaborator

Hi @boseoladipo 👋 According to a note, file format should not be specified in creating stages.

We use old query builders for building queries to Snowflake. This resource will be reworked before v1. We'll examine resource fields and investigate this COPY INTO solution.

Until then, you can use https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/resources/unsafe_execute.

@boseoladipo
Copy link
Author

boseoladipo commented Aug 15, 2024

Hello @sfc-gh-jmichalak, thanks for the quick response

This is the only related note I can see in the shared link.
image

But in the COPY INTO docs formatTypeOptions is in a different category from copyOptions.

@sfc-gh-jmichalak
Copy link
Collaborator

Please take look at examples. Maybe one of them covers your case.

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