From f88b0e37e9bac943336ce3ae806c4ef39f1e0b05 Mon Sep 17 00:00:00 2001 From: sfc-gh-dszmolka Date: Sat, 28 Dec 2024 15:36:35 +0100 Subject: [PATCH 1/2] NO-SNOW (issue #1040) add a little bit more clarification how to specify location for the external table --- docs/resources/external_table.md | 2 +- pkg/resources/external_table.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/resources/external_table.md b/docs/resources/external_table.md index f9cd0a5456..3464f936e7 100644 --- a/docs/resources/external_table.md +++ b/docs/resources/external_table.md @@ -44,7 +44,7 @@ resource "snowflake_external_table" "external_table" { - `column` (Block List, Min: 1) Definitions of a column to create in the external table. Minimum one required. (see [below for nested schema](#nestedblock--column)) - `database` (String) The database in which to create the external table. - `file_format` (String) Specifies the file format for the external table. -- `location` (String) Specifies a location for the external table. +- `location` (String) Specifies a location for the external table, using its FQDN. You can hardcode it (`"@MYDB.MYSCHEMA.MYSTAGE"`), or populate dynamically (`"@${snowflake_database.mydb.name}.${snowflake_schema.myschema.name}.${snowflake_stage.mystage.name}"`) - `name` (String) Specifies the identifier for the external table; must be unique for the database and schema in which the externalTable is created. - `schema` (String) The schema in which to create the external table. diff --git a/pkg/resources/external_table.go b/pkg/resources/external_table.go index bd03b75bf6..df8861b273 100644 --- a/pkg/resources/external_table.go +++ b/pkg/resources/external_table.go @@ -76,7 +76,7 @@ var externalTableSchema = map[string]*schema.Schema{ Type: schema.TypeString, Required: true, ForceNew: true, - Description: "Specifies a location for the external table.", + Description: "Specifies a location for the external table, using its FQDN. You can hardcode it (`\"@MYDB.MYSCHEMA.MYSTAGE\"`), or populate dynamically (`\"@${snowflake_database.mydb.name}.${snowflake_schema.myschema.name}.${snowflake_stage.mystage.name}\"`)", }, "file_format": { Type: schema.TypeString, From 550dcf9e033b5b5a179d747db6cb4ea431a41c22 Mon Sep 17 00:00:00 2001 From: sfc-gh-dszmolka Date: Wed, 8 Jan 2025 13:55:05 +0100 Subject: [PATCH 2/2] incorporated review advice: * added example in resource.tf (for snowflake_external_table) * using the preferred format for dynamic value in external_table.go --- docs/resources/external_table.md | 16 +++++++++++++++- .../snowflake_external_table/resource.tf | 14 ++++++++++++++ pkg/resources/external_table.go | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/docs/resources/external_table.md b/docs/resources/external_table.md index 3464f936e7..260806f64b 100644 --- a/docs/resources/external_table.md +++ b/docs/resources/external_table.md @@ -31,6 +31,20 @@ resource "snowflake_external_table" "external_table" { type = "text" } } + +# with a location pointing to an existing stage +# name is hardcoded, please see resource documentation for other options +resource "snowflake_external_table" "external_table_with_location" { + database = "db" + schema = "schema" + name = "external_table_with_location" + location = "@MYDB.MYSCHEMA.MYSTAGE" + + column { + name = "id" + type = "int" + } +} ``` -> **Note** Instead of using fully_qualified_name, you can reference objects managed outside Terraform by constructing a correct ID, consult [identifiers guide](https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/guides/identifiers#new-computed-fully-qualified-name-field-in-resources). @@ -44,7 +58,7 @@ resource "snowflake_external_table" "external_table" { - `column` (Block List, Min: 1) Definitions of a column to create in the external table. Minimum one required. (see [below for nested schema](#nestedblock--column)) - `database` (String) The database in which to create the external table. - `file_format` (String) Specifies the file format for the external table. -- `location` (String) Specifies a location for the external table, using its FQDN. You can hardcode it (`"@MYDB.MYSCHEMA.MYSTAGE"`), or populate dynamically (`"@${snowflake_database.mydb.name}.${snowflake_schema.myschema.name}.${snowflake_stage.mystage.name}"`) +- `location` (String) Specifies a location for the external table, using its FQDN. You can hardcode it (`"@MYDB.MYSCHEMA.MYSTAGE"`), or populate dynamically (`"@${snowflake_stage.mystage.fully_qualified_name}"`) - `name` (String) Specifies the identifier for the external table; must be unique for the database and schema in which the externalTable is created. - `schema` (String) The schema in which to create the external table. diff --git a/examples/resources/snowflake_external_table/resource.tf b/examples/resources/snowflake_external_table/resource.tf index 5f355a14db..3752c04dd8 100644 --- a/examples/resources/snowflake_external_table/resource.tf +++ b/examples/resources/snowflake_external_table/resource.tf @@ -15,3 +15,17 @@ resource "snowflake_external_table" "external_table" { type = "text" } } + +# with a location pointing to an existing stage +# name is hardcoded, please see resource documentation for other options +resource "snowflake_external_table" "external_table_with_location" { + database = "db" + schema = "schema" + name = "external_table_with_location" + location = "@MYDB.MYSCHEMA.MYSTAGE" + + column { + name = "id" + type = "int" + } +} \ No newline at end of file diff --git a/pkg/resources/external_table.go b/pkg/resources/external_table.go index df8861b273..9cdb256359 100644 --- a/pkg/resources/external_table.go +++ b/pkg/resources/external_table.go @@ -76,7 +76,7 @@ var externalTableSchema = map[string]*schema.Schema{ Type: schema.TypeString, Required: true, ForceNew: true, - Description: "Specifies a location for the external table, using its FQDN. You can hardcode it (`\"@MYDB.MYSCHEMA.MYSTAGE\"`), or populate dynamically (`\"@${snowflake_database.mydb.name}.${snowflake_schema.myschema.name}.${snowflake_stage.mystage.name}\"`)", + Description: "Specifies a location for the external table, using its FQDN. You can hardcode it (`\"@MYDB.MYSCHEMA.MYSTAGE\"`), or populate dynamically (`\"@${snowflake_stage.mystage.fully_qualified_name}\"`)", }, "file_format": { Type: schema.TypeString,