Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into sdk-helper-methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jmichalak committed Jan 9, 2025
2 parents 52f603a + 25323da commit 9564cd7
Show file tree
Hide file tree
Showing 36 changed files with 132 additions and 66 deletions.
16 changes: 15 additions & 1 deletion docs/resources/external_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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.
- `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.

Expand Down
13 changes: 12 additions & 1 deletion docs/resources/stage.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ resource "snowflake_stage" "example_stage" {
schema = "EXAMPLE_SCHEMA"
credentials = "AWS_KEY_ID='${var.example_aws_key_id}' AWS_SECRET_KEY='${var.example_aws_secret_key}'"
}
# with an existing hardcoded file format
# please see other examples in the resource documentation
resource "snowflake_stage" "example_stage_with_file_format" {
name = "EXAMPLE_STAGE"
url = "s3://com.example.bucket/prefix"
database = "EXAMPLE_DB"
schema = "EXAMPLE_SCHEMA"
credentials = "AWS_KEY_ID='${var.example_aws_key_id}' AWS_SECRET_KEY='${var.example_aws_secret_key}'"
file_format = "FORMAT_NAME = DB.SCHEMA.FORMATNAME"
}
```

-> **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).
Expand All @@ -43,7 +54,7 @@ resource "snowflake_stage" "example_stage" {
- `credentials` (String, Sensitive) Specifies the credentials for the stage.
- `directory` (String) Specifies the directory settings for the stage.
- `encryption` (String) Specifies the encryption settings for the stage.
- `file_format` (String) Specifies the file format for the stage. Specifying the default Snowflake value (e.g. TYPE = CSV) will currently result in a permadiff (check [#2679](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2679)). For now, omit the default values; it will be fixed in the upcoming provider versions.
- `file_format` (String) Specifies the file format for the stage. Specifying the default Snowflake value (e.g. TYPE = CSV) will currently result in a permadiff (check [#2679](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2679)). For now, omit the default values; it will be fixed in the upcoming provider versions. Examples of usage: <b>1. with hardcoding value:</b> `file_format="FORMAT_NAME = DB.SCHEMA.FORMATNAME"` <b>2. from dynamic value:</b> `file_format = "FORMAT_NAME = ${snowflake_file_format.myfileformat.fully_qualified_name}"` <b>3. from expression:</b> `file_format = format("FORMAT_NAME =%s.%s.MYFILEFORMAT", var.db_name, each.value.schema_name)`. Reference: [#265](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/265)
- `snowflake_iam_user` (String) An AWS IAM user created for your Snowflake account. This user is the same for every external S3 stage created in your account.
- `storage_integration` (String) Specifies the name of the storage integration used to delegate authentication responsibility for external cloud storage to a Snowflake identity and access management (IAM) entity.
- `tag` (Block List, Deprecated) Definitions of a tag to associate with the resource. (see [below for nested schema](#nestedblock--tag))
Expand Down
14 changes: 14 additions & 0 deletions examples/resources/snowflake_external_table/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
11 changes: 11 additions & 0 deletions examples/resources/snowflake_stage/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,14 @@ resource "snowflake_stage" "example_stage" {
schema = "EXAMPLE_SCHEMA"
credentials = "AWS_KEY_ID='${var.example_aws_key_id}' AWS_SECRET_KEY='${var.example_aws_secret_key}'"
}

# with an existing hardcoded file format
# please see other examples in the resource documentation
resource "snowflake_stage" "example_stage_with_file_format" {
name = "EXAMPLE_STAGE"
url = "s3://com.example.bucket/prefix"
database = "EXAMPLE_DB"
schema = "EXAMPLE_SCHEMA"
credentials = "AWS_KEY_ID='${var.example_aws_key_id}' AWS_SECRET_KEY='${var.example_aws_secret_key}'"
file_format = "FORMAT_NAME = DB.SCHEMA.FORMATNAME"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

tfconfig "github.com/hashicorp/terraform-plugin-testing/config"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/collections"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/datatypes"
Expand All @@ -18,7 +17,7 @@ func FunctionJavaBasicInline(
handler string,
functionDefinition string,
) *FunctionJavaModel {
return FunctionJava(resourceName, id.DatabaseName(), handler, id.Name(), returnType.ToSql(), id.SchemaName()).WithFunctionDefinitionValue(config.MultilineWrapperVariable(functionDefinition))
return FunctionJava(resourceName, id.DatabaseName(), handler, id.Name(), returnType.ToSql(), id.SchemaName()).WithFunctionDefinition(functionDefinition)
}

func FunctionJavaBasicStaged(
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package model
import (
tfconfig "github.com/hashicorp/terraform-plugin-testing/config"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/datatypes"
)

func FunctionJavascriptInline(resourceName string, id sdk.SchemaObjectIdentifierWithArguments, functionDefinition string, returnType string) *FunctionJavascriptModel {
return FunctionJavascript(resourceName, id.DatabaseName(), functionDefinition, id.Name(), returnType, id.SchemaName()).
WithFunctionDefinitionValue(config.MultilineWrapperVariable(functionDefinition))
return FunctionJavascript(resourceName, id.DatabaseName(), functionDefinition, id.Name(), returnType, id.SchemaName())
}

func (f *FunctionJavascriptModel) WithArgument(argName string, argDataType datatypes.DataType) *FunctionJavascriptModel {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package model
import (
tfconfig "github.com/hashicorp/terraform-plugin-testing/config"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/collections"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/datatypes"
)

func FunctionPythonBasicInline(resourceName string, id sdk.SchemaObjectIdentifierWithArguments, runtimeVersion string, returnType datatypes.DataType, handler string, functionDefinition string) *FunctionPythonModel {
return FunctionPython(resourceName, id.DatabaseName(), handler, id.Name(), returnType.ToSql(), runtimeVersion, id.SchemaName()).WithFunctionDefinitionValue(config.MultilineWrapperVariable(functionDefinition))
return FunctionPython(resourceName, id.DatabaseName(), handler, id.Name(), returnType.ToSql(), runtimeVersion, id.SchemaName()).WithFunctionDefinition(functionDefinition)
}

func (f *FunctionPythonModel) WithArgument(argName string, argDataType datatypes.DataType) *FunctionPythonModel {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

tfconfig "github.com/hashicorp/terraform-plugin-testing/config"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/collections"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/datatypes"
Expand All @@ -19,7 +18,7 @@ func FunctionScalaBasicInline(
handler string,
functionDefinition string,
) *FunctionScalaModel {
return FunctionScala(resourceName, id.DatabaseName(), handler, id.Name(), returnType.ToSql(), runtimeVersion, id.SchemaName()).WithFunctionDefinitionValue(config.MultilineWrapperVariable(functionDefinition))
return FunctionScala(resourceName, id.DatabaseName(), handler, id.Name(), returnType.ToSql(), runtimeVersion, id.SchemaName()).WithFunctionDefinition(functionDefinition)
}

func (f *FunctionScalaModel) WithArgument(argName string, argDataType datatypes.DataType) *FunctionScalaModel {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package model
import (
tfconfig "github.com/hashicorp/terraform-plugin-testing/config"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/datatypes"
)

func FunctionSqlBasicInline(resourceName string, id sdk.SchemaObjectIdentifierWithArguments, functionDefinition string, returnType string) *FunctionSqlModel {
return FunctionSql(resourceName, id.DatabaseName(), functionDefinition, id.Name(), returnType, id.SchemaName()).
WithFunctionDefinitionValue(config.MultilineWrapperVariable(functionDefinition))
return FunctionSql(resourceName, id.DatabaseName(), functionDefinition, id.Name(), returnType, id.SchemaName())
}

func (f *FunctionSqlModel) WithArgument(argName string, argDataType datatypes.DataType) *FunctionSqlModel {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions pkg/acceptance/bettertestspoc/config/model/gen/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type ResourceConfigBuilderAttributeModel struct {
AttributeType string
Required bool
VariableMethod string
MethodImport string
}

func ModelFromResourceSchemaDetails(resourceSchemaDetails genhelpers.ResourceSchemaDetails) ResourceConfigBuilderModel {
Expand All @@ -38,6 +39,17 @@ func ModelFromResourceSchemaDetails(resourceSchemaDetails genhelpers.ResourceSch
continue
}

if v, ok := multilineAttributesOverrides[resourceSchemaDetails.Name]; ok && slices.Contains(v, attr.Name) && attr.AttributeType == schema.TypeString {
attributes = append(attributes, ResourceConfigBuilderAttributeModel{
Name: attr.Name,
AttributeType: "string",
Required: attr.Required,
VariableMethod: "MultilineWrapperVariable",
MethodImport: "config",
})
continue
}

// TODO [SNOW-1501905]: support the rest of attribute types
var attributeType string
var variableMethod string
Expand All @@ -61,6 +73,7 @@ func ModelFromResourceSchemaDetails(resourceSchemaDetails genhelpers.ResourceSch
AttributeType: attributeType,
Required: attr.Required,
VariableMethod: variableMethod,
MethodImport: "tfconfig",
})
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package gen

var multilineAttributesOverrides = map[string][]string{
"User": {"rsa_public_key", "rsa_public_key_2"},
"ServiceUser": {"rsa_public_key", "rsa_public_key_2"},
"LegacyServiceUser": {"rsa_public_key", "rsa_public_key_2"},
"FunctionJava": {"function_definition"},
"FunctionJavascript": {"function_definition"},
"FunctionPython": {"function_definition"},
"FunctionScala": {"function_definition"},
"FunctionSql": {"function_definition"},
"ProcedureJava": {"procedure_definition"},
"ProcedureJavascript": {"procedure_definition"},
"ProcedurePython": {"procedure_definition"},
"ProcedureScala": {"procedure_definition"},
"ProcedureSql": {"procedure_definition"},
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{{- $attributeNameCamel := SnakeCaseToCamel .Name -}}
{{ if .AttributeType }}
func ({{ $modelVar }} *{{ $modelName }}) With{{ $attributeNameCamel }}({{ FirstLetterLowercase $attributeNameCamel }} {{ .AttributeType }}) *{{ $modelName }} {
{{ $modelVar }}.{{ $attributeNameCamel }} = tfconfig.{{ .VariableMethod }}({{ FirstLetterLowercase $attributeNameCamel }})
{{ $modelVar }}.{{ $attributeNameCamel }} = {{ .MethodImport }}.{{ .VariableMethod }}({{ FirstLetterLowercase $attributeNameCamel }})
return {{ $modelVar }}
}
{{ else }}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package model
import (
tfconfig "github.com/hashicorp/terraform-plugin-testing/config"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/collections"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/datatypes"
Expand All @@ -17,7 +16,7 @@ func ProcedureJavaBasicInline(
procedureDefinition string,
) *ProcedureJavaModel {
return ProcedureJava(resourceName, id.DatabaseName(), handler, id.Name(), returnType.ToSql(), "11", id.SchemaName(), "1.14.0").
WithProcedureDefinitionValue(config.MultilineWrapperVariable(procedureDefinition))
WithProcedureDefinition(procedureDefinition)
}

func ProcedureJavaBasicStaged(
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package model
import (
tfconfig "github.com/hashicorp/terraform-plugin-testing/config"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/datatypes"
)
Expand All @@ -14,8 +13,7 @@ func ProcedureJavascriptBasicInline(
returnType datatypes.DataType,
procedureDefinition string,
) *ProcedureJavascriptModel {
return ProcedureJavascript(resourceName, id.DatabaseName(), id.Name(), procedureDefinition, returnType.ToSql(), id.SchemaName()).
WithProcedureDefinitionValue(config.MultilineWrapperVariable(procedureDefinition))
return ProcedureJavascript(resourceName, id.DatabaseName(), id.Name(), procedureDefinition, returnType.ToSql(), id.SchemaName())
}

func (f *ProcedureJavascriptModel) WithArgument(argName string, argDataType datatypes.DataType) *ProcedureJavascriptModel {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package model
import (
tfconfig "github.com/hashicorp/terraform-plugin-testing/config"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/collections"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/datatypes"
Expand All @@ -17,7 +16,7 @@ func ProcedurePythonBasicInline(
procedureDefinition string,
) *ProcedurePythonModel {
return ProcedurePython(resourceName, id.DatabaseName(), handler, id.Name(), returnType.ToSql(), "3.8", id.SchemaName(), "1.14.0").
WithProcedureDefinitionValue(config.MultilineWrapperVariable(procedureDefinition))
WithProcedureDefinition(procedureDefinition)
}

func (f *ProcedurePythonModel) WithArgument(argName string, argDataType datatypes.DataType) *ProcedurePythonModel {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9564cd7

Please sign in to comment.