Skip to content

Commit

Permalink
Merge branch 'dev' into NO-SNOW-extend-docs-for-file-format
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dszmolka authored Jan 9, 2025
2 parents 35db31f + 292d1fe commit 84ca446
Show file tree
Hide file tree
Showing 30 changed files with 78 additions and 62 deletions.
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.

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 ProcedureScalaBasicInline(
procedureDefinition string,
) *ProcedureScalaModel {
return ProcedureScala(resourceName, id.DatabaseName(), handler, id.Name(), returnType.ToSql(), "2.12", id.SchemaName(), "1.14.0").
WithProcedureDefinitionValue(config.MultilineWrapperVariable(procedureDefinition))
WithProcedureDefinition(procedureDefinition)
}

func ProcedureScalaBasicStaged(
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 ProcedureSqlBasicInline(
returnType datatypes.DataType,
procedureDefinition string,
) *ProcedureSqlModel {
return ProcedureSql(resourceName, id.DatabaseName(), id.Name(), procedureDefinition, returnType.ToSql(), id.SchemaName()).
WithProcedureDefinitionValue(config.MultilineWrapperVariable(procedureDefinition))
return ProcedureSql(resourceName, id.DatabaseName(), id.Name(), procedureDefinition, returnType.ToSql(), id.SchemaName())
}

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

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

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

4 changes: 2 additions & 2 deletions pkg/acceptance/bettertestspoc/config/model/user_model_gen.go

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

12 changes: 6 additions & 6 deletions pkg/datasources/users_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func TestAcc_Users_PersonUser(t *testing.T) {
WithDefaultRole("some_role").
WithDefaultSecondaryRolesOptionEnum(sdk.SecondaryRolesOptionAll).
WithMinsToBypassMfa(10).
WithRsaPublicKeyValue(config.MultilineWrapperVariable(key1)).
WithRsaPublicKey2Value(config.MultilineWrapperVariable(key2)).
WithRsaPublicKey(key1).
WithRsaPublicKey2(key2).
WithComment(comment).
WithDisableMfa("true")

Expand Down Expand Up @@ -204,8 +204,8 @@ func TestAcc_Users_ServiceUser(t *testing.T) {
WithDefaultNamespace("some.namespace").
WithDefaultRole("some_role").
WithDefaultSecondaryRolesOptionEnum(sdk.SecondaryRolesOptionAll).
WithRsaPublicKeyValue(config.MultilineWrapperVariable(key1)).
WithRsaPublicKey2Value(config.MultilineWrapperVariable(key2)).
WithRsaPublicKey(key1).
WithRsaPublicKey2(key2).
WithComment(comment)

resource.Test(t, resource.TestCase{
Expand Down Expand Up @@ -364,8 +364,8 @@ func TestAcc_Users_LegacyServiceUser(t *testing.T) {
WithDefaultNamespace("some.namespace").
WithDefaultRole("some_role").
WithDefaultSecondaryRolesOptionEnum(sdk.SecondaryRolesOptionAll).
WithRsaPublicKeyValue(config.MultilineWrapperVariable(key1)).
WithRsaPublicKey2Value(config.MultilineWrapperVariable(key2)).
WithRsaPublicKey(key1).
WithRsaPublicKey2(key2).
WithComment(comment)

resource.Test(t, resource.TestCase{
Expand Down
Loading

0 comments on commit 84ca446

Please sign in to comment.