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

"The session does not have a current database" when creating external table #1040

Open
glittershark opened this issue Jun 3, 2022 · 1 comment
Labels
bug Used to mark issues with provider's incorrect behavior category:resource resource:external_table Issue connected to the snowflake_external_table resource

Comments

@glittershark
Copy link

Provider Version

`0.34.0

Terraform Version

1.1.6

Describe the bug

I've got something that looks like the following, for querying JSON files stored in an s3 bucket:

resource "snowflake_storage_integration" "foo_s3" {
  name    = "FOO_S3"
  type    = "EXTERNAL_STAGE"
  enabled = true

  storage_provider = "S3"
  storage_allowed_locations = [
    "s3://${data.aws_s3_bucket.foo_bucket.bucket}"
  ]
  storage_aws_role_arn = aws_iam_role.snowflake_foo.arn
}

resource "snowflake_database" "foo" {
  name = "FOO"
}

resource "snowflake_stage" "foo_s3" {
  name                = "FOO_S3"
  url                 = "s3://${data.aws_s3_bucket.foo_bucket.bucket}"
  database            = snowflake_database.foo.name
  schema              = "PUBLIC"
  storage_integration = snowflake_storage_integration.foo_s3.name
}

resource "snowflake_external_table" "foo" {
  database    = snowflake_database.foo.name
  schema      = "PUBLIC"
  name        = "FOO"
  file_format = "type = json"
  location    = "@${snowflake_stage.foo_s3.name}"

  column {
    name = "id"
    type = "text"
    as   = "metadata$filename"
  }

  column {
    name = "data"
    type = "variant"
    as   = "value"
  }
}

When I run terraform apply, I get the following error message:

╷
│ Error: error creating externalTable FOO: 090105 (22000): Cannot perform STAGE GET. This session does not have a current database. Call 'USE DATABASE', or use a qualified name.

I've tried replacing the location with @${snowflake_database.foo.name}.${snowflake_stage.foo_s3.name}", but that gave the same error message

Expected behavior

I'd like the external table to create successfully

@glittershark glittershark added the bug Used to mark issues with provider's incorrect behavior label Jun 3, 2022
@glittershark
Copy link
Author

"@${snowflake_database.foo.name}.PUBLIC.${snowflake_stage.foo_s3.name}" fixed it. Maybe this could be documented?

@sfc-gh-jcieslak sfc-gh-jcieslak added category:resource resource:external_table Issue connected to the snowflake_external_table resource labels May 20, 2024
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 category:resource resource:external_table Issue connected to the snowflake_external_table resource
Projects
None yet
Development

No branches or pull requests

2 participants