From 44ec62620323405aff56e559db7636c92b3152c4 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 17 Jun 2024 21:21:23 +0200 Subject: [PATCH 01/28] generater show output with mappers starts here From 3170d493f94fb43c83eb1cf68990aec940a379a4 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sat, 22 Jun 2024 10:51:08 +0200 Subject: [PATCH 02/28] Print all SDK struct field names with types --- pkg/schemas/gen/main/example.go | 3 + pkg/schemas/gen/main/main.go | 120 +++++++++++++++++++++++ pkg/schemas/gen/show_output_generator.go | 1 + pkg/schemas/gen/util.go | 37 +++++++ pkg/schemas/gen/util_test.go | 33 +++++++ 5 files changed, 194 insertions(+) create mode 100644 pkg/schemas/gen/main/example.go create mode 100644 pkg/schemas/gen/main/main.go create mode 100644 pkg/schemas/gen/show_output_generator.go create mode 100644 pkg/schemas/gen/util.go create mode 100644 pkg/schemas/gen/util_test.go diff --git a/pkg/schemas/gen/main/example.go b/pkg/schemas/gen/main/example.go new file mode 100644 index 0000000000..fd5d40978c --- /dev/null +++ b/pkg/schemas/gen/main/example.go @@ -0,0 +1,3 @@ +package main + +//go:generate go run ./main.go diff --git a/pkg/schemas/gen/main/main.go b/pkg/schemas/gen/main/main.go new file mode 100644 index 0000000000..62d8a35b20 --- /dev/null +++ b/pkg/schemas/gen/main/main.go @@ -0,0 +1,120 @@ +//go:build exclude + +package main + +import ( + "fmt" + "os" + "reflect" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/schemas/gen" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" +) + +var showStructs = []any{ + sdk.Account{}, + sdk.Alert{}, + sdk.ApiIntegration{}, + sdk.ApplicationPackage{}, + sdk.ApplicationRole{}, + sdk.Application{}, + sdk.DatabaseRole{}, + sdk.Database{}, + sdk.DynamicTable{}, + sdk.EventTable{}, + sdk.ExternalFunction{}, + sdk.ExternalTable{}, + sdk.FailoverGroup{}, + sdk.FileFormat{}, + sdk.Function{}, + sdk.Grant{}, + sdk.ManagedAccount{}, + sdk.MaskingPolicy{}, + sdk.MaterializedView{}, + sdk.NetworkPolicy{}, + sdk.NetworkRule{}, + sdk.NotificationIntegration{}, + sdk.Parameter{}, + sdk.PasswordPolicy{}, + sdk.Pipe{}, + sdk.PolicyReference{}, + sdk.Procedure{}, + sdk.ReplicationAccount{}, + sdk.ReplicationDatabase{}, + sdk.Region{}, + sdk.ResourceMonitor{}, + sdk.Role{}, + sdk.RowAccessPolicy{}, + sdk.Schema{}, + sdk.SecurityIntegration{}, + sdk.Sequence{}, + sdk.SessionPolicy{}, + sdk.Share{}, + sdk.Stage{}, + sdk.StorageIntegration{}, + sdk.Streamlit{}, + sdk.Stream{}, + sdk.Table{}, + sdk.Tag{}, + sdk.Task{}, + sdk.User{}, + sdk.View{}, + sdk.Warehouse{}, +} + +func main() { + file := os.Getenv("GOFILE") + fmt.Printf("Running generator on %s with args %#v\n", file, os.Args[1:]) + + for _, s := range showStructs { + printFields(s) + } +} + +// TODO: test completely new struct with: +// - basic type fields (string, int, float, bool) +// - pointer to basic types fields +// - time.Time, *time.Time +// - enum (string and int) +// - slice (string, enum) +// - identifier (each type) +// - slice (identifier) +// - (?) slice of pointers +// - (?) pointer to slice +// - (?) struct +func printFields(s any) { + v := reflect.ValueOf(s) + if v.Kind() == reflect.Pointer { + v = v.Elem() + } + + fmt.Println("===========================") + fmt.Printf("%s\n", v.Type().String()) + fmt.Println("===========================") + + for i := 0; i < v.NumField(); i++ { + currentField := v.Field(i) + currentName := v.Type().Field(i).Name + currentType := v.Type().Field(i).Type.String() + //currentValue := currentField.Interface() + + var kind reflect.Kind + var isPtr bool + + if currentField.Kind() == reflect.Pointer { + isPtr = true + kind = currentField.Type().Elem().Kind() + } else { + kind = currentField.Kind() + } + + var underlyingType string + if isPtr { + underlyingType = "*" + } + underlyingType += kind.String() + + gen.TabularOutput(40, currentName, currentType, underlyingType) + } + fmt.Println() +} diff --git a/pkg/schemas/gen/show_output_generator.go b/pkg/schemas/gen/show_output_generator.go new file mode 100644 index 0000000000..15c192a339 --- /dev/null +++ b/pkg/schemas/gen/show_output_generator.go @@ -0,0 +1 @@ +package gen diff --git a/pkg/schemas/gen/util.go b/pkg/schemas/gen/util.go new file mode 100644 index 0000000000..0c02c1f958 --- /dev/null +++ b/pkg/schemas/gen/util.go @@ -0,0 +1,37 @@ +package gen + +import ( + "fmt" + "regexp" + "strings" +) + +var splitOnTheWordsBeginnings = regexp.MustCompile(`(.)([A-Z][a-z]+)`) +var splitRemainingWordBreaks = regexp.MustCompile("([a-z0-9])([A-Z]+)") + +func ToSnakeCase(str string) string { + wordsSplit := splitOnTheWordsBeginnings.ReplaceAllString(str, "${1}_${2}") + return strings.ToLower(splitRemainingWordBreaks.ReplaceAllString(wordsSplit, "${1}_${2}")) +} + +// TODO: test and describe +func TabularOutput(columnWidth int, columns ...string) { + var sb strings.Builder + for i, column := range columns { + d, rem := DivWithRemainder(columnWidth-len(column), 8) + tabs := d + if rem != 0 { + tabs++ + } + sb.WriteString(column) + if i != len(columns) { + sb.WriteString(strings.Repeat("\t", tabs)) + } + } + fmt.Println(sb.String()) +} + +// TODO: test and describe +func DivWithRemainder(numerator int, denominator int) (int, int) { + return numerator / denominator, numerator % denominator +} diff --git a/pkg/schemas/gen/util_test.go b/pkg/schemas/gen/util_test.go new file mode 100644 index 0000000000..c49575c7ab --- /dev/null +++ b/pkg/schemas/gen/util_test.go @@ -0,0 +1,33 @@ +package gen + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/require" +) + +func Test_ToSnakeCase(t *testing.T) { + + type test struct { + input string + expected string + } + + testCases := []test{ + {input: "CamelCase", expected: "camel_case"}, + {input: "ACamelCase", expected: "a_camel_case"}, + {input: "URLParser", expected: "url_parser"}, + {input: "Camel1Case", expected: "camel1_case"}, + {input: "camelCase", expected: "camel_case"}, + {input: "camelURL", expected: "camel_url"}, + {input: "camelURLSomething", expected: "camel_url_something"}, + } + + for _, tc := range testCases { + t.Run(fmt.Sprintf("%s=>%s", tc.input, tc.expected), func(t *testing.T) { + result := ToSnakeCase(tc.input) + require.Equal(t, tc.expected, result) + }) + } +} From c1ed52fcad9c733a3d6d044ca5f39f8a0b91819b Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sat, 22 Jun 2024 10:54:04 +0200 Subject: [PATCH 03/28] Change tabs to spaces --- pkg/schemas/gen/main/main.go | 2 +- pkg/schemas/gen/util.go | 17 +++-------------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/pkg/schemas/gen/main/main.go b/pkg/schemas/gen/main/main.go index 62d8a35b20..5ebfd0569e 100644 --- a/pkg/schemas/gen/main/main.go +++ b/pkg/schemas/gen/main/main.go @@ -114,7 +114,7 @@ func printFields(s any) { } underlyingType += kind.String() - gen.TabularOutput(40, currentName, currentType, underlyingType) + fmt.Println(gen.ColumnOutput(40, currentName, currentType, underlyingType)) } fmt.Println() } diff --git a/pkg/schemas/gen/util.go b/pkg/schemas/gen/util.go index 0c02c1f958..cae70842be 100644 --- a/pkg/schemas/gen/util.go +++ b/pkg/schemas/gen/util.go @@ -1,7 +1,6 @@ package gen import ( - "fmt" "regexp" "strings" ) @@ -15,23 +14,13 @@ func ToSnakeCase(str string) string { } // TODO: test and describe -func TabularOutput(columnWidth int, columns ...string) { +func ColumnOutput(columnWidth int, columns ...string) string { var sb strings.Builder for i, column := range columns { - d, rem := DivWithRemainder(columnWidth-len(column), 8) - tabs := d - if rem != 0 { - tabs++ - } sb.WriteString(column) if i != len(columns) { - sb.WriteString(strings.Repeat("\t", tabs)) + sb.WriteString(strings.Repeat(" ", columnWidth-len(column))) } } - fmt.Println(sb.String()) -} - -// TODO: test and describe -func DivWithRemainder(numerator int, denominator int) (int, int) { - return numerator / denominator, numerator % denominator + return sb.String() } From 4026d42ba538d4761bdbbf5fa12ee02a0d3e0068 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sat, 22 Jun 2024 11:10:00 +0200 Subject: [PATCH 04/28] Reorganize code --- pkg/schemas/gen/main/main.go | 98 ++------------------- pkg/schemas/gen/sdk_show_result_structs.go | 54 ++++++++++++ pkg/schemas/gen/show_output_generator.go | 1 - pkg/schemas/gen/struct_details_extractor.go | 61 +++++++++++++ pkg/schemas/gen/util.go | 2 +- 5 files changed, 121 insertions(+), 95 deletions(-) create mode 100644 pkg/schemas/gen/sdk_show_result_structs.go delete mode 100644 pkg/schemas/gen/show_output_generator.go create mode 100644 pkg/schemas/gen/struct_details_extractor.go diff --git a/pkg/schemas/gen/main/main.go b/pkg/schemas/gen/main/main.go index 5ebfd0569e..25dc82baca 100644 --- a/pkg/schemas/gen/main/main.go +++ b/pkg/schemas/gen/main/main.go @@ -5,116 +5,28 @@ package main import ( "fmt" "os" - "reflect" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/schemas/gen" - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" ) -var showStructs = []any{ - sdk.Account{}, - sdk.Alert{}, - sdk.ApiIntegration{}, - sdk.ApplicationPackage{}, - sdk.ApplicationRole{}, - sdk.Application{}, - sdk.DatabaseRole{}, - sdk.Database{}, - sdk.DynamicTable{}, - sdk.EventTable{}, - sdk.ExternalFunction{}, - sdk.ExternalTable{}, - sdk.FailoverGroup{}, - sdk.FileFormat{}, - sdk.Function{}, - sdk.Grant{}, - sdk.ManagedAccount{}, - sdk.MaskingPolicy{}, - sdk.MaterializedView{}, - sdk.NetworkPolicy{}, - sdk.NetworkRule{}, - sdk.NotificationIntegration{}, - sdk.Parameter{}, - sdk.PasswordPolicy{}, - sdk.Pipe{}, - sdk.PolicyReference{}, - sdk.Procedure{}, - sdk.ReplicationAccount{}, - sdk.ReplicationDatabase{}, - sdk.Region{}, - sdk.ResourceMonitor{}, - sdk.Role{}, - sdk.RowAccessPolicy{}, - sdk.Schema{}, - sdk.SecurityIntegration{}, - sdk.Sequence{}, - sdk.SessionPolicy{}, - sdk.Share{}, - sdk.Stage{}, - sdk.StorageIntegration{}, - sdk.Streamlit{}, - sdk.Stream{}, - sdk.Table{}, - sdk.Tag{}, - sdk.Task{}, - sdk.User{}, - sdk.View{}, - sdk.Warehouse{}, -} - func main() { file := os.Getenv("GOFILE") fmt.Printf("Running generator on %s with args %#v\n", file, os.Args[1:]) - for _, s := range showStructs { + for _, s := range gen.SdkShowResultStructs { printFields(s) } } -// TODO: test completely new struct with: -// - basic type fields (string, int, float, bool) -// - pointer to basic types fields -// - time.Time, *time.Time -// - enum (string and int) -// - slice (string, enum) -// - identifier (each type) -// - slice (identifier) -// - (?) slice of pointers -// - (?) pointer to slice -// - (?) struct func printFields(s any) { - v := reflect.ValueOf(s) - if v.Kind() == reflect.Pointer { - v = v.Elem() - } + structDetails := gen.ExtractStructDetails(s) fmt.Println("===========================") - fmt.Printf("%s\n", v.Type().String()) + fmt.Printf("%s\n", structDetails.Name) fmt.Println("===========================") - for i := 0; i < v.NumField(); i++ { - currentField := v.Field(i) - currentName := v.Type().Field(i).Name - currentType := v.Type().Field(i).Type.String() - //currentValue := currentField.Interface() - - var kind reflect.Kind - var isPtr bool - - if currentField.Kind() == reflect.Pointer { - isPtr = true - kind = currentField.Type().Elem().Kind() - } else { - kind = currentField.Kind() - } - - var underlyingType string - if isPtr { - underlyingType = "*" - } - underlyingType += kind.String() - - fmt.Println(gen.ColumnOutput(40, currentName, currentType, underlyingType)) + for _, field := range structDetails.Fields { + fmt.Println(gen.ColumnOutput(40, field.Name, field.ConcreteType, field.UnderlyingType)) } fmt.Println() } diff --git a/pkg/schemas/gen/sdk_show_result_structs.go b/pkg/schemas/gen/sdk_show_result_structs.go new file mode 100644 index 0000000000..537c1fcfd8 --- /dev/null +++ b/pkg/schemas/gen/sdk_show_result_structs.go @@ -0,0 +1,54 @@ +package gen + +import "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + +var SdkShowResultStructs = []any{ + sdk.Account{}, + sdk.Alert{}, + sdk.ApiIntegration{}, + sdk.ApplicationPackage{}, + sdk.ApplicationRole{}, + sdk.Application{}, + sdk.DatabaseRole{}, + sdk.Database{}, + sdk.DynamicTable{}, + sdk.EventTable{}, + sdk.ExternalFunction{}, + sdk.ExternalTable{}, + sdk.FailoverGroup{}, + sdk.FileFormat{}, + sdk.Function{}, + sdk.Grant{}, + sdk.ManagedAccount{}, + sdk.MaskingPolicy{}, + sdk.MaterializedView{}, + sdk.NetworkPolicy{}, + sdk.NetworkRule{}, + sdk.NotificationIntegration{}, + sdk.Parameter{}, + sdk.PasswordPolicy{}, + sdk.Pipe{}, + sdk.PolicyReference{}, + sdk.Procedure{}, + sdk.ReplicationAccount{}, + sdk.ReplicationDatabase{}, + sdk.Region{}, + sdk.ResourceMonitor{}, + sdk.Role{}, + sdk.RowAccessPolicy{}, + sdk.Schema{}, + sdk.SecurityIntegration{}, + sdk.Sequence{}, + sdk.SessionPolicy{}, + sdk.Share{}, + sdk.Stage{}, + sdk.StorageIntegration{}, + sdk.Streamlit{}, + sdk.Stream{}, + sdk.Table{}, + sdk.Tag{}, + sdk.Task{}, + sdk.User{}, + sdk.View{}, + sdk.Warehouse{}, +} diff --git a/pkg/schemas/gen/show_output_generator.go b/pkg/schemas/gen/show_output_generator.go deleted file mode 100644 index 15c192a339..0000000000 --- a/pkg/schemas/gen/show_output_generator.go +++ /dev/null @@ -1 +0,0 @@ -package gen diff --git a/pkg/schemas/gen/struct_details_extractor.go b/pkg/schemas/gen/struct_details_extractor.go new file mode 100644 index 0000000000..50b454fc8c --- /dev/null +++ b/pkg/schemas/gen/struct_details_extractor.go @@ -0,0 +1,61 @@ +package gen + +import ( + "reflect" +) + +type Struct struct { + Name string + Fields []Field +} + +type Field struct { + Name string + ConcreteType string + UnderlyingType string +} + +// TODO: test completely new struct with: +// - basic type fields (string, int, float, bool) +// - pointer to basic types fields +// - time.Time, *time.Time +// - enum (string and int) +// - slice (string, enum) +// - identifier (each type) +// - slice (identifier) +// - (?) slice of pointers +// - (?) pointer to slice +// - (?) struct +func ExtractStructDetails(s any) Struct { + v := reflect.ValueOf(s) + if v.Kind() == reflect.Pointer { + v = v.Elem() + } + + fields := make([]Field, v.NumField()) + for i := 0; i < v.NumField(); i++ { + currentField := v.Field(i) + currentName := v.Type().Field(i).Name + currentType := v.Type().Field(i).Type.String() + //currentValue := currentField.Interface() + + var kind reflect.Kind + var isPtr bool + + if currentField.Kind() == reflect.Pointer { + isPtr = true + kind = currentField.Type().Elem().Kind() + } else { + kind = currentField.Kind() + } + + var underlyingType string + if isPtr { + underlyingType = "*" + } + underlyingType += kind.String() + + fields[i] = Field{currentName, currentType, underlyingType} + } + return Struct{v.Type().String(), fields} +} diff --git a/pkg/schemas/gen/util.go b/pkg/schemas/gen/util.go index cae70842be..8701c0e18a 100644 --- a/pkg/schemas/gen/util.go +++ b/pkg/schemas/gen/util.go @@ -18,7 +18,7 @@ func ColumnOutput(columnWidth int, columns ...string) string { var sb strings.Builder for i, column := range columns { sb.WriteString(column) - if i != len(columns) { + if i != len(columns)-1 { sb.WriteString(strings.Repeat(" ", columnWidth-len(column))) } } From 8124687b78ce2c0d708d8cff79f37e1c831d4479 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sat, 22 Jun 2024 11:57:52 +0200 Subject: [PATCH 05/28] Test struct details extractor (WIP) --- pkg/schemas/gen/main/main.go | 30 ++++-- pkg/schemas/gen/struct_details_extractor.go | 11 -- .../gen/struct_details_extractor_test.go | 102 ++++++++++++++++++ 3 files changed, 125 insertions(+), 18 deletions(-) create mode 100644 pkg/schemas/gen/struct_details_extractor_test.go diff --git a/pkg/schemas/gen/main/main.go b/pkg/schemas/gen/main/main.go index 25dc82baca..6661e955d4 100644 --- a/pkg/schemas/gen/main/main.go +++ b/pkg/schemas/gen/main/main.go @@ -5,27 +5,43 @@ package main import ( "fmt" "os" + "slices" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/schemas/gen" + "golang.org/x/exp/maps" ) func main() { file := os.Getenv("GOFILE") fmt.Printf("Running generator on %s with args %#v\n", file, os.Args[1:]) - for _, s := range gen.SdkShowResultStructs { - printFields(s) + uniqueTypes := make(map[string]bool) + allStructsDetails := make([]gen.Struct, len(gen.SdkShowResultStructs)) + for idx, s := range gen.SdkShowResultStructs { + details := gen.ExtractStructDetails(s) + allStructsDetails[idx] = details + printFields(details) + + for _, f := range details.Fields { + uniqueTypes[f.ConcreteType] = true + } + } + fmt.Println("===========================") + fmt.Println("Unique types") + fmt.Println("===========================") + keys := maps.Keys(uniqueTypes) + slices.Sort(keys) + for _, k := range keys { + fmt.Println(k) } } -func printFields(s any) { - structDetails := gen.ExtractStructDetails(s) - +func printFields(s gen.Struct) { fmt.Println("===========================") - fmt.Printf("%s\n", structDetails.Name) + fmt.Printf("%s\n", s.Name) fmt.Println("===========================") - for _, field := range structDetails.Fields { + for _, field := range s.Fields { fmt.Println(gen.ColumnOutput(40, field.Name, field.ConcreteType, field.UnderlyingType)) } fmt.Println() diff --git a/pkg/schemas/gen/struct_details_extractor.go b/pkg/schemas/gen/struct_details_extractor.go index 50b454fc8c..4fca6b448e 100644 --- a/pkg/schemas/gen/struct_details_extractor.go +++ b/pkg/schemas/gen/struct_details_extractor.go @@ -15,17 +15,6 @@ type Field struct { UnderlyingType string } -// TODO: test completely new struct with: -// - basic type fields (string, int, float, bool) -// - pointer to basic types fields -// - time.Time, *time.Time -// - enum (string and int) -// - slice (string, enum) -// - identifier (each type) -// - slice (identifier) -// - (?) slice of pointers -// - (?) pointer to slice -// - (?) struct func ExtractStructDetails(s any) Struct { v := reflect.ValueOf(s) if v.Kind() == reflect.Pointer { diff --git a/pkg/schemas/gen/struct_details_extractor_test.go b/pkg/schemas/gen/struct_details_extractor_test.go new file mode 100644 index 0000000000..b06e29e61e --- /dev/null +++ b/pkg/schemas/gen/struct_details_extractor_test.go @@ -0,0 +1,102 @@ +package gen + +import ( + "testing" + "time" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/stretchr/testify/assert" +) + +// TODO: test completely new struct with: +// - slice (string, enum) +// - slice (identifier) +// - sdk.FileFormatTypeOptions (sql builder struct) +// - sdk.ObjectIdentifier (interface) +// - (?) slice of pointers +// - (?) pointer to slice +func Test_ExtractStructDetails(t *testing.T) { + + type testStruct struct { + unexportedString string + unexportedInt int + unexportedBool bool + unexportedFloat64 float64 + unexportedStringPtr *string + unexportedIntPtr *int + unexportedBoolPtr *bool + unexportedFloat64Ptr *float64 + + unexportedTime time.Time + unexportedTimePtr *time.Time + + unexportedStringEnum sdk.WarehouseType + unexportedStringEnumPtr *sdk.WarehouseType + unexportedIntEnum sdk.ResourceMonitorLevel + unexportedIntEnumPtr *sdk.ResourceMonitorLevel + + unexportedAccountIdentifier sdk.AccountIdentifier + unexportedExternalObjectIdentifier sdk.ExternalObjectIdentifier + unexportedAccountObjectIdentifier sdk.AccountObjectIdentifier + unexportedDatabaseObjectIdentifier sdk.DatabaseObjectIdentifier + unexportedSchemaObjectIdentifier sdk.SchemaObjectIdentifier + unexportedTableColumnIdentifier sdk.TableColumnIdentifier + unexportedAccountIdentifierPtr *sdk.AccountIdentifier + unexportedExternalObjectIdentifierPtr *sdk.ExternalObjectIdentifier + unexportedAccountObjectIdentifierPtr *sdk.AccountObjectIdentifier + unexportedDatabaseObjectIdentifierPtr *sdk.DatabaseObjectIdentifier + unexportedSchemaObjectIdentifierPtr *sdk.SchemaObjectIdentifier + unexportedTableColumnIdentifierPtr *sdk.TableColumnIdentifier + + ExportedString string + ExportedInt int + ExportedBool bool + ExportedFloat64 float64 + ExportedStringPtr *string + ExportedIntPtr *int + ExportedBoolPtr *bool + ExportedFloat64Ptr *float64 + } + + assertFieldExtracted := func(field Field, expectedName string, expectedConcreteType string, expectedUnderlyingType string) { + assert.Equal(t, expectedName, field.Name) + assert.Equal(t, expectedConcreteType, field.ConcreteType) + assert.Equal(t, expectedUnderlyingType, field.UnderlyingType) + } + + t.Run("test struct details extraction", func(t *testing.T) { + structDetails := ExtractStructDetails(testStruct{}) + + assert.Equal(t, structDetails.Name, "gen.testStruct") + + assertFieldExtracted(structDetails.Fields[0], "unexportedString", "string", "string") + assertFieldExtracted(structDetails.Fields[1], "unexportedInt", "int", "int") + assertFieldExtracted(structDetails.Fields[2], "unexportedBool", "bool", "bool") + assertFieldExtracted(structDetails.Fields[3], "unexportedFloat64", "float64", "float64") + assertFieldExtracted(structDetails.Fields[4], "unexportedStringPtr", "*string", "*string") + assertFieldExtracted(structDetails.Fields[5], "unexportedIntPtr", "*int", "*int") + assertFieldExtracted(structDetails.Fields[6], "unexportedBoolPtr", "*bool", "*bool") + assertFieldExtracted(structDetails.Fields[7], "unexportedFloat64Ptr", "*float64", "*float64") + + assertFieldExtracted(structDetails.Fields[8], "unexportedTime", "time.Time", "struct") + assertFieldExtracted(structDetails.Fields[9], "unexportedTimePtr", "*time.Time", "*struct") + + assertFieldExtracted(structDetails.Fields[10], "unexportedStringEnum", "sdk.WarehouseType", "string") + assertFieldExtracted(structDetails.Fields[11], "unexportedStringEnumPtr", "*sdk.WarehouseType", "*string") + assertFieldExtracted(structDetails.Fields[12], "unexportedIntEnum", "sdk.ResourceMonitorLevel", "int") + assertFieldExtracted(structDetails.Fields[13], "unexportedIntEnumPtr", "*sdk.ResourceMonitorLevel", "*int") + + assertFieldExtracted(structDetails.Fields[14], "unexportedAccountIdentifier", "sdk.AccountIdentifier", "struct") + assertFieldExtracted(structDetails.Fields[15], "unexportedExternalObjectIdentifier", "sdk.ExternalObjectIdentifier", "struct") + assertFieldExtracted(structDetails.Fields[16], "unexportedAccountObjectIdentifier", "sdk.AccountObjectIdentifier", "struct") + assertFieldExtracted(structDetails.Fields[17], "unexportedDatabaseObjectIdentifier", "sdk.DatabaseObjectIdentifier", "struct") + assertFieldExtracted(structDetails.Fields[18], "unexportedSchemaObjectIdentifier", "sdk.SchemaObjectIdentifier", "struct") + assertFieldExtracted(structDetails.Fields[19], "unexportedTableColumnIdentifier", "sdk.TableColumnIdentifier", "struct") + assertFieldExtracted(structDetails.Fields[20], "unexportedAccountIdentifierPtr", "*sdk.AccountIdentifier", "*struct") + assertFieldExtracted(structDetails.Fields[21], "unexportedExternalObjectIdentifierPtr", "*sdk.ExternalObjectIdentifier", "*struct") + assertFieldExtracted(structDetails.Fields[22], "unexportedAccountObjectIdentifierPtr", "*sdk.AccountObjectIdentifier", "*struct") + assertFieldExtracted(structDetails.Fields[23], "unexportedDatabaseObjectIdentifierPtr", "*sdk.DatabaseObjectIdentifier", "*struct") + assertFieldExtracted(structDetails.Fields[24], "unexportedSchemaObjectIdentifierPtr", "*sdk.SchemaObjectIdentifier", "*struct") + assertFieldExtracted(structDetails.Fields[25], "unexportedTableColumnIdentifierPtr", "*sdk.TableColumnIdentifier", "*struct") + }) +} From 352739ff3264819fa27891e6b2c8701c8a493090 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sat, 22 Jun 2024 12:08:11 +0200 Subject: [PATCH 06/28] Test struct details extractor All cases from the current show result structs --- .../gen/struct_details_extractor_test.go | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/pkg/schemas/gen/struct_details_extractor_test.go b/pkg/schemas/gen/struct_details_extractor_test.go index b06e29e61e..f3189abb87 100644 --- a/pkg/schemas/gen/struct_details_extractor_test.go +++ b/pkg/schemas/gen/struct_details_extractor_test.go @@ -8,13 +8,13 @@ import ( "github.com/stretchr/testify/assert" ) -// TODO: test completely new struct with: -// - slice (string, enum) -// - slice (identifier) -// - sdk.FileFormatTypeOptions (sql builder struct) -// - sdk.ObjectIdentifier (interface) -// - (?) slice of pointers +// TODO: do we need any of: +// - (?) slice of pointers to interface +// - (?) slice of pointers to structs +// - (?) slice of pointers to basic // - (?) pointer to slice +// +// TODO: test type of slice fields func Test_ExtractStructDetails(t *testing.T) { type testStruct struct { @@ -48,6 +48,14 @@ func Test_ExtractStructDetails(t *testing.T) { unexportedSchemaObjectIdentifierPtr *sdk.SchemaObjectIdentifier unexportedTableColumnIdentifierPtr *sdk.TableColumnIdentifier + unexportedStringSlice []string + unexportedIntSlice []int + unexportedStringEnumSlice []sdk.WarehouseType + unexportedIdentifierSlice []sdk.SchemaObjectIdentifier + + unexportedInterface sdk.ObjectIdentifier + unexportedStruct sdk.FileFormatTypeOptions + ExportedString string ExportedInt int ExportedBool bool @@ -98,5 +106,13 @@ func Test_ExtractStructDetails(t *testing.T) { assertFieldExtracted(structDetails.Fields[23], "unexportedDatabaseObjectIdentifierPtr", "*sdk.DatabaseObjectIdentifier", "*struct") assertFieldExtracted(structDetails.Fields[24], "unexportedSchemaObjectIdentifierPtr", "*sdk.SchemaObjectIdentifier", "*struct") assertFieldExtracted(structDetails.Fields[25], "unexportedTableColumnIdentifierPtr", "*sdk.TableColumnIdentifier", "*struct") + + assertFieldExtracted(structDetails.Fields[26], "unexportedStringSlice", "[]string", "slice") + assertFieldExtracted(structDetails.Fields[27], "unexportedIntSlice", "[]int", "slice") + assertFieldExtracted(structDetails.Fields[28], "unexportedStringEnumSlice", "[]sdk.WarehouseType", "slice") + assertFieldExtracted(structDetails.Fields[29], "unexportedIdentifierSlice", "[]sdk.SchemaObjectIdentifier", "slice") + + assertFieldExtracted(structDetails.Fields[30], "unexportedInterface", "sdk.ObjectIdentifier", "interface") + assertFieldExtracted(structDetails.Fields[31], "unexportedStruct", "sdk.FileFormatTypeOptions", "struct") }) } From 47dffcde65a9577e8aa3d9d9d6f4d8b855d58001 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sat, 22 Jun 2024 12:22:23 +0200 Subject: [PATCH 07/28] Test column output --- pkg/schemas/gen/util.go | 6 ++++-- pkg/schemas/gen/util_test.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/pkg/schemas/gen/util.go b/pkg/schemas/gen/util.go index 8701c0e18a..3b0e5d4737 100644 --- a/pkg/schemas/gen/util.go +++ b/pkg/schemas/gen/util.go @@ -8,18 +8,20 @@ import ( var splitOnTheWordsBeginnings = regexp.MustCompile(`(.)([A-Z][a-z]+)`) var splitRemainingWordBreaks = regexp.MustCompile("([a-z0-9])([A-Z]+)") +// TODO: describe func ToSnakeCase(str string) string { wordsSplit := splitOnTheWordsBeginnings.ReplaceAllString(str, "${1}_${2}") return strings.ToLower(splitRemainingWordBreaks.ReplaceAllString(wordsSplit, "${1}_${2}")) } -// TODO: test and describe +// TODO: describe func ColumnOutput(columnWidth int, columns ...string) string { var sb strings.Builder for i, column := range columns { sb.WriteString(column) if i != len(columns)-1 { - sb.WriteString(strings.Repeat(" ", columnWidth-len(column))) + spaces := max(columnWidth-len(column), 1) + sb.WriteString(strings.Repeat(" ", spaces)) } } return sb.String() diff --git a/pkg/schemas/gen/util_test.go b/pkg/schemas/gen/util_test.go index c49575c7ab..3a2fba257f 100644 --- a/pkg/schemas/gen/util_test.go +++ b/pkg/schemas/gen/util_test.go @@ -2,6 +2,7 @@ package gen import ( "fmt" + "strings" "testing" "github.com/stretchr/testify/require" @@ -31,3 +32,38 @@ func Test_ToSnakeCase(t *testing.T) { }) } } + +func Test_ColumnOutput(t *testing.T) { + spaces := func(count int) string { + return strings.Repeat(" ", count) + } + chars := func(count int) string { + return strings.Repeat("a", count) + } + ten := chars(10) + twenty := chars(20) + + type test struct { + name string + columnWidth int + columns []string + expectedOutput string + } + + testCases := []test{ + {name: "no columns", columnWidth: 16, columns: []string{}, expectedOutput: ""}, + {name: "one column, shorter than width", columnWidth: 16, columns: []string{ten}, expectedOutput: ten}, + {name: "one column, longer than width", columnWidth: 16, columns: []string{twenty}, expectedOutput: twenty}, + {name: "two column, shorter than width", columnWidth: 16, columns: []string{ten, ten}, expectedOutput: ten + spaces(6) + ten}, + {name: "two column, longer than width", columnWidth: 16, columns: []string{twenty, ten}, expectedOutput: twenty + spaces(1) + ten}, + {name: "zero width", columnWidth: 0, columns: []string{ten, ten}, expectedOutput: ten + spaces(1) + ten}, + {name: "negative width", columnWidth: -10, columns: []string{ten, ten}, expectedOutput: ten + spaces(1) + ten}, + } + + for _, tc := range testCases { + t.Run(fmt.Sprintf("%s - column width [%d]", tc.name, tc.columnWidth), func(t *testing.T) { + result := ColumnOutput(tc.columnWidth, tc.columns...) + require.Equal(t, tc.expectedOutput, result) + }) + } +} From f98da5cbb90df26ee1dbc3b09efb769072ec03cb Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 23 Jun 2024 13:48:52 +0200 Subject: [PATCH 08/28] Prepare schema field mapper (WIP) --- pkg/schemas/gen/schema_field_mapper.go | 60 +++++++++++++++++++++ pkg/schemas/gen/schema_field_mapper_test.go | 28 ++++++++++ pkg/schemas/gen/struct_details_extractor.go | 11 ++++ 3 files changed, 99 insertions(+) create mode 100644 pkg/schemas/gen/schema_field_mapper.go create mode 100644 pkg/schemas/gen/schema_field_mapper_test.go diff --git a/pkg/schemas/gen/schema_field_mapper.go b/pkg/schemas/gen/schema_field_mapper.go new file mode 100644 index 0000000000..1cedb61a38 --- /dev/null +++ b/pkg/schemas/gen/schema_field_mapper.go @@ -0,0 +1,60 @@ +package gen + +import ( + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +type Mapper func(string) string + +type SchemaField struct { + Name string + SchemaType schema.ValueType + IsOriginalTypePointer bool + Mapper Mapper +} + +var Identity = func(field string) string { return field } +var ToString = func(field string) string { return fmt.Sprintf("%s.String()", field) } +var FullyQualifiedName = func(field string) string { return fmt.Sprintf("%s.FullyQualifiedName()", field) } +var CastToString = func(field string) string { return fmt.Sprintf("string(%s)", field) } +var CastToInt = func(field string) string { return fmt.Sprintf("int(%s)", field) } + +// TODO: handle other basic type variants +// TODO: handle any other interface (error) +// TODO: handle slices +// TODO: handle structs (chosen one or all) +func MapToSchemaField(field Field) SchemaField { + isPointer := field.IsPointer() + concreteTypeWithoutPtr, _ := strings.CutPrefix(field.ConcreteType, "*") + name := ToSnakeCase(field.Name) + switch concreteTypeWithoutPtr { + case "string": + return SchemaField{name, schema.TypeString, isPointer, Identity} + case "int": + return SchemaField{name, schema.TypeInt, isPointer, Identity} + case "float64": + return SchemaField{name, schema.TypeFloat, isPointer, Identity} + case "bool": + return SchemaField{name, schema.TypeBool, isPointer, Identity} + case "time.Time": + return SchemaField{name, schema.TypeString, isPointer, ToString} + case "sdk.AccountIdentifier", "sdk.ExternalObjectIdentifier", + "sdk.AccountObjectIdentifier", "sdk.DatabaseObjectIdentifier", + "sdk.SchemaObjectIdentifier", "sdk.TableColumnIdentifier": + return SchemaField{name, schema.TypeString, isPointer, FullyQualifiedName} + case "sdk.ObjectIdentifier": + return SchemaField{name, schema.TypeString, isPointer, FullyQualifiedName} + } + + underlyingTypeWithoutPtr, _ := strings.CutPrefix(field.UnderlyingType, "*") + switch { + case strings.HasPrefix(concreteTypeWithoutPtr, "sdk.") && underlyingTypeWithoutPtr == "string": + return SchemaField{name, schema.TypeString, isPointer, CastToString} + case strings.HasPrefix(concreteTypeWithoutPtr, "sdk.") && underlyingTypeWithoutPtr == "int": + return SchemaField{name, schema.TypeInt, isPointer, CastToInt} + } + return SchemaField{name, schema.TypeInvalid, isPointer, Identity} +} diff --git a/pkg/schemas/gen/schema_field_mapper_test.go b/pkg/schemas/gen/schema_field_mapper_test.go new file mode 100644 index 0000000000..ea0824cf10 --- /dev/null +++ b/pkg/schemas/gen/schema_field_mapper_test.go @@ -0,0 +1,28 @@ +package gen + +import ( + "reflect" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/stretchr/testify/assert" +) + +func Test_MapToSchemaField(t *testing.T) { + + assertSchemaFieldMapped := func(schemaField SchemaField, expectedName string, expectedSchemaType schema.ValueType, expectedOriginalPointer bool, expectedMapper Mapper) { + assert.Equal(t, expectedName, schemaField.Name) + assert.Equal(t, expectedSchemaType, schemaField.SchemaType) + assert.Equal(t, expectedOriginalPointer, schemaField.IsOriginalTypePointer) + // TODO: ugly comparison of functions with the current implementation of mapper + assert.Equal(t, reflect.ValueOf(expectedMapper).Pointer(), reflect.ValueOf(schemaField.Mapper).Pointer()) + } + + t.Run("test schema field mapper", func(t *testing.T) { + stringField := Field{"unexportedString", "string", "string"} + + schemaField := MapToSchemaField(stringField) + + assertSchemaFieldMapped(schemaField, "unexported_string", schema.TypeString, false, Identity) + }) +} diff --git a/pkg/schemas/gen/struct_details_extractor.go b/pkg/schemas/gen/struct_details_extractor.go index 4fca6b448e..4ac12a1f92 100644 --- a/pkg/schemas/gen/struct_details_extractor.go +++ b/pkg/schemas/gen/struct_details_extractor.go @@ -2,6 +2,7 @@ package gen import ( "reflect" + "strings" ) type Struct struct { @@ -15,6 +16,16 @@ type Field struct { UnderlyingType string } +// TODO: test +func (f *Field) IsPointer() bool { + return strings.HasPrefix(f.ConcreteType, "*") +} + +// TODO: test +func (f *Field) IsSlice() bool { + return strings.HasPrefix(f.ConcreteType, "[]") +} + func ExtractStructDetails(s any) Struct { v := reflect.ValueOf(s) if v.Kind() == reflect.Pointer { From aa6ac60eb61e925fbaf40d0d1ac82878c7686060 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 23 Jun 2024 15:36:46 +0200 Subject: [PATCH 09/28] Test all currently implemented schema types --- pkg/schemas/gen/schema_field_mapper_test.go | 144 ++++++++++++++++++-- 1 file changed, 133 insertions(+), 11 deletions(-) diff --git a/pkg/schemas/gen/schema_field_mapper_test.go b/pkg/schemas/gen/schema_field_mapper_test.go index ea0824cf10..368d499745 100644 --- a/pkg/schemas/gen/schema_field_mapper_test.go +++ b/pkg/schemas/gen/schema_field_mapper_test.go @@ -1,6 +1,7 @@ package gen import ( + "fmt" "reflect" "testing" @@ -10,19 +11,140 @@ import ( func Test_MapToSchemaField(t *testing.T) { - assertSchemaFieldMapped := func(schemaField SchemaField, expectedName string, expectedSchemaType schema.ValueType, expectedOriginalPointer bool, expectedMapper Mapper) { - assert.Equal(t, expectedName, schemaField.Name) - assert.Equal(t, expectedSchemaType, schemaField.SchemaType) - assert.Equal(t, expectedOriginalPointer, schemaField.IsOriginalTypePointer) - // TODO: ugly comparison of functions with the current implementation of mapper - assert.Equal(t, reflect.ValueOf(expectedMapper).Pointer(), reflect.ValueOf(schemaField.Mapper).Pointer()) + type expectedValues struct { + name string + schemaType schema.ValueType + isPointer bool + mapper Mapper + } + + testCases := []struct { + field Field + expected expectedValues + }{ + { + field: Field{"unexportedString", "string", "string"}, + expected: expectedValues{"unexported_string", schema.TypeString, false, Identity}, + }, + { + field: Field{"unexportedInt", "int", "int"}, + expected: expectedValues{"unexported_int", schema.TypeInt, false, Identity}, + }, + { + field: Field{"unexportedBool", "bool", "bool"}, + expected: expectedValues{"unexported_bool", schema.TypeBool, false, Identity}, + }, + { + field: Field{"unexportedFloat64", "float64", "float64"}, + expected: expectedValues{"unexported_float64", schema.TypeFloat, false, Identity}, + }, + { + field: Field{"unexportedStringPtr", "*string", "*string"}, + expected: expectedValues{"unexported_string_ptr", schema.TypeString, true, Identity}, + }, + { + field: Field{"unexportedIntPtr", "*int", "*int"}, + expected: expectedValues{"unexported_int_ptr", schema.TypeInt, true, Identity}, + }, + { + field: Field{"unexportedBoolPtr", "*bool", "*bool"}, + expected: expectedValues{"unexported_bool_ptr", schema.TypeBool, true, Identity}, + }, + { + field: Field{"unexportedFloat64Ptr", "*float64", "*float64"}, + expected: expectedValues{"unexported_float64_ptr", schema.TypeFloat, true, Identity}, + }, + { + field: Field{"unexportedTime", "time.Time", "struct"}, + expected: expectedValues{"unexported_time", schema.TypeString, false, ToString}, + }, + { + field: Field{"unexportedTimePtr", "*time.Time", "*struct"}, + expected: expectedValues{"unexported_time_ptr", schema.TypeString, true, ToString}, + }, + { + field: Field{"unexportedStringEnum", "sdk.WarehouseType", "string"}, + expected: expectedValues{"unexported_string_enum", schema.TypeString, false, CastToString}, + }, + { + field: Field{"unexportedStringEnumPtr", "*sdk.WarehouseType", "*string"}, + expected: expectedValues{"unexported_string_enum_ptr", schema.TypeString, true, CastToString}, + }, + { + field: Field{"unexportedIntEnum", "sdk.ResourceMonitorLevel", "int"}, + expected: expectedValues{"unexported_int_enum", schema.TypeInt, false, CastToInt}, + }, + { + field: Field{"unexportedIntEnumPtr", "*sdk.ResourceMonitorLevel", "*int"}, + expected: expectedValues{"unexported_int_enum_ptr", schema.TypeInt, true, CastToInt}, + }, + { + field: Field{"unexportedAccountIdentifier", "sdk.AccountIdentifier", "struct"}, + expected: expectedValues{"unexported_account_identifier", schema.TypeString, false, FullyQualifiedName}, + }, + { + field: Field{"unexportedExternalObjectIdentifier", "sdk.ExternalObjectIdentifier", "struct"}, + expected: expectedValues{"unexported_external_object_identifier", schema.TypeString, false, FullyQualifiedName}, + }, + { + field: Field{"unexportedAccountObjectIdentifier", "sdk.AccountObjectIdentifier", "struct"}, + expected: expectedValues{"unexported_account_object_identifier", schema.TypeString, false, FullyQualifiedName}, + }, + { + field: Field{"unexportedDatabaseObjectIdentifier", "sdk.DatabaseObjectIdentifier", "struct"}, + expected: expectedValues{"unexported_database_object_identifier", schema.TypeString, false, FullyQualifiedName}, + }, + { + field: Field{"unexportedSchemaObjectIdentifier", "sdk.SchemaObjectIdentifier", "struct"}, + expected: expectedValues{"unexported_schema_object_identifier", schema.TypeString, false, FullyQualifiedName}, + }, + { + field: Field{"unexportedTableColumnIdentifier", "sdk.TableColumnIdentifier", "struct"}, + expected: expectedValues{"unexported_table_column_identifier", schema.TypeString, false, FullyQualifiedName}, + }, + { + field: Field{"unexportedAccountIdentifierPtr", "*sdk.AccountIdentifier", "*struct"}, + expected: expectedValues{"unexported_account_identifier_ptr", schema.TypeString, true, FullyQualifiedName}, + }, + { + field: Field{"unexportedExternalObjectIdentifierPtr", "*sdk.ExternalObjectIdentifier", "*struct"}, + expected: expectedValues{"unexported_external_object_identifier_ptr", schema.TypeString, true, FullyQualifiedName}, + }, + { + field: Field{"unexportedAccountObjectIdentifierPtr", "*sdk.AccountObjectIdentifier", "*struct"}, + expected: expectedValues{"unexported_account_object_identifier_ptr", schema.TypeString, true, FullyQualifiedName}, + }, + { + field: Field{"unexportedDatabaseObjectIdentifierPtr", "*sdk.DatabaseObjectIdentifier", "*struct"}, + expected: expectedValues{"unexported_database_object_identifier_ptr", schema.TypeString, true, FullyQualifiedName}, + }, + { + field: Field{"unexportedSchemaObjectIdentifierPtr", "*sdk.SchemaObjectIdentifier", "*struct"}, + expected: expectedValues{"unexported_schema_object_identifier_ptr", schema.TypeString, true, FullyQualifiedName}, + }, + { + field: Field{"unexportedTableColumnIdentifierPtr", "*sdk.TableColumnIdentifier", "*struct"}, + expected: expectedValues{"unexported_table_column_identifier_ptr", schema.TypeString, true, FullyQualifiedName}, + }, + { + field: Field{"unexportedInterface", "sdk.ObjectIdentifier", "interface"}, + expected: expectedValues{"unexported_interface", schema.TypeString, false, FullyQualifiedName}, + }, } - t.Run("test schema field mapper", func(t *testing.T) { - stringField := Field{"unexportedString", "string", "string"} + assertSchemaFieldMapped := func(schemaField SchemaField, expected expectedValues) { + assert.Equal(t, expected.name, schemaField.Name) + assert.Equal(t, expected.schemaType, schemaField.SchemaType) + assert.Equal(t, expected.isPointer, schemaField.IsOriginalTypePointer) + // TODO: ugly comparison of functions with the current implementation of mapper + assert.Equal(t, reflect.ValueOf(expected.mapper).Pointer(), reflect.ValueOf(schemaField.Mapper).Pointer()) + } - schemaField := MapToSchemaField(stringField) + for _, tc := range testCases { + t.Run(fmt.Sprintf("%s", tc.field.Name), func(t *testing.T) { + schemaField := MapToSchemaField(tc.field) - assertSchemaFieldMapped(schemaField, "unexported_string", schema.TypeString, false, Identity) - }) + assertSchemaFieldMapped(schemaField, tc.expected) + }) + } } From c902e23d74017413844870ddfa22249d9f0b3005 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 23 Jun 2024 15:41:36 +0200 Subject: [PATCH 10/28] Prepare model for generation (WIP) --- pkg/schemas/gen/model.go | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 pkg/schemas/gen/model.go diff --git a/pkg/schemas/gen/model.go b/pkg/schemas/gen/model.go new file mode 100644 index 0000000000..3695e09461 --- /dev/null +++ b/pkg/schemas/gen/model.go @@ -0,0 +1,6 @@ +package gen + +type ShowResultSchemaModel struct { + Name string + SchemaFields []SchemaField +} From 8b1b7c4671ad44378465bb0a3c04c5a31ada6284 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 23 Jun 2024 18:06:17 +0200 Subject: [PATCH 11/28] Print generated schemas and mappers --- pkg/schemas/gen/main/main.go | 16 ++++++++++ pkg/schemas/gen/model.go | 17 ++++++++++ pkg/schemas/gen/schema_field_mapper.go | 21 +++++++------ pkg/schemas/gen/schema_field_mapper_test.go | 5 +-- pkg/schemas/gen/templates.go | 31 +++++++++++++++++++ pkg/schemas/gen/templates/schema.tmpl | 11 +++++++ .../gen/templates/to_schema_mapper.tmpl | 11 +++++++ 7 files changed, 100 insertions(+), 12 deletions(-) create mode 100644 pkg/schemas/gen/templates.go create mode 100644 pkg/schemas/gen/templates/schema.tmpl create mode 100644 pkg/schemas/gen/templates/to_schema_mapper.tmpl diff --git a/pkg/schemas/gen/main/main.go b/pkg/schemas/gen/main/main.go index 6661e955d4..5e9a880bc3 100644 --- a/pkg/schemas/gen/main/main.go +++ b/pkg/schemas/gen/main/main.go @@ -4,6 +4,7 @@ package main import ( "fmt" + "log" "os" "slices" @@ -34,6 +35,21 @@ func main() { for _, k := range keys { fmt.Println(k) } + + fmt.Println("===========================") + fmt.Println("Generated") + fmt.Println("===========================") + for _, details := range allStructsDetails { + model := gen.ModelFromStructDetails(details) + err := gen.SchemaTemplate.Execute(os.Stdout, model) + if err != nil { + log.Panicln(err) + } + err = gen.ToSchemaMapperTemplate.Execute(os.Stdout, model) + if err != nil { + log.Panicln(err) + } + } } func printFields(s gen.Struct) { diff --git a/pkg/schemas/gen/model.go b/pkg/schemas/gen/model.go index 3695e09461..2e4c850fb1 100644 --- a/pkg/schemas/gen/model.go +++ b/pkg/schemas/gen/model.go @@ -1,6 +1,23 @@ package gen +import "strings" + type ShowResultSchemaModel struct { Name string + SdkType string SchemaFields []SchemaField } + +func ModelFromStructDetails(sdkStruct Struct) ShowResultSchemaModel { + name, _ := strings.CutPrefix(sdkStruct.Name, "sdk.") + schemaFields := make([]SchemaField, len(sdkStruct.Fields)) + for idx, field := range sdkStruct.Fields { + schemaFields[idx] = MapToSchemaField(field) + } + + return ShowResultSchemaModel{ + Name: name, + SdkType: sdkStruct.Name, + SchemaFields: schemaFields, + } +} diff --git a/pkg/schemas/gen/schema_field_mapper.go b/pkg/schemas/gen/schema_field_mapper.go index 1cedb61a38..c034e0ddb5 100644 --- a/pkg/schemas/gen/schema_field_mapper.go +++ b/pkg/schemas/gen/schema_field_mapper.go @@ -12,6 +12,7 @@ type Mapper func(string) string type SchemaField struct { Name string SchemaType schema.ValueType + OriginalName string IsOriginalTypePointer bool Mapper Mapper } @@ -32,29 +33,29 @@ func MapToSchemaField(field Field) SchemaField { name := ToSnakeCase(field.Name) switch concreteTypeWithoutPtr { case "string": - return SchemaField{name, schema.TypeString, isPointer, Identity} + return SchemaField{name, schema.TypeString, field.Name, isPointer, Identity} case "int": - return SchemaField{name, schema.TypeInt, isPointer, Identity} + return SchemaField{name, schema.TypeInt, field.Name, isPointer, Identity} case "float64": - return SchemaField{name, schema.TypeFloat, isPointer, Identity} + return SchemaField{name, schema.TypeFloat, field.Name, isPointer, Identity} case "bool": - return SchemaField{name, schema.TypeBool, isPointer, Identity} + return SchemaField{name, schema.TypeBool, field.Name, isPointer, Identity} case "time.Time": - return SchemaField{name, schema.TypeString, isPointer, ToString} + return SchemaField{name, schema.TypeString, field.Name, isPointer, ToString} case "sdk.AccountIdentifier", "sdk.ExternalObjectIdentifier", "sdk.AccountObjectIdentifier", "sdk.DatabaseObjectIdentifier", "sdk.SchemaObjectIdentifier", "sdk.TableColumnIdentifier": - return SchemaField{name, schema.TypeString, isPointer, FullyQualifiedName} + return SchemaField{name, schema.TypeString, field.Name, isPointer, FullyQualifiedName} case "sdk.ObjectIdentifier": - return SchemaField{name, schema.TypeString, isPointer, FullyQualifiedName} + return SchemaField{name, schema.TypeString, field.Name, isPointer, FullyQualifiedName} } underlyingTypeWithoutPtr, _ := strings.CutPrefix(field.UnderlyingType, "*") switch { case strings.HasPrefix(concreteTypeWithoutPtr, "sdk.") && underlyingTypeWithoutPtr == "string": - return SchemaField{name, schema.TypeString, isPointer, CastToString} + return SchemaField{name, schema.TypeString, field.Name, isPointer, CastToString} case strings.HasPrefix(concreteTypeWithoutPtr, "sdk.") && underlyingTypeWithoutPtr == "int": - return SchemaField{name, schema.TypeInt, isPointer, CastToInt} + return SchemaField{name, schema.TypeInt, field.Name, isPointer, CastToInt} } - return SchemaField{name, schema.TypeInvalid, isPointer, Identity} + return SchemaField{name, schema.TypeInvalid, field.Name, isPointer, Identity} } diff --git a/pkg/schemas/gen/schema_field_mapper_test.go b/pkg/schemas/gen/schema_field_mapper_test.go index 368d499745..2b193197c8 100644 --- a/pkg/schemas/gen/schema_field_mapper_test.go +++ b/pkg/schemas/gen/schema_field_mapper_test.go @@ -132,9 +132,10 @@ func Test_MapToSchemaField(t *testing.T) { }, } - assertSchemaFieldMapped := func(schemaField SchemaField, expected expectedValues) { + assertSchemaFieldMapped := func(schemaField SchemaField, originalField Field, expected expectedValues) { assert.Equal(t, expected.name, schemaField.Name) assert.Equal(t, expected.schemaType, schemaField.SchemaType) + assert.Equal(t, originalField.Name, schemaField.OriginalName) assert.Equal(t, expected.isPointer, schemaField.IsOriginalTypePointer) // TODO: ugly comparison of functions with the current implementation of mapper assert.Equal(t, reflect.ValueOf(expected.mapper).Pointer(), reflect.ValueOf(schemaField.Mapper).Pointer()) @@ -144,7 +145,7 @@ func Test_MapToSchemaField(t *testing.T) { t.Run(fmt.Sprintf("%s", tc.field.Name), func(t *testing.T) { schemaField := MapToSchemaField(tc.field) - assertSchemaFieldMapped(schemaField, tc.expected) + assertSchemaFieldMapped(schemaField, tc.field, tc.expected) }) } } diff --git a/pkg/schemas/gen/templates.go b/pkg/schemas/gen/templates.go new file mode 100644 index 0000000000..f04d5fbe2e --- /dev/null +++ b/pkg/schemas/gen/templates.go @@ -0,0 +1,31 @@ +package gen + +import ( + "fmt" + "strings" + "text/template" + + _ "embed" +) + +// TODO: extract common funcs +var ( + //go:embed templates/schema.tmpl + schemaTemplateContent string + SchemaTemplate, _ = template.New("schemaTemplate").Funcs(template.FuncMap{ + "uppercase": func(in string) string { return strings.ToUpper(in) }, + "lowercase": func(in string) string { return strings.ToLower(in) }, + "firstLetterLowercase": func(in string) string { return strings.ToLower(in[:1]) + in[1:] }, + }).Parse(schemaTemplateContent) + + //go:embed templates/to_schema_mapper.tmpl + toSchemaMapperTemplateContent string + ToSchemaMapperTemplate, _ = template.New("toSchemaMapperTemplate").Funcs(template.FuncMap{ + "uppercase": func(in string) string { return strings.ToUpper(in) }, + "lowercase": func(in string) string { return strings.ToLower(in) }, + "firstLetterLowercase": func(in string) string { return strings.ToLower(in[:1]) + in[1:] }, + "mapSdkFieldValue": func(in SchemaField, name string) string { + return in.Mapper(fmt.Sprintf("%s.%s", name, in.OriginalName)) + }, + }).Parse(toSchemaMapperTemplateContent) +) diff --git a/pkg/schemas/gen/templates/schema.tmpl b/pkg/schemas/gen/templates/schema.tmpl new file mode 100644 index 0000000000..22055813fa --- /dev/null +++ b/pkg/schemas/gen/templates/schema.tmpl @@ -0,0 +1,11 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/schemas/gen.ShowResultSchemaModel*/ -}} + +// Show{{ .Name }}Schema represents output of SHOW {{ uppercase .Name }}S query for the single {{ .Name }}. +var Show{{ .Name }}Schema = map[string]*schema.Schema{ + {{- range .SchemaFields }} + "{{ .Name }}": { + Type: schema.{{ .SchemaType }}, + Computed: true, + }, + {{- end }} +} diff --git a/pkg/schemas/gen/templates/to_schema_mapper.tmpl b/pkg/schemas/gen/templates/to_schema_mapper.tmpl new file mode 100644 index 0000000000..31310450fc --- /dev/null +++ b/pkg/schemas/gen/templates/to_schema_mapper.tmpl @@ -0,0 +1,11 @@ +{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/schemas/gen.ShowResultSchemaModel*/ -}} + +{{ $name := .Name }} +{{ $nameLowerCase := firstLetterLowercase .Name }} +func {{ .Name }}ToSchema({{ $nameLowerCase }} *{{ .SdkType }}) map[string]any { + {{ $nameLowerCase }}Schema := make(map[string]any) + {{- range .SchemaFields }} + {{ $nameLowerCase }}Schema["{{ .Name }}"] = {{ mapSdkFieldValue . $nameLowerCase }} + {{- end }} + return {{ $nameLowerCase }}Schema +} From 2e9a5665fb7164c9e3d7a316476be0ed9232f919 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 23 Jun 2024 18:19:43 +0200 Subject: [PATCH 12/28] Change logic a bit --- pkg/schemas/gen/templates.go | 5 +---- pkg/schemas/gen/templates/to_schema_mapper.tmpl | 6 +++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/pkg/schemas/gen/templates.go b/pkg/schemas/gen/templates.go index f04d5fbe2e..be2dd2e23e 100644 --- a/pkg/schemas/gen/templates.go +++ b/pkg/schemas/gen/templates.go @@ -1,7 +1,6 @@ package gen import ( - "fmt" "strings" "text/template" @@ -24,8 +23,6 @@ var ( "uppercase": func(in string) string { return strings.ToUpper(in) }, "lowercase": func(in string) string { return strings.ToLower(in) }, "firstLetterLowercase": func(in string) string { return strings.ToLower(in[:1]) + in[1:] }, - "mapSdkFieldValue": func(in SchemaField, name string) string { - return in.Mapper(fmt.Sprintf("%s.%s", name, in.OriginalName)) - }, + "runMapper": func(mapper Mapper, in ...string) string { return mapper(strings.Join(in, "")) }, }).Parse(toSchemaMapperTemplateContent) ) diff --git a/pkg/schemas/gen/templates/to_schema_mapper.tmpl b/pkg/schemas/gen/templates/to_schema_mapper.tmpl index 31310450fc..f25c72673a 100644 --- a/pkg/schemas/gen/templates/to_schema_mapper.tmpl +++ b/pkg/schemas/gen/templates/to_schema_mapper.tmpl @@ -1,11 +1,11 @@ {{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/schemas/gen.ShowResultSchemaModel*/ -}} -{{ $name := .Name }} {{ $nameLowerCase := firstLetterLowercase .Name }} +{{ $schemaName := $nameLowerCase | printf "%sSchema" }} func {{ .Name }}ToSchema({{ $nameLowerCase }} *{{ .SdkType }}) map[string]any { - {{ $nameLowerCase }}Schema := make(map[string]any) + {{ $schemaName }} := make(map[string]any) {{- range .SchemaFields }} - {{ $nameLowerCase }}Schema["{{ .Name }}"] = {{ mapSdkFieldValue . $nameLowerCase }} + {{ $schemaName }}["{{ .Name }}"] = {{ runMapper .Mapper $nameLowerCase "." .OriginalName }} {{- end }} return {{ $nameLowerCase }}Schema } From f44afe565f963e6d1a1959b981edff5c7370c661 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 23 Jun 2024 18:40:27 +0200 Subject: [PATCH 13/28] Extract generator and cleanup main --- pkg/schemas/gen/generator.go | 20 +++++++++++++ pkg/schemas/gen/main/main.go | 58 ++++++++++++++++++------------------ 2 files changed, 49 insertions(+), 29 deletions(-) create mode 100644 pkg/schemas/gen/generator.go diff --git a/pkg/schemas/gen/generator.go b/pkg/schemas/gen/generator.go new file mode 100644 index 0000000000..98d69483e7 --- /dev/null +++ b/pkg/schemas/gen/generator.go @@ -0,0 +1,20 @@ +package gen + +import ( + "io" + "log" +) + +// TODO: handle panics better +// TODO: test and describe +func Generate(structDetails Struct, writer io.Writer) { + model := ModelFromStructDetails(structDetails) + err := SchemaTemplate.Execute(writer, model) + if err != nil { + log.Panicln(err) + } + err = ToSchemaMapperTemplate.Execute(writer, model) + if err != nil { + log.Panicln(err) + } +} diff --git a/pkg/schemas/gen/main/main.go b/pkg/schemas/gen/main/main.go index 5e9a880bc3..a0ad05f00f 100644 --- a/pkg/schemas/gen/main/main.go +++ b/pkg/schemas/gen/main/main.go @@ -4,7 +4,6 @@ package main import ( "fmt" - "log" "os" "slices" @@ -16,14 +15,32 @@ func main() { file := os.Getenv("GOFILE") fmt.Printf("Running generator on %s with args %#v\n", file, os.Args[1:]) - uniqueTypes := make(map[string]bool) allStructsDetails := make([]gen.Struct, len(gen.SdkShowResultStructs)) for idx, s := range gen.SdkShowResultStructs { - details := gen.ExtractStructDetails(s) - allStructsDetails[idx] = details - printFields(details) + allStructsDetails[idx] = gen.ExtractStructDetails(s) + } - for _, f := range details.Fields { + printAllStructsFields(allStructsDetails) + printUniqueTypes(allStructsDetails) + generateAllStructsToStdOut(allStructsDetails) +} + +func printAllStructsFields(allStructs []gen.Struct) { + for _, s := range allStructs { + fmt.Println("===========================") + fmt.Printf("%s\n", s.Name) + fmt.Println("===========================") + for _, field := range s.Fields { + fmt.Println(gen.ColumnOutput(40, field.Name, field.ConcreteType, field.UnderlyingType)) + } + fmt.Println() + } +} + +func printUniqueTypes(allStructs []gen.Struct) { + uniqueTypes := make(map[string]bool) + for _, s := range allStructs { + for _, f := range s.Fields { uniqueTypes[f.ConcreteType] = true } } @@ -35,30 +52,13 @@ func main() { for _, k := range keys { fmt.Println(k) } - - fmt.Println("===========================") - fmt.Println("Generated") - fmt.Println("===========================") - for _, details := range allStructsDetails { - model := gen.ModelFromStructDetails(details) - err := gen.SchemaTemplate.Execute(os.Stdout, model) - if err != nil { - log.Panicln(err) - } - err = gen.ToSchemaMapperTemplate.Execute(os.Stdout, model) - if err != nil { - log.Panicln(err) - } - } } -func printFields(s gen.Struct) { - fmt.Println("===========================") - fmt.Printf("%s\n", s.Name) - fmt.Println("===========================") - - for _, field := range s.Fields { - fmt.Println(gen.ColumnOutput(40, field.Name, field.ConcreteType, field.UnderlyingType)) +func generateAllStructsToStdOut(allStructs []gen.Struct) { + for _, s := range allStructs { + fmt.Println("===========================") + fmt.Printf("Generated for %s\n", s.Name) + fmt.Println("===========================") + gen.Generate(s, os.Stdout) } - fmt.Println() } From 041b4aafa03206a3e0bf7d3c9a3dc5b288c90ef9 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 23 Jun 2024 18:50:08 +0200 Subject: [PATCH 14/28] Prepare saving to file --- pkg/schemas/gen/generator.go | 3 +-- pkg/schemas/gen/main/example.go | 3 --- pkg/schemas/gen/main/main.go | 34 ++++++++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 6 deletions(-) delete mode 100644 pkg/schemas/gen/main/example.go diff --git a/pkg/schemas/gen/generator.go b/pkg/schemas/gen/generator.go index 98d69483e7..8ce3a60f4f 100644 --- a/pkg/schemas/gen/generator.go +++ b/pkg/schemas/gen/generator.go @@ -7,8 +7,7 @@ import ( // TODO: handle panics better // TODO: test and describe -func Generate(structDetails Struct, writer io.Writer) { - model := ModelFromStructDetails(structDetails) +func Generate(model ShowResultSchemaModel, writer io.Writer) { err := SchemaTemplate.Execute(writer, model) if err != nil { log.Panicln(err) diff --git a/pkg/schemas/gen/main/example.go b/pkg/schemas/gen/main/example.go deleted file mode 100644 index fd5d40978c..0000000000 --- a/pkg/schemas/gen/main/example.go +++ /dev/null @@ -1,3 +0,0 @@ -package main - -//go:generate go run ./main.go diff --git a/pkg/schemas/gen/main/main.go b/pkg/schemas/gen/main/main.go index a0ad05f00f..9c59fcf5c1 100644 --- a/pkg/schemas/gen/main/main.go +++ b/pkg/schemas/gen/main/main.go @@ -3,8 +3,12 @@ package main import ( + "bytes" "fmt" + "go/format" + "log" "os" + "path/filepath" "slices" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/schemas/gen" @@ -23,6 +27,7 @@ func main() { printAllStructsFields(allStructsDetails) printUniqueTypes(allStructsDetails) generateAllStructsToStdOut(allStructsDetails) + saveAllGeneratedSchemas(allStructsDetails) } func printAllStructsFields(allStructs []gen.Struct) { @@ -59,6 +64,33 @@ func generateAllStructsToStdOut(allStructs []gen.Struct) { fmt.Println("===========================") fmt.Printf("Generated for %s\n", s.Name) fmt.Println("===========================") - gen.Generate(s, os.Stdout) + model := gen.ModelFromStructDetails(s) + gen.Generate(model, os.Stdout) + } +} + +func saveAllGeneratedSchemas(allStructs []gen.Struct) { + for _, s := range allStructs { + buffer := bytes.Buffer{} + model := gen.ModelFromStructDetails(s) + gen.Generate(model, &buffer) + filename := gen.ToSnakeCase(model.Name) + "_gen.go" + writeCodeToFile(&buffer, filename) + } +} + +// TODO: this is copied, extract some generator helpers +func writeCodeToFile(buffer *bytes.Buffer, fileName string) { + wd, errWd := os.Getwd() + if errWd != nil { + log.Panicln(errWd) + } + outputPath := filepath.Join(wd, fileName) + src, errSrcFormat := format.Source(buffer.Bytes()) + if errSrcFormat != nil { + log.Panicln(errSrcFormat) + } + if err := os.WriteFile(outputPath, src, 0o600); err != nil { + log.Panicln(err) } } From 09d9e1fe625ce7b0e1c7e53f130cfbc0f75be201 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 23 Jun 2024 18:53:03 +0200 Subject: [PATCH 15/28] Add preamble --- pkg/schemas/gen/generator.go | 6 +++++- pkg/schemas/gen/templates.go | 4 ++++ pkg/schemas/gen/templates/preamble.tmpl | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 pkg/schemas/gen/templates/preamble.tmpl diff --git a/pkg/schemas/gen/generator.go b/pkg/schemas/gen/generator.go index 8ce3a60f4f..5010e66ea9 100644 --- a/pkg/schemas/gen/generator.go +++ b/pkg/schemas/gen/generator.go @@ -8,7 +8,11 @@ import ( // TODO: handle panics better // TODO: test and describe func Generate(model ShowResultSchemaModel, writer io.Writer) { - err := SchemaTemplate.Execute(writer, model) + err := PreambleTemplate.Execute(writer, model) + if err != nil { + log.Panicln(err) + } + err = SchemaTemplate.Execute(writer, model) if err != nil { log.Panicln(err) } diff --git a/pkg/schemas/gen/templates.go b/pkg/schemas/gen/templates.go index be2dd2e23e..d9dcb1e24a 100644 --- a/pkg/schemas/gen/templates.go +++ b/pkg/schemas/gen/templates.go @@ -9,6 +9,10 @@ import ( // TODO: extract common funcs var ( + //go:embed templates/preamble.tmpl + preambleTemplateContent string + PreambleTemplate, _ = template.New("preambleTemplate").Parse(preambleTemplateContent) + //go:embed templates/schema.tmpl schemaTemplateContent string SchemaTemplate, _ = template.New("schemaTemplate").Funcs(template.FuncMap{ diff --git a/pkg/schemas/gen/templates/preamble.tmpl b/pkg/schemas/gen/templates/preamble.tmpl new file mode 100644 index 0000000000..997db12956 --- /dev/null +++ b/pkg/schemas/gen/templates/preamble.tmpl @@ -0,0 +1,6 @@ +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) From 7db2a893ebe113947ca0223da9f6180ebfbba404 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 23 Jun 2024 18:55:15 +0200 Subject: [PATCH 16/28] Add generate --- pkg/schemas/generate.go | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 pkg/schemas/generate.go diff --git a/pkg/schemas/generate.go b/pkg/schemas/generate.go new file mode 100644 index 0000000000..be058d1d6b --- /dev/null +++ b/pkg/schemas/generate.go @@ -0,0 +1,3 @@ +package schemas + +//go:generate go run ./gen/main/main.go From d6f61fcb596e4af52d9de8759e3e29597ed7bf82 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 23 Jun 2024 18:57:22 +0200 Subject: [PATCH 17/28] Add guards and generated comment --- pkg/schemas/gen/templates/preamble.tmpl | 2 ++ pkg/schemas/gen/templates/schema.tmpl | 2 ++ pkg/schemas/gen/templates/to_schema_mapper.tmpl | 2 ++ pkg/schemas/generate.go | 1 + 4 files changed, 7 insertions(+) diff --git a/pkg/schemas/gen/templates/preamble.tmpl b/pkg/schemas/gen/templates/preamble.tmpl index 997db12956..4f2a137630 100644 --- a/pkg/schemas/gen/templates/preamble.tmpl +++ b/pkg/schemas/gen/templates/preamble.tmpl @@ -1,3 +1,5 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + package schemas import ( diff --git a/pkg/schemas/gen/templates/schema.tmpl b/pkg/schemas/gen/templates/schema.tmpl index 22055813fa..5567b93017 100644 --- a/pkg/schemas/gen/templates/schema.tmpl +++ b/pkg/schemas/gen/templates/schema.tmpl @@ -9,3 +9,5 @@ var Show{{ .Name }}Schema = map[string]*schema.Schema{ }, {{- end }} } + +var _ = Show{{ .Name }}Schema diff --git a/pkg/schemas/gen/templates/to_schema_mapper.tmpl b/pkg/schemas/gen/templates/to_schema_mapper.tmpl index f25c72673a..3b670b610f 100644 --- a/pkg/schemas/gen/templates/to_schema_mapper.tmpl +++ b/pkg/schemas/gen/templates/to_schema_mapper.tmpl @@ -9,3 +9,5 @@ func {{ .Name }}ToSchema({{ $nameLowerCase }} *{{ .SdkType }}) map[string]any { {{- end }} return {{ $nameLowerCase }}Schema } + +var _ = {{ .Name }}ToSchema diff --git a/pkg/schemas/generate.go b/pkg/schemas/generate.go index be058d1d6b..088647bf53 100644 --- a/pkg/schemas/generate.go +++ b/pkg/schemas/generate.go @@ -1,3 +1,4 @@ package schemas +// TODO: add invocation and cleanup to makefile //go:generate go run ./gen/main/main.go From 915c07c3e80d7a0345388fe7427058980f99ac72 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 23 Jun 2024 19:07:42 +0200 Subject: [PATCH 18/28] Handle pointers --- pkg/schemas/gen/templates/to_schema_mapper.tmpl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/schemas/gen/templates/to_schema_mapper.tmpl b/pkg/schemas/gen/templates/to_schema_mapper.tmpl index 3b670b610f..a9d91b11c0 100644 --- a/pkg/schemas/gen/templates/to_schema_mapper.tmpl +++ b/pkg/schemas/gen/templates/to_schema_mapper.tmpl @@ -5,7 +5,13 @@ func {{ .Name }}ToSchema({{ $nameLowerCase }} *{{ .SdkType }}) map[string]any { {{ $schemaName }} := make(map[string]any) {{- range .SchemaFields }} + {{ if .IsOriginalTypePointer -}} + if {{ $nameLowerCase }}.{{ .OriginalName }} != nil { + {{ $schemaName }}["{{ .Name }}"] = {{ runMapper .Mapper $nameLowerCase "." .OriginalName }} + } + {{- else -}} {{ $schemaName }}["{{ .Name }}"] = {{ runMapper .Mapper $nameLowerCase "." .OriginalName }} + {{- end -}} {{- end }} return {{ $nameLowerCase }}Schema } From 585c48f1a919bdac8f585d99c7a36ac8d149c50f Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Sun, 23 Jun 2024 19:11:09 +0200 Subject: [PATCH 19/28] Change comment and remove unused --- pkg/schemas/gen/templates.go | 4 ---- pkg/schemas/gen/templates/schema.tmpl | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/pkg/schemas/gen/templates.go b/pkg/schemas/gen/templates.go index d9dcb1e24a..15a53fe97f 100644 --- a/pkg/schemas/gen/templates.go +++ b/pkg/schemas/gen/templates.go @@ -16,16 +16,12 @@ var ( //go:embed templates/schema.tmpl schemaTemplateContent string SchemaTemplate, _ = template.New("schemaTemplate").Funcs(template.FuncMap{ - "uppercase": func(in string) string { return strings.ToUpper(in) }, - "lowercase": func(in string) string { return strings.ToLower(in) }, "firstLetterLowercase": func(in string) string { return strings.ToLower(in[:1]) + in[1:] }, }).Parse(schemaTemplateContent) //go:embed templates/to_schema_mapper.tmpl toSchemaMapperTemplateContent string ToSchemaMapperTemplate, _ = template.New("toSchemaMapperTemplate").Funcs(template.FuncMap{ - "uppercase": func(in string) string { return strings.ToUpper(in) }, - "lowercase": func(in string) string { return strings.ToLower(in) }, "firstLetterLowercase": func(in string) string { return strings.ToLower(in[:1]) + in[1:] }, "runMapper": func(mapper Mapper, in ...string) string { return mapper(strings.Join(in, "")) }, }).Parse(toSchemaMapperTemplateContent) diff --git a/pkg/schemas/gen/templates/schema.tmpl b/pkg/schemas/gen/templates/schema.tmpl index 5567b93017..1ac71205b9 100644 --- a/pkg/schemas/gen/templates/schema.tmpl +++ b/pkg/schemas/gen/templates/schema.tmpl @@ -1,6 +1,6 @@ {{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/schemas/gen.ShowResultSchemaModel*/ -}} -// Show{{ .Name }}Schema represents output of SHOW {{ uppercase .Name }}S query for the single {{ .Name }}. +// Show{{ .Name }}Schema represents output of SHOW query for the single {{ .Name }}. var Show{{ .Name }}Schema = map[string]*schema.Schema{ {{- range .SchemaFields }} "{{ .Name }}": { From 01dcc48a644f10d2891a851026840099e63eae11 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 24 Jun 2024 10:30:31 +0200 Subject: [PATCH 20/28] Add generating show output schemas to the makefile --- Makefile | 6 ++++++ pkg/schemas/generate.go | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6693d99835..62fd39aa39 100644 --- a/Makefile +++ b/Makefile @@ -114,4 +114,10 @@ generate-docs-additional-files: ## generate docs additional files generate-docs-additional-files-check: generate-docs-additional-files ## check that docs additional files have been generated git diff --exit-code -- examples/additional +generate-show-output-schemas: ## Generate show output schemas with mappers + go generate ./pkg/schemas/generate.go + +clean-show-output-schemas: ## Clean generated show output schemas + rm -f ./pkg/schemas/*_gen.go + .PHONY: build-local clean-generator-poc dev-setup dev-cleanup docs docs-check fmt fmt-check fumpt help install lint lint-fix mod mod-check pre-push pre-push-check sweep test test-acceptance uninstall-tf diff --git a/pkg/schemas/generate.go b/pkg/schemas/generate.go index 088647bf53..be058d1d6b 100644 --- a/pkg/schemas/generate.go +++ b/pkg/schemas/generate.go @@ -1,4 +1,3 @@ package schemas -// TODO: add invocation and cleanup to makefile //go:generate go run ./gen/main/main.go From 6c155fd8b0e84126759561af2ebb78fac220849b Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 24 Jun 2024 13:43:41 +0200 Subject: [PATCH 21/28] Add README and cleanup comments --- pkg/schemas/gen/README.md | 82 +++++++++++++++++++ pkg/schemas/gen/generator.go | 4 +- pkg/schemas/gen/main/main.go | 2 +- pkg/schemas/gen/schema_field_mapper.go | 8 +- pkg/schemas/gen/schema_field_mapper_test.go | 2 +- pkg/schemas/gen/struct_details_extractor.go | 2 - .../gen/struct_details_extractor_test.go | 48 ++++++++++- pkg/schemas/gen/templates.go | 2 +- pkg/schemas/gen/util.go | 13 ++- 9 files changed, 148 insertions(+), 15 deletions(-) create mode 100644 pkg/schemas/gen/README.md diff --git a/pkg/schemas/gen/README.md b/pkg/schemas/gen/README.md new file mode 100644 index 0000000000..c8f57d644b --- /dev/null +++ b/pkg/schemas/gen/README.md @@ -0,0 +1,82 @@ +## show output schemas generation + +These schemas are necessary to include SHOW output in every resource and datasource. The work is repetitive, so it's +easier to just generate all the needed schemas and mappers. + +### Description + +File [generate.go](../generate.go) invokes the generation logic from [main.go](./main/main.go). By default, all SDK show +output struct are used (listed in [sdk_show_result_structs.go](./sdk_show_result_structs.go)). After successful +generation all SDK objects will have: + +- show output schema that can be used in the resource/datasource (e.g. [warehouse_gen](../warehouse_gen.go#L11)) +- mapper from the SDK object to the generated schema (e.g. [warehouse_gen](../warehouse_gen.go#L124)) + +### How it works + +##### Invoking the generation + +To generate all show outputs (with a cleanup first) run: + +```shell +make clean-show-output-schemas generate-show-output-schemas +``` + +##### Supported types + +The following types are supported currently in the generator (schema and mappings): + +- basic types (`string`, `int`, `float64`, `bool`) +- pointers to basic types (the same as above) +- `time.Time` (pointer too) +- enums based on `string` and `int` like `sdk.WarehouseType` or `sdk.ResourceMonitorLevel` (pointers too) +- identifiers (pointers too): + - `sdk.AccountIdentifier` + - `sdk.ExternalObjectIdentifier` + - `sdk.AccountObjectIdentifier` + - `sdk.DatabaseObjectIdentifier` + - `sdk.SchemaObjectIdentifier` + - `sdk.TableColumnIdentifier` +- `sdk.ObjectIdentifier` interface + +##### Changing the SDK object's show output + +If you change the show output struct in the SDK: + +1. Check if you don't introduce a type that is unsupported (check [supported types](#supported-types) + and [known limitations](#known-limitations)). +2. Run generation according to [instructions](#invoking-the-generation). + +##### Adding a new object to the SDK + +1. Add the new show output struct to [sdk_show_result_structs.go](./sdk_show_result_structs.go). +2. Check if you don't introduce a type that is unsupported (check [supported types](#supported-types) + and [known limitations](#known-limitations)). +3. Run generation according to [instructions](#invoking-the-generation). + +### Next steps + +##### Known limitations + +- The following types (already existing in the SDK show output structs) are not yet supported (for all of them the + schema will be generated with `schema.TypeInvalid`: + - slices of basic types (`[]int`, `[]string`) + - slices of identifiers (`[]sdk.AccountIdentifier`, `[]sdk.SchemaObjectIdentifier`) + - slices of enums (`[]sdk.IntegrationType`, `[]sdk.PluralObjectType`) + - structs (`sdk.FileFormatTypeOptions`) + +##### Improvements + +Functional improvements: +- handle the missing types (TODOs in [schema_field_mapper.go](./schema_field_mapper.go) and [struct_details_extractor_test.go](./struct_details_extractor_test.go)) +- parametrize the generation, e.g.: + - generate only given object(s) - now all are always generated + - manage the output - currently, the output consists of all structs displayed with fields, unique types grouped, and schemas generated + - (optional) parametrize the output directory - currently, it's always written to `schemas` package + +Implementation improvements: +- add acceptance test for a `testStruct` (the one from [struct_details_extractor_test.go](./struct_details_extractor_test.go)) for the whole generation flow +- extract common generator functions inside the project (TODO in [main.go](./main/main.go); e.g. `writeCodeToFile` function) +- test the generator part and improve error handling (TODOs in [generator.go](./generator.go)) +- extract common template functions (TODO in [templates.go](./templates.go))) +- (optional) consider different implementations of `Mapper` (e.g. TODO in [schema_field_mapper_test.go](./schema_field_mapper_test.go): `ugly comparison of functions with the current implementation of mapper` and not ideal implementation in the [to_schema_mapper.tmpl](./templates/to_schema_mapper.tmpl): `runMapper .Mapper $nameLowerCase "." .OriginalName`) diff --git a/pkg/schemas/gen/generator.go b/pkg/schemas/gen/generator.go index 5010e66ea9..da2f5d63a5 100644 --- a/pkg/schemas/gen/generator.go +++ b/pkg/schemas/gen/generator.go @@ -5,8 +5,8 @@ import ( "log" ) -// TODO: handle panics better -// TODO: test and describe +// TODO [SNOW-1501905]: handle panics better +// TODO [SNOW-1501905]: test and describe func Generate(model ShowResultSchemaModel, writer io.Writer) { err := PreambleTemplate.Execute(writer, model) if err != nil { diff --git a/pkg/schemas/gen/main/main.go b/pkg/schemas/gen/main/main.go index 9c59fcf5c1..cac8db67bc 100644 --- a/pkg/schemas/gen/main/main.go +++ b/pkg/schemas/gen/main/main.go @@ -79,7 +79,7 @@ func saveAllGeneratedSchemas(allStructs []gen.Struct) { } } -// TODO: this is copied, extract some generator helpers +// TODO [SNOW-1501905]: this is copied, extract some generator helpers func writeCodeToFile(buffer *bytes.Buffer, fileName string) { wd, errWd := os.Getwd() if errWd != nil { diff --git a/pkg/schemas/gen/schema_field_mapper.go b/pkg/schemas/gen/schema_field_mapper.go index c034e0ddb5..66369eb037 100644 --- a/pkg/schemas/gen/schema_field_mapper.go +++ b/pkg/schemas/gen/schema_field_mapper.go @@ -23,10 +23,10 @@ var FullyQualifiedName = func(field string) string { return fmt.Sprintf("%s.Full var CastToString = func(field string) string { return fmt.Sprintf("string(%s)", field) } var CastToInt = func(field string) string { return fmt.Sprintf("int(%s)", field) } -// TODO: handle other basic type variants -// TODO: handle any other interface (error) -// TODO: handle slices -// TODO: handle structs (chosen one or all) +// TODO [SNOW-1501905]: handle other basic type variants +// TODO [SNOW-1501905]: handle any other interface (error) +// TODO [SNOW-1501905]: handle slices +// TODO [SNOW-1501905]: handle structs (chosen one or all) func MapToSchemaField(field Field) SchemaField { isPointer := field.IsPointer() concreteTypeWithoutPtr, _ := strings.CutPrefix(field.ConcreteType, "*") diff --git a/pkg/schemas/gen/schema_field_mapper_test.go b/pkg/schemas/gen/schema_field_mapper_test.go index 2b193197c8..1dbef95948 100644 --- a/pkg/schemas/gen/schema_field_mapper_test.go +++ b/pkg/schemas/gen/schema_field_mapper_test.go @@ -137,7 +137,7 @@ func Test_MapToSchemaField(t *testing.T) { assert.Equal(t, expected.schemaType, schemaField.SchemaType) assert.Equal(t, originalField.Name, schemaField.OriginalName) assert.Equal(t, expected.isPointer, schemaField.IsOriginalTypePointer) - // TODO: ugly comparison of functions with the current implementation of mapper + // TODO [SNOW-1501905]: ugly comparison of functions with the current implementation of mapper assert.Equal(t, reflect.ValueOf(expected.mapper).Pointer(), reflect.ValueOf(schemaField.Mapper).Pointer()) } diff --git a/pkg/schemas/gen/struct_details_extractor.go b/pkg/schemas/gen/struct_details_extractor.go index 4ac12a1f92..1a5e24c759 100644 --- a/pkg/schemas/gen/struct_details_extractor.go +++ b/pkg/schemas/gen/struct_details_extractor.go @@ -16,12 +16,10 @@ type Field struct { UnderlyingType string } -// TODO: test func (f *Field) IsPointer() bool { return strings.HasPrefix(f.ConcreteType, "*") } -// TODO: test func (f *Field) IsSlice() bool { return strings.HasPrefix(f.ConcreteType, "[]") } diff --git a/pkg/schemas/gen/struct_details_extractor_test.go b/pkg/schemas/gen/struct_details_extractor_test.go index f3189abb87..d72727b8c5 100644 --- a/pkg/schemas/gen/struct_details_extractor_test.go +++ b/pkg/schemas/gen/struct_details_extractor_test.go @@ -8,13 +8,13 @@ import ( "github.com/stretchr/testify/assert" ) -// TODO: do we need any of: +// TODO [SNOW-1501905]: do we need any of: // - (?) slice of pointers to interface // - (?) slice of pointers to structs // - (?) slice of pointers to basic // - (?) pointer to slice // -// TODO: test type of slice fields +// TODO [SNOW-1501905]: test type of slice fields func Test_ExtractStructDetails(t *testing.T) { type testStruct struct { @@ -116,3 +116,47 @@ func Test_ExtractStructDetails(t *testing.T) { assertFieldExtracted(structDetails.Fields[31], "unexportedStruct", "sdk.FileFormatTypeOptions", "struct") }) } + +func Test_Field_IsSlice(t *testing.T) { + t.Run("is a slice", func(t *testing.T) { + field := Field{ConcreteType: "[]any_type"} + + assert.True(t, field.IsSlice()) + }) + + t.Run("is not a slice", func(t *testing.T) { + field := Field{ConcreteType: "*any_type"} + + assert.False(t, field.IsSlice()) + + field = Field{ConcreteType: "*[]any_type"} + + assert.False(t, field.IsSlice()) + + field = Field{ConcreteType: "any_type"} + + assert.False(t, field.IsSlice()) + }) +} + +func Test_Field_IsPointer(t *testing.T) { + t.Run("is a pointer", func(t *testing.T) { + field := Field{ConcreteType: "*any_type"} + + assert.True(t, field.IsPointer()) + }) + + t.Run("is not a pointer", func(t *testing.T) { + field := Field{ConcreteType: "[]any_type"} + + assert.False(t, field.IsPointer()) + + field = Field{ConcreteType: "[]*any_type"} + + assert.False(t, field.IsPointer()) + + field = Field{ConcreteType: "any_type"} + + assert.False(t, field.IsPointer()) + }) +} diff --git a/pkg/schemas/gen/templates.go b/pkg/schemas/gen/templates.go index 15a53fe97f..478e699c19 100644 --- a/pkg/schemas/gen/templates.go +++ b/pkg/schemas/gen/templates.go @@ -7,7 +7,7 @@ import ( _ "embed" ) -// TODO: extract common funcs +// TODO [SNOW-1501905]: extract common funcs var ( //go:embed templates/preamble.tmpl preambleTemplateContent string diff --git a/pkg/schemas/gen/util.go b/pkg/schemas/gen/util.go index 3b0e5d4737..d610de8609 100644 --- a/pkg/schemas/gen/util.go +++ b/pkg/schemas/gen/util.go @@ -8,13 +8,22 @@ import ( var splitOnTheWordsBeginnings = regexp.MustCompile(`(.)([A-Z][a-z]+)`) var splitRemainingWordBreaks = regexp.MustCompile("([a-z0-9])([A-Z]+)") -// TODO: describe +// ToSnakeCase allows converting a CamelCase text to camel_case one (needed for schema attribute names). Examples: +// - CamelCase -> camel_case +// - ACamelCase -> a_camel_case +// - URLParser -> url_parser +// - Camel1Case -> camel1_case +// - camelCase -> camel_case +// - camelURL -> camel_url +// - camelURLSomething -> camel_url_something func ToSnakeCase(str string) string { wordsSplit := splitOnTheWordsBeginnings.ReplaceAllString(str, "${1}_${2}") return strings.ToLower(splitRemainingWordBreaks.ReplaceAllString(wordsSplit, "${1}_${2}")) } -// TODO: describe +// ColumnOutput is a helper to align a tabular output with the given columnWidth, e.g. (for 20 spaces column width): +// Name string string +// State sdk.WarehouseState string func ColumnOutput(columnWidth int, columns ...string) string { var sb strings.Builder for i, column := range columns { From 918937637bdc42a772383dcb8f7438a9683f4311 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 24 Jun 2024 13:50:11 +0200 Subject: [PATCH 22/28] Generate all --- pkg/schemas/account_gen.go | 101 +++++++++++++ pkg/schemas/alert_gen.go | 83 +++++++++++ pkg/schemas/api_integration_gen.go | 51 +++++++ pkg/schemas/application_gen.go | 86 +++++++++++ pkg/schemas/application_package_gen.go | 76 ++++++++++ pkg/schemas/application_role_gen.go | 46 ++++++ pkg/schemas/database_gen.go | 91 ++++++++++++ pkg/schemas/database_role_gen.go | 76 ++++++++++ pkg/schemas/dynamic_table_gen.go | 131 ++++++++++++++++ pkg/schemas/event_table_gen.go | 56 +++++++ pkg/schemas/external_function_gen.go | 111 ++++++++++++++ pkg/schemas/external_table_gen.go | 116 +++++++++++++++ pkg/schemas/failover_group_gen.go | 111 ++++++++++++++ pkg/schemas/file_format_gen.go | 56 +++++++ pkg/schemas/function_gen.go | 106 +++++++++++++ pkg/schemas/grant_gen.go | 71 +++++++++ pkg/schemas/managed_account_gen.go | 66 +++++++++ pkg/schemas/masking_policy_gen.go | 66 +++++++++ pkg/schemas/materialized_view_gen.go | 138 +++++++++++++++++ pkg/schemas/network_policy_gen.go | 56 +++++++ pkg/schemas/network_rule_gen.go | 71 +++++++++ pkg/schemas/notification_integration_gen.go | 51 +++++++ pkg/schemas/parameter_gen.go | 46 ++++++ pkg/schemas/password_policy_gen.go | 61 ++++++++ pkg/schemas/pipe_gen.go | 86 +++++++++++ pkg/schemas/policy_reference_gen.go | 111 ++++++++++++++ pkg/schemas/procedure_gen.go | 91 ++++++++++++ pkg/schemas/region_gen.go | 46 ++++++ pkg/schemas/replication_account_gen.go | 56 +++++++ pkg/schemas/replication_database_gen.go | 81 ++++++++++ pkg/schemas/resource_monitor_gen.go | 90 +++++++++++ pkg/schemas/role_gen.go | 71 +++++++++ pkg/schemas/row_access_policy_gen.go | 66 +++++++++ pkg/schemas/schema_gen.go | 75 ++++++++++ pkg/schemas/security_integration_gen.go | 51 +++++++ pkg/schemas/sequence_gen.go | 71 +++++++++ pkg/schemas/session_policy_gen.go | 66 +++++++++ pkg/schemas/share_gen.go | 56 +++++++ pkg/schemas/stage_gen.go | 111 ++++++++++++++ pkg/schemas/storage_integration_gen.go | 51 +++++++ pkg/schemas/stream_gen.go | 125 ++++++++++++++++ pkg/schemas/streamlit_gen.go | 71 +++++++++ pkg/schemas/table_gen.go | 139 +++++++++++++++++ pkg/schemas/tag_gen.go | 61 ++++++++ pkg/schemas/task_gen.go | 121 +++++++++++++++ pkg/schemas/user_gen.go | 151 +++++++++++++++++++ pkg/schemas/view_gen.go | 86 +++++++++++ pkg/schemas/warehouse_gen.go | 156 ++++++++++++++++++++ 48 files changed, 4012 insertions(+) create mode 100644 pkg/schemas/account_gen.go create mode 100644 pkg/schemas/alert_gen.go create mode 100644 pkg/schemas/api_integration_gen.go create mode 100644 pkg/schemas/application_gen.go create mode 100644 pkg/schemas/application_package_gen.go create mode 100644 pkg/schemas/application_role_gen.go create mode 100644 pkg/schemas/database_gen.go create mode 100644 pkg/schemas/database_role_gen.go create mode 100644 pkg/schemas/dynamic_table_gen.go create mode 100644 pkg/schemas/event_table_gen.go create mode 100644 pkg/schemas/external_function_gen.go create mode 100644 pkg/schemas/external_table_gen.go create mode 100644 pkg/schemas/failover_group_gen.go create mode 100644 pkg/schemas/file_format_gen.go create mode 100644 pkg/schemas/function_gen.go create mode 100644 pkg/schemas/grant_gen.go create mode 100644 pkg/schemas/managed_account_gen.go create mode 100644 pkg/schemas/masking_policy_gen.go create mode 100644 pkg/schemas/materialized_view_gen.go create mode 100644 pkg/schemas/network_policy_gen.go create mode 100644 pkg/schemas/network_rule_gen.go create mode 100644 pkg/schemas/notification_integration_gen.go create mode 100644 pkg/schemas/parameter_gen.go create mode 100644 pkg/schemas/password_policy_gen.go create mode 100644 pkg/schemas/pipe_gen.go create mode 100644 pkg/schemas/policy_reference_gen.go create mode 100644 pkg/schemas/procedure_gen.go create mode 100644 pkg/schemas/region_gen.go create mode 100644 pkg/schemas/replication_account_gen.go create mode 100644 pkg/schemas/replication_database_gen.go create mode 100644 pkg/schemas/resource_monitor_gen.go create mode 100644 pkg/schemas/role_gen.go create mode 100644 pkg/schemas/row_access_policy_gen.go create mode 100644 pkg/schemas/schema_gen.go create mode 100644 pkg/schemas/security_integration_gen.go create mode 100644 pkg/schemas/sequence_gen.go create mode 100644 pkg/schemas/session_policy_gen.go create mode 100644 pkg/schemas/share_gen.go create mode 100644 pkg/schemas/stage_gen.go create mode 100644 pkg/schemas/storage_integration_gen.go create mode 100644 pkg/schemas/stream_gen.go create mode 100644 pkg/schemas/streamlit_gen.go create mode 100644 pkg/schemas/table_gen.go create mode 100644 pkg/schemas/tag_gen.go create mode 100644 pkg/schemas/task_gen.go create mode 100644 pkg/schemas/user_gen.go create mode 100644 pkg/schemas/view_gen.go create mode 100644 pkg/schemas/warehouse_gen.go diff --git a/pkg/schemas/account_gen.go b/pkg/schemas/account_gen.go new file mode 100644 index 0000000000..17d7ee2836 --- /dev/null +++ b/pkg/schemas/account_gen.go @@ -0,0 +1,101 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowAccountSchema represents output of SHOW query for the single Account. +var ShowAccountSchema = map[string]*schema.Schema{ + "organization_name": { + Type: schema.TypeString, + Computed: true, + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + }, + "region_group": { + Type: schema.TypeString, + Computed: true, + }, + "snowflake_region": { + Type: schema.TypeString, + Computed: true, + }, + "edition": { + Type: schema.TypeString, + Computed: true, + }, + "account_url": { + Type: schema.TypeString, + Computed: true, + }, + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "account_locator": { + Type: schema.TypeString, + Computed: true, + }, + "account_locator_url": { + Type: schema.TypeString, + Computed: true, + }, + "managed_accounts": { + Type: schema.TypeInt, + Computed: true, + }, + "consumption_billing_entity_name": { + Type: schema.TypeString, + Computed: true, + }, + "marketplace_consumer_billing_entity_name": { + Type: schema.TypeString, + Computed: true, + }, + "marketplace_provider_billing_entity_name": { + Type: schema.TypeString, + Computed: true, + }, + "old_account_url": { + Type: schema.TypeString, + Computed: true, + }, + "is_org_admin": { + Type: schema.TypeBool, + Computed: true, + }, +} + +var _ = ShowAccountSchema + +func AccountToSchema(account *sdk.Account) map[string]any { + accountSchema := make(map[string]any) + accountSchema["organization_name"] = account.OrganizationName + accountSchema["account_name"] = account.AccountName + accountSchema["region_group"] = account.RegionGroup + accountSchema["snowflake_region"] = account.SnowflakeRegion + accountSchema["edition"] = string(account.Edition) + accountSchema["account_url"] = account.AccountURL + accountSchema["created_on"] = account.CreatedOn.String() + accountSchema["comment"] = account.Comment + accountSchema["account_locator"] = account.AccountLocator + accountSchema["account_locator_url"] = account.AccountLocatorURL + accountSchema["managed_accounts"] = account.ManagedAccounts + accountSchema["consumption_billing_entity_name"] = account.ConsumptionBillingEntityName + accountSchema["marketplace_consumer_billing_entity_name"] = account.MarketplaceConsumerBillingEntityName + accountSchema["marketplace_provider_billing_entity_name"] = account.MarketplaceProviderBillingEntityName + accountSchema["old_account_url"] = account.OldAccountURL + accountSchema["is_org_admin"] = account.IsOrgAdmin + return accountSchema +} + +var _ = AccountToSchema diff --git a/pkg/schemas/alert_gen.go b/pkg/schemas/alert_gen.go new file mode 100644 index 0000000000..786c1ae22b --- /dev/null +++ b/pkg/schemas/alert_gen.go @@ -0,0 +1,83 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowAlertSchema represents output of SHOW query for the single Alert. +var ShowAlertSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "database_name": { + Type: schema.TypeString, + Computed: true, + }, + "schema_name": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "warehouse": { + Type: schema.TypeString, + Computed: true, + }, + "schedule": { + Type: schema.TypeString, + Computed: true, + }, + "state": { + Type: schema.TypeString, + Computed: true, + }, + "condition": { + Type: schema.TypeString, + Computed: true, + }, + "action": { + Type: schema.TypeString, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowAlertSchema + +func AlertToSchema(alert *sdk.Alert) map[string]any { + alertSchema := make(map[string]any) + alertSchema["created_on"] = alert.CreatedOn.String() + alertSchema["name"] = alert.Name + alertSchema["database_name"] = alert.DatabaseName + alertSchema["schema_name"] = alert.SchemaName + alertSchema["owner"] = alert.Owner + if alert.Comment != nil { + alertSchema["comment"] = alert.Comment + } + alertSchema["warehouse"] = alert.Warehouse + alertSchema["schedule"] = alert.Schedule + alertSchema["state"] = string(alert.State) + alertSchema["condition"] = alert.Condition + alertSchema["action"] = alert.Action + alertSchema["owner_role_type"] = alert.OwnerRoleType + return alertSchema +} + +var _ = AlertToSchema diff --git a/pkg/schemas/api_integration_gen.go b/pkg/schemas/api_integration_gen.go new file mode 100644 index 0000000000..027de9bc45 --- /dev/null +++ b/pkg/schemas/api_integration_gen.go @@ -0,0 +1,51 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowApiIntegrationSchema represents output of SHOW query for the single ApiIntegration. +var ShowApiIntegrationSchema = map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "api_type": { + Type: schema.TypeString, + Computed: true, + }, + "category": { + Type: schema.TypeString, + Computed: true, + }, + "enabled": { + Type: schema.TypeBool, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "created_on": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowApiIntegrationSchema + +func ApiIntegrationToSchema(apiIntegration *sdk.ApiIntegration) map[string]any { + apiIntegrationSchema := make(map[string]any) + apiIntegrationSchema["name"] = apiIntegration.Name + apiIntegrationSchema["api_type"] = apiIntegration.ApiType + apiIntegrationSchema["category"] = apiIntegration.Category + apiIntegrationSchema["enabled"] = apiIntegration.Enabled + apiIntegrationSchema["comment"] = apiIntegration.Comment + apiIntegrationSchema["created_on"] = apiIntegration.CreatedOn.String() + return apiIntegrationSchema +} + +var _ = ApiIntegrationToSchema diff --git a/pkg/schemas/application_gen.go b/pkg/schemas/application_gen.go new file mode 100644 index 0000000000..aeec9f7c94 --- /dev/null +++ b/pkg/schemas/application_gen.go @@ -0,0 +1,86 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowApplicationSchema represents output of SHOW query for the single Application. +var ShowApplicationSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "is_default": { + Type: schema.TypeBool, + Computed: true, + }, + "is_current": { + Type: schema.TypeBool, + Computed: true, + }, + "source_type": { + Type: schema.TypeString, + Computed: true, + }, + "source": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "version": { + Type: schema.TypeString, + Computed: true, + }, + "label": { + Type: schema.TypeString, + Computed: true, + }, + "patch": { + Type: schema.TypeInt, + Computed: true, + }, + "options": { + Type: schema.TypeString, + Computed: true, + }, + "retention_time": { + Type: schema.TypeInt, + Computed: true, + }, +} + +var _ = ShowApplicationSchema + +func ApplicationToSchema(application *sdk.Application) map[string]any { + applicationSchema := make(map[string]any) + applicationSchema["created_on"] = application.CreatedOn + applicationSchema["name"] = application.Name + applicationSchema["is_default"] = application.IsDefault + applicationSchema["is_current"] = application.IsCurrent + applicationSchema["source_type"] = application.SourceType + applicationSchema["source"] = application.Source + applicationSchema["owner"] = application.Owner + applicationSchema["comment"] = application.Comment + applicationSchema["version"] = application.Version + applicationSchema["label"] = application.Label + applicationSchema["patch"] = application.Patch + applicationSchema["options"] = application.Options + applicationSchema["retention_time"] = application.RetentionTime + return applicationSchema +} + +var _ = ApplicationToSchema diff --git a/pkg/schemas/application_package_gen.go b/pkg/schemas/application_package_gen.go new file mode 100644 index 0000000000..33198d07b6 --- /dev/null +++ b/pkg/schemas/application_package_gen.go @@ -0,0 +1,76 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowApplicationPackageSchema represents output of SHOW query for the single ApplicationPackage. +var ShowApplicationPackageSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "is_default": { + Type: schema.TypeBool, + Computed: true, + }, + "is_current": { + Type: schema.TypeBool, + Computed: true, + }, + "distribution": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "retention_time": { + Type: schema.TypeInt, + Computed: true, + }, + "options": { + Type: schema.TypeString, + Computed: true, + }, + "dropped_on": { + Type: schema.TypeString, + Computed: true, + }, + "application_class": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowApplicationPackageSchema + +func ApplicationPackageToSchema(applicationPackage *sdk.ApplicationPackage) map[string]any { + applicationPackageSchema := make(map[string]any) + applicationPackageSchema["created_on"] = applicationPackage.CreatedOn + applicationPackageSchema["name"] = applicationPackage.Name + applicationPackageSchema["is_default"] = applicationPackage.IsDefault + applicationPackageSchema["is_current"] = applicationPackage.IsCurrent + applicationPackageSchema["distribution"] = applicationPackage.Distribution + applicationPackageSchema["owner"] = applicationPackage.Owner + applicationPackageSchema["comment"] = applicationPackage.Comment + applicationPackageSchema["retention_time"] = applicationPackage.RetentionTime + applicationPackageSchema["options"] = applicationPackage.Options + applicationPackageSchema["dropped_on"] = applicationPackage.DroppedOn + applicationPackageSchema["application_class"] = applicationPackage.ApplicationClass + return applicationPackageSchema +} + +var _ = ApplicationPackageToSchema diff --git a/pkg/schemas/application_role_gen.go b/pkg/schemas/application_role_gen.go new file mode 100644 index 0000000000..9f33f0f9c5 --- /dev/null +++ b/pkg/schemas/application_role_gen.go @@ -0,0 +1,46 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowApplicationRoleSchema represents output of SHOW query for the single ApplicationRole. +var ShowApplicationRoleSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowApplicationRoleSchema + +func ApplicationRoleToSchema(applicationRole *sdk.ApplicationRole) map[string]any { + applicationRoleSchema := make(map[string]any) + applicationRoleSchema["created_on"] = applicationRole.CreatedOn.String() + applicationRoleSchema["name"] = applicationRole.Name + applicationRoleSchema["owner"] = applicationRole.Owner + applicationRoleSchema["comment"] = applicationRole.Comment + applicationRoleSchema["owner_role_type"] = applicationRole.OwnerRoleType + return applicationRoleSchema +} + +var _ = ApplicationRoleToSchema diff --git a/pkg/schemas/database_gen.go b/pkg/schemas/database_gen.go new file mode 100644 index 0000000000..f4a5596b14 --- /dev/null +++ b/pkg/schemas/database_gen.go @@ -0,0 +1,91 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowDatabaseSchema represents output of SHOW query for the single Database. +var ShowDatabaseSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "is_default": { + Type: schema.TypeBool, + Computed: true, + }, + "is_current": { + Type: schema.TypeBool, + Computed: true, + }, + "origin": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "options": { + Type: schema.TypeString, + Computed: true, + }, + "retention_time": { + Type: schema.TypeInt, + Computed: true, + }, + "resource_group": { + Type: schema.TypeString, + Computed: true, + }, + "dropped_on": { + Type: schema.TypeString, + Computed: true, + }, + "transient": { + Type: schema.TypeBool, + Computed: true, + }, + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowDatabaseSchema + +func DatabaseToSchema(database *sdk.Database) map[string]any { + databaseSchema := make(map[string]any) + databaseSchema["created_on"] = database.CreatedOn.String() + databaseSchema["name"] = database.Name + databaseSchema["is_default"] = database.IsDefault + databaseSchema["is_current"] = database.IsCurrent + databaseSchema["origin"] = database.Origin + databaseSchema["owner"] = database.Owner + databaseSchema["comment"] = database.Comment + databaseSchema["options"] = database.Options + databaseSchema["retention_time"] = database.RetentionTime + databaseSchema["resource_group"] = database.ResourceGroup + databaseSchema["dropped_on"] = database.DroppedOn.String() + databaseSchema["transient"] = database.Transient + databaseSchema["kind"] = database.Kind + databaseSchema["owner_role_type"] = database.OwnerRoleType + return databaseSchema +} + +var _ = DatabaseToSchema diff --git a/pkg/schemas/database_role_gen.go b/pkg/schemas/database_role_gen.go new file mode 100644 index 0000000000..f9a7dfd119 --- /dev/null +++ b/pkg/schemas/database_role_gen.go @@ -0,0 +1,76 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowDatabaseRoleSchema represents output of SHOW query for the single DatabaseRole. +var ShowDatabaseRoleSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "is_default": { + Type: schema.TypeBool, + Computed: true, + }, + "is_current": { + Type: schema.TypeBool, + Computed: true, + }, + "is_inherited": { + Type: schema.TypeBool, + Computed: true, + }, + "granted_to_roles": { + Type: schema.TypeInt, + Computed: true, + }, + "granted_to_database_roles": { + Type: schema.TypeInt, + Computed: true, + }, + "granted_database_roles": { + Type: schema.TypeInt, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowDatabaseRoleSchema + +func DatabaseRoleToSchema(databaseRole *sdk.DatabaseRole) map[string]any { + databaseRoleSchema := make(map[string]any) + databaseRoleSchema["created_on"] = databaseRole.CreatedOn + databaseRoleSchema["name"] = databaseRole.Name + databaseRoleSchema["is_default"] = databaseRole.IsDefault + databaseRoleSchema["is_current"] = databaseRole.IsCurrent + databaseRoleSchema["is_inherited"] = databaseRole.IsInherited + databaseRoleSchema["granted_to_roles"] = databaseRole.GrantedToRoles + databaseRoleSchema["granted_to_database_roles"] = databaseRole.GrantedToDatabaseRoles + databaseRoleSchema["granted_database_roles"] = databaseRole.GrantedDatabaseRoles + databaseRoleSchema["owner"] = databaseRole.Owner + databaseRoleSchema["comment"] = databaseRole.Comment + databaseRoleSchema["owner_role_type"] = databaseRole.OwnerRoleType + return databaseRoleSchema +} + +var _ = DatabaseRoleToSchema diff --git a/pkg/schemas/dynamic_table_gen.go b/pkg/schemas/dynamic_table_gen.go new file mode 100644 index 0000000000..d7a6b7986b --- /dev/null +++ b/pkg/schemas/dynamic_table_gen.go @@ -0,0 +1,131 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowDynamicTableSchema represents output of SHOW query for the single DynamicTable. +var ShowDynamicTableSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "reserved": { + Type: schema.TypeString, + Computed: true, + }, + "database_name": { + Type: schema.TypeString, + Computed: true, + }, + "schema_name": { + Type: schema.TypeString, + Computed: true, + }, + "cluster_by": { + Type: schema.TypeString, + Computed: true, + }, + "rows": { + Type: schema.TypeInt, + Computed: true, + }, + "bytes": { + Type: schema.TypeInt, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "target_lag": { + Type: schema.TypeString, + Computed: true, + }, + "refresh_mode": { + Type: schema.TypeString, + Computed: true, + }, + "refresh_mode_reason": { + Type: schema.TypeString, + Computed: true, + }, + "warehouse": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "text": { + Type: schema.TypeString, + Computed: true, + }, + "automatic_clustering": { + Type: schema.TypeBool, + Computed: true, + }, + "scheduling_state": { + Type: schema.TypeString, + Computed: true, + }, + "last_suspended_on": { + Type: schema.TypeString, + Computed: true, + }, + "is_clone": { + Type: schema.TypeBool, + Computed: true, + }, + "is_replica": { + Type: schema.TypeBool, + Computed: true, + }, + "data_timestamp": { + Type: schema.TypeString, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowDynamicTableSchema + +func DynamicTableToSchema(dynamicTable *sdk.DynamicTable) map[string]any { + dynamicTableSchema := make(map[string]any) + dynamicTableSchema["created_on"] = dynamicTable.CreatedOn.String() + dynamicTableSchema["name"] = dynamicTable.Name + dynamicTableSchema["reserved"] = dynamicTable.Reserved + dynamicTableSchema["database_name"] = dynamicTable.DatabaseName + dynamicTableSchema["schema_name"] = dynamicTable.SchemaName + dynamicTableSchema["cluster_by"] = dynamicTable.ClusterBy + dynamicTableSchema["rows"] = dynamicTable.Rows + dynamicTableSchema["bytes"] = dynamicTable.Bytes + dynamicTableSchema["owner"] = dynamicTable.Owner + dynamicTableSchema["target_lag"] = dynamicTable.TargetLag + dynamicTableSchema["refresh_mode"] = string(dynamicTable.RefreshMode) + dynamicTableSchema["refresh_mode_reason"] = dynamicTable.RefreshModeReason + dynamicTableSchema["warehouse"] = dynamicTable.Warehouse + dynamicTableSchema["comment"] = dynamicTable.Comment + dynamicTableSchema["text"] = dynamicTable.Text + dynamicTableSchema["automatic_clustering"] = dynamicTable.AutomaticClustering + dynamicTableSchema["scheduling_state"] = string(dynamicTable.SchedulingState) + dynamicTableSchema["last_suspended_on"] = dynamicTable.LastSuspendedOn.String() + dynamicTableSchema["is_clone"] = dynamicTable.IsClone + dynamicTableSchema["is_replica"] = dynamicTable.IsReplica + dynamicTableSchema["data_timestamp"] = dynamicTable.DataTimestamp.String() + dynamicTableSchema["owner_role_type"] = dynamicTable.OwnerRoleType + return dynamicTableSchema +} + +var _ = DynamicTableToSchema diff --git a/pkg/schemas/event_table_gen.go b/pkg/schemas/event_table_gen.go new file mode 100644 index 0000000000..50d69557a7 --- /dev/null +++ b/pkg/schemas/event_table_gen.go @@ -0,0 +1,56 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowEventTableSchema represents output of SHOW query for the single EventTable. +var ShowEventTableSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "database_name": { + Type: schema.TypeString, + Computed: true, + }, + "schema_name": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowEventTableSchema + +func EventTableToSchema(eventTable *sdk.EventTable) map[string]any { + eventTableSchema := make(map[string]any) + eventTableSchema["created_on"] = eventTable.CreatedOn.String() + eventTableSchema["name"] = eventTable.Name + eventTableSchema["database_name"] = eventTable.DatabaseName + eventTableSchema["schema_name"] = eventTable.SchemaName + eventTableSchema["owner"] = eventTable.Owner + eventTableSchema["comment"] = eventTable.Comment + eventTableSchema["owner_role_type"] = eventTable.OwnerRoleType + return eventTableSchema +} + +var _ = EventTableToSchema diff --git a/pkg/schemas/external_function_gen.go b/pkg/schemas/external_function_gen.go new file mode 100644 index 0000000000..4439ec7d18 --- /dev/null +++ b/pkg/schemas/external_function_gen.go @@ -0,0 +1,111 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowExternalFunctionSchema represents output of SHOW query for the single ExternalFunction. +var ShowExternalFunctionSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "schema_name": { + Type: schema.TypeString, + Computed: true, + }, + "is_builtin": { + Type: schema.TypeBool, + Computed: true, + }, + "is_aggregate": { + Type: schema.TypeBool, + Computed: true, + }, + "is_ansi": { + Type: schema.TypeBool, + Computed: true, + }, + "min_num_arguments": { + Type: schema.TypeInt, + Computed: true, + }, + "max_num_arguments": { + Type: schema.TypeInt, + Computed: true, + }, + "arguments": { + Type: schema.TypeString, + Computed: true, + }, + "description": { + Type: schema.TypeString, + Computed: true, + }, + "catalog_name": { + Type: schema.TypeString, + Computed: true, + }, + "is_table_function": { + Type: schema.TypeBool, + Computed: true, + }, + "valid_for_clustering": { + Type: schema.TypeBool, + Computed: true, + }, + "is_secure": { + Type: schema.TypeBool, + Computed: true, + }, + "is_external_function": { + Type: schema.TypeBool, + Computed: true, + }, + "language": { + Type: schema.TypeString, + Computed: true, + }, + "is_memoizable": { + Type: schema.TypeBool, + Computed: true, + }, + "is_data_metric": { + Type: schema.TypeBool, + Computed: true, + }, +} + +var _ = ShowExternalFunctionSchema + +func ExternalFunctionToSchema(externalFunction *sdk.ExternalFunction) map[string]any { + externalFunctionSchema := make(map[string]any) + externalFunctionSchema["created_on"] = externalFunction.CreatedOn + externalFunctionSchema["name"] = externalFunction.Name + externalFunctionSchema["schema_name"] = externalFunction.SchemaName + externalFunctionSchema["is_builtin"] = externalFunction.IsBuiltin + externalFunctionSchema["is_aggregate"] = externalFunction.IsAggregate + externalFunctionSchema["is_ansi"] = externalFunction.IsAnsi + externalFunctionSchema["min_num_arguments"] = externalFunction.MinNumArguments + externalFunctionSchema["max_num_arguments"] = externalFunction.MaxNumArguments + externalFunctionSchema["arguments"] = externalFunction.Arguments + externalFunctionSchema["description"] = externalFunction.Description + externalFunctionSchema["catalog_name"] = externalFunction.CatalogName + externalFunctionSchema["is_table_function"] = externalFunction.IsTableFunction + externalFunctionSchema["valid_for_clustering"] = externalFunction.ValidForClustering + externalFunctionSchema["is_secure"] = externalFunction.IsSecure + externalFunctionSchema["is_external_function"] = externalFunction.IsExternalFunction + externalFunctionSchema["language"] = externalFunction.Language + externalFunctionSchema["is_memoizable"] = externalFunction.IsMemoizable + externalFunctionSchema["is_data_metric"] = externalFunction.IsDataMetric + return externalFunctionSchema +} + +var _ = ExternalFunctionToSchema diff --git a/pkg/schemas/external_table_gen.go b/pkg/schemas/external_table_gen.go new file mode 100644 index 0000000000..5ca444a71d --- /dev/null +++ b/pkg/schemas/external_table_gen.go @@ -0,0 +1,116 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowExternalTableSchema represents output of SHOW query for the single ExternalTable. +var ShowExternalTableSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "database_name": { + Type: schema.TypeString, + Computed: true, + }, + "schema_name": { + Type: schema.TypeString, + Computed: true, + }, + "invalid": { + Type: schema.TypeBool, + Computed: true, + }, + "invalid_reason": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "stage": { + Type: schema.TypeString, + Computed: true, + }, + "location": { + Type: schema.TypeString, + Computed: true, + }, + "file_format_name": { + Type: schema.TypeString, + Computed: true, + }, + "file_format_type": { + Type: schema.TypeString, + Computed: true, + }, + "cloud": { + Type: schema.TypeString, + Computed: true, + }, + "region": { + Type: schema.TypeString, + Computed: true, + }, + "notification_channel": { + Type: schema.TypeString, + Computed: true, + }, + "last_refreshed_on": { + Type: schema.TypeString, + Computed: true, + }, + "table_format": { + Type: schema.TypeString, + Computed: true, + }, + "last_refresh_details": { + Type: schema.TypeString, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowExternalTableSchema + +func ExternalTableToSchema(externalTable *sdk.ExternalTable) map[string]any { + externalTableSchema := make(map[string]any) + externalTableSchema["created_on"] = externalTable.CreatedOn.String() + externalTableSchema["name"] = externalTable.Name + externalTableSchema["database_name"] = externalTable.DatabaseName + externalTableSchema["schema_name"] = externalTable.SchemaName + externalTableSchema["invalid"] = externalTable.Invalid + externalTableSchema["invalid_reason"] = externalTable.InvalidReason + externalTableSchema["owner"] = externalTable.Owner + externalTableSchema["comment"] = externalTable.Comment + externalTableSchema["stage"] = externalTable.Stage + externalTableSchema["location"] = externalTable.Location + externalTableSchema["file_format_name"] = externalTable.FileFormatName + externalTableSchema["file_format_type"] = externalTable.FileFormatType + externalTableSchema["cloud"] = externalTable.Cloud + externalTableSchema["region"] = externalTable.Region + externalTableSchema["notification_channel"] = externalTable.NotificationChannel + externalTableSchema["last_refreshed_on"] = externalTable.LastRefreshedOn.String() + externalTableSchema["table_format"] = externalTable.TableFormat + externalTableSchema["last_refresh_details"] = externalTable.LastRefreshDetails + externalTableSchema["owner_role_type"] = externalTable.OwnerRoleType + return externalTableSchema +} + +var _ = ExternalTableToSchema diff --git a/pkg/schemas/failover_group_gen.go b/pkg/schemas/failover_group_gen.go new file mode 100644 index 0000000000..4698ca8872 --- /dev/null +++ b/pkg/schemas/failover_group_gen.go @@ -0,0 +1,111 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowFailoverGroupSchema represents output of SHOW query for the single FailoverGroup. +var ShowFailoverGroupSchema = map[string]*schema.Schema{ + "region_group": { + Type: schema.TypeString, + Computed: true, + }, + "snowflake_region": { + Type: schema.TypeString, + Computed: true, + }, + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "is_primary": { + Type: schema.TypeBool, + Computed: true, + }, + "primary": { + Type: schema.TypeString, + Computed: true, + }, + "object_types": { + Type: schema.TypeInvalid, + Computed: true, + }, + "allowed_integration_types": { + Type: schema.TypeInvalid, + Computed: true, + }, + "allowed_accounts": { + Type: schema.TypeInvalid, + Computed: true, + }, + "organization_name": { + Type: schema.TypeString, + Computed: true, + }, + "account_locator": { + Type: schema.TypeString, + Computed: true, + }, + "replication_schedule": { + Type: schema.TypeString, + Computed: true, + }, + "secondary_state": { + Type: schema.TypeString, + Computed: true, + }, + "next_scheduled_refresh": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowFailoverGroupSchema + +func FailoverGroupToSchema(failoverGroup *sdk.FailoverGroup) map[string]any { + failoverGroupSchema := make(map[string]any) + failoverGroupSchema["region_group"] = failoverGroup.RegionGroup + failoverGroupSchema["snowflake_region"] = failoverGroup.SnowflakeRegion + failoverGroupSchema["created_on"] = failoverGroup.CreatedOn.String() + failoverGroupSchema["account_name"] = failoverGroup.AccountName + failoverGroupSchema["name"] = failoverGroup.Name + failoverGroupSchema["type"] = failoverGroup.Type + failoverGroupSchema["comment"] = failoverGroup.Comment + failoverGroupSchema["is_primary"] = failoverGroup.IsPrimary + failoverGroupSchema["primary"] = failoverGroup.Primary.FullyQualifiedName() + failoverGroupSchema["object_types"] = failoverGroup.ObjectTypes + failoverGroupSchema["allowed_integration_types"] = failoverGroup.AllowedIntegrationTypes + failoverGroupSchema["allowed_accounts"] = failoverGroup.AllowedAccounts + failoverGroupSchema["organization_name"] = failoverGroup.OrganizationName + failoverGroupSchema["account_locator"] = failoverGroup.AccountLocator + failoverGroupSchema["replication_schedule"] = failoverGroup.ReplicationSchedule + failoverGroupSchema["secondary_state"] = string(failoverGroup.SecondaryState) + failoverGroupSchema["next_scheduled_refresh"] = failoverGroup.NextScheduledRefresh + failoverGroupSchema["owner"] = failoverGroup.Owner + return failoverGroupSchema +} + +var _ = FailoverGroupToSchema diff --git a/pkg/schemas/file_format_gen.go b/pkg/schemas/file_format_gen.go new file mode 100644 index 0000000000..95fa91eb45 --- /dev/null +++ b/pkg/schemas/file_format_gen.go @@ -0,0 +1,56 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowFileFormatSchema represents output of SHOW query for the single FileFormat. +var ShowFileFormatSchema = map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, + "options": { + Type: schema.TypeInvalid, + Computed: true, + }, +} + +var _ = ShowFileFormatSchema + +func FileFormatToSchema(fileFormat *sdk.FileFormat) map[string]any { + fileFormatSchema := make(map[string]any) + fileFormatSchema["name"] = fileFormat.Name.FullyQualifiedName() + fileFormatSchema["created_on"] = fileFormat.CreatedOn.String() + fileFormatSchema["type"] = string(fileFormat.Type) + fileFormatSchema["owner"] = fileFormat.Owner + fileFormatSchema["comment"] = fileFormat.Comment + fileFormatSchema["owner_role_type"] = fileFormat.OwnerRoleType + fileFormatSchema["options"] = fileFormat.Options + return fileFormatSchema +} + +var _ = FileFormatToSchema diff --git a/pkg/schemas/function_gen.go b/pkg/schemas/function_gen.go new file mode 100644 index 0000000000..c915b1831e --- /dev/null +++ b/pkg/schemas/function_gen.go @@ -0,0 +1,106 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowFunctionSchema represents output of SHOW query for the single Function. +var ShowFunctionSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "schema_name": { + Type: schema.TypeString, + Computed: true, + }, + "is_builtin": { + Type: schema.TypeBool, + Computed: true, + }, + "is_aggregate": { + Type: schema.TypeBool, + Computed: true, + }, + "is_ansi": { + Type: schema.TypeBool, + Computed: true, + }, + "min_num_arguments": { + Type: schema.TypeInt, + Computed: true, + }, + "max_num_arguments": { + Type: schema.TypeInt, + Computed: true, + }, + "arguments": { + Type: schema.TypeString, + Computed: true, + }, + "description": { + Type: schema.TypeString, + Computed: true, + }, + "catalog_name": { + Type: schema.TypeString, + Computed: true, + }, + "is_table_function": { + Type: schema.TypeBool, + Computed: true, + }, + "valid_for_clustering": { + Type: schema.TypeBool, + Computed: true, + }, + "is_secure": { + Type: schema.TypeBool, + Computed: true, + }, + "is_external_function": { + Type: schema.TypeBool, + Computed: true, + }, + "language": { + Type: schema.TypeString, + Computed: true, + }, + "is_memoizable": { + Type: schema.TypeBool, + Computed: true, + }, +} + +var _ = ShowFunctionSchema + +func FunctionToSchema(function *sdk.Function) map[string]any { + functionSchema := make(map[string]any) + functionSchema["created_on"] = function.CreatedOn + functionSchema["name"] = function.Name + functionSchema["schema_name"] = function.SchemaName + functionSchema["is_builtin"] = function.IsBuiltin + functionSchema["is_aggregate"] = function.IsAggregate + functionSchema["is_ansi"] = function.IsAnsi + functionSchema["min_num_arguments"] = function.MinNumArguments + functionSchema["max_num_arguments"] = function.MaxNumArguments + functionSchema["arguments"] = function.Arguments + functionSchema["description"] = function.Description + functionSchema["catalog_name"] = function.CatalogName + functionSchema["is_table_function"] = function.IsTableFunction + functionSchema["valid_for_clustering"] = function.ValidForClustering + functionSchema["is_secure"] = function.IsSecure + functionSchema["is_external_function"] = function.IsExternalFunction + functionSchema["language"] = function.Language + functionSchema["is_memoizable"] = function.IsMemoizable + return functionSchema +} + +var _ = FunctionToSchema diff --git a/pkg/schemas/grant_gen.go b/pkg/schemas/grant_gen.go new file mode 100644 index 0000000000..aae677fe4b --- /dev/null +++ b/pkg/schemas/grant_gen.go @@ -0,0 +1,71 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowGrantSchema represents output of SHOW query for the single Grant. +var ShowGrantSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "privilege": { + Type: schema.TypeString, + Computed: true, + }, + "granted_on": { + Type: schema.TypeString, + Computed: true, + }, + "grant_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "granted_to": { + Type: schema.TypeString, + Computed: true, + }, + "grant_to": { + Type: schema.TypeString, + Computed: true, + }, + "grantee_name": { + Type: schema.TypeString, + Computed: true, + }, + "grant_option": { + Type: schema.TypeBool, + Computed: true, + }, + "granted_by": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowGrantSchema + +func GrantToSchema(grant *sdk.Grant) map[string]any { + grantSchema := make(map[string]any) + grantSchema["created_on"] = grant.CreatedOn.String() + grantSchema["privilege"] = grant.Privilege + grantSchema["granted_on"] = string(grant.GrantedOn) + grantSchema["grant_on"] = string(grant.GrantOn) + grantSchema["name"] = grant.Name.FullyQualifiedName() + grantSchema["granted_to"] = string(grant.GrantedTo) + grantSchema["grant_to"] = string(grant.GrantTo) + grantSchema["grantee_name"] = grant.GranteeName.FullyQualifiedName() + grantSchema["grant_option"] = grant.GrantOption + grantSchema["granted_by"] = grant.GrantedBy.FullyQualifiedName() + return grantSchema +} + +var _ = GrantToSchema diff --git a/pkg/schemas/managed_account_gen.go b/pkg/schemas/managed_account_gen.go new file mode 100644 index 0000000000..25bf18febb --- /dev/null +++ b/pkg/schemas/managed_account_gen.go @@ -0,0 +1,66 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowManagedAccountSchema represents output of SHOW query for the single ManagedAccount. +var ShowManagedAccountSchema = map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "cloud": { + Type: schema.TypeString, + Computed: true, + }, + "region": { + Type: schema.TypeString, + Computed: true, + }, + "locator": { + Type: schema.TypeString, + Computed: true, + }, + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "url": { + Type: schema.TypeString, + Computed: true, + }, + "account_locator_url": { + Type: schema.TypeString, + Computed: true, + }, + "is_reader": { + Type: schema.TypeBool, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowManagedAccountSchema + +func ManagedAccountToSchema(managedAccount *sdk.ManagedAccount) map[string]any { + managedAccountSchema := make(map[string]any) + managedAccountSchema["name"] = managedAccount.Name + managedAccountSchema["cloud"] = managedAccount.Cloud + managedAccountSchema["region"] = managedAccount.Region + managedAccountSchema["locator"] = managedAccount.Locator + managedAccountSchema["created_on"] = managedAccount.CreatedOn + managedAccountSchema["url"] = managedAccount.URL + managedAccountSchema["account_locator_url"] = managedAccount.AccountLocatorURL + managedAccountSchema["is_reader"] = managedAccount.IsReader + managedAccountSchema["comment"] = managedAccount.Comment + return managedAccountSchema +} + +var _ = ManagedAccountToSchema diff --git a/pkg/schemas/masking_policy_gen.go b/pkg/schemas/masking_policy_gen.go new file mode 100644 index 0000000000..6aad9f5565 --- /dev/null +++ b/pkg/schemas/masking_policy_gen.go @@ -0,0 +1,66 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowMaskingPolicySchema represents output of SHOW query for the single MaskingPolicy. +var ShowMaskingPolicySchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "database_name": { + Type: schema.TypeString, + Computed: true, + }, + "schema_name": { + Type: schema.TypeString, + Computed: true, + }, + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "exempt_other_policies": { + Type: schema.TypeBool, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowMaskingPolicySchema + +func MaskingPolicyToSchema(maskingPolicy *sdk.MaskingPolicy) map[string]any { + maskingPolicySchema := make(map[string]any) + maskingPolicySchema["created_on"] = maskingPolicy.CreatedOn.String() + maskingPolicySchema["name"] = maskingPolicy.Name + maskingPolicySchema["database_name"] = maskingPolicy.DatabaseName + maskingPolicySchema["schema_name"] = maskingPolicy.SchemaName + maskingPolicySchema["kind"] = maskingPolicy.Kind + maskingPolicySchema["owner"] = maskingPolicy.Owner + maskingPolicySchema["comment"] = maskingPolicy.Comment + maskingPolicySchema["exempt_other_policies"] = maskingPolicy.ExemptOtherPolicies + maskingPolicySchema["owner_role_type"] = maskingPolicy.OwnerRoleType + return maskingPolicySchema +} + +var _ = MaskingPolicyToSchema diff --git a/pkg/schemas/materialized_view_gen.go b/pkg/schemas/materialized_view_gen.go new file mode 100644 index 0000000000..aa8c910e65 --- /dev/null +++ b/pkg/schemas/materialized_view_gen.go @@ -0,0 +1,138 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowMaterializedViewSchema represents output of SHOW query for the single MaterializedView. +var ShowMaterializedViewSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "reserved": { + Type: schema.TypeString, + Computed: true, + }, + "database_name": { + Type: schema.TypeString, + Computed: true, + }, + "schema_name": { + Type: schema.TypeString, + Computed: true, + }, + "cluster_by": { + Type: schema.TypeString, + Computed: true, + }, + "rows": { + Type: schema.TypeInt, + Computed: true, + }, + "bytes": { + Type: schema.TypeInt, + Computed: true, + }, + "source_database_name": { + Type: schema.TypeString, + Computed: true, + }, + "source_schema_name": { + Type: schema.TypeString, + Computed: true, + }, + "source_table_name": { + Type: schema.TypeString, + Computed: true, + }, + "refreshed_on": { + Type: schema.TypeString, + Computed: true, + }, + "compacted_on": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "invalid": { + Type: schema.TypeBool, + Computed: true, + }, + "invalid_reason": { + Type: schema.TypeString, + Computed: true, + }, + "behind_by": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "text": { + Type: schema.TypeString, + Computed: true, + }, + "is_secure": { + Type: schema.TypeBool, + Computed: true, + }, + "automatic_clustering": { + Type: schema.TypeBool, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, + "budget": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowMaterializedViewSchema + +func MaterializedViewToSchema(materializedView *sdk.MaterializedView) map[string]any { + materializedViewSchema := make(map[string]any) + materializedViewSchema["created_on"] = materializedView.CreatedOn + materializedViewSchema["name"] = materializedView.Name + if materializedView.Reserved != nil { + materializedViewSchema["reserved"] = materializedView.Reserved + } + materializedViewSchema["database_name"] = materializedView.DatabaseName + materializedViewSchema["schema_name"] = materializedView.SchemaName + materializedViewSchema["cluster_by"] = materializedView.ClusterBy + materializedViewSchema["rows"] = materializedView.Rows + materializedViewSchema["bytes"] = materializedView.Bytes + materializedViewSchema["source_database_name"] = materializedView.SourceDatabaseName + materializedViewSchema["source_schema_name"] = materializedView.SourceSchemaName + materializedViewSchema["source_table_name"] = materializedView.SourceTableName + materializedViewSchema["refreshed_on"] = materializedView.RefreshedOn.String() + materializedViewSchema["compacted_on"] = materializedView.CompactedOn.String() + materializedViewSchema["owner"] = materializedView.Owner + materializedViewSchema["invalid"] = materializedView.Invalid + materializedViewSchema["invalid_reason"] = materializedView.InvalidReason + materializedViewSchema["behind_by"] = materializedView.BehindBy + materializedViewSchema["comment"] = materializedView.Comment + materializedViewSchema["text"] = materializedView.Text + materializedViewSchema["is_secure"] = materializedView.IsSecure + materializedViewSchema["automatic_clustering"] = materializedView.AutomaticClustering + materializedViewSchema["owner_role_type"] = materializedView.OwnerRoleType + materializedViewSchema["budget"] = materializedView.Budget + return materializedViewSchema +} + +var _ = MaterializedViewToSchema diff --git a/pkg/schemas/network_policy_gen.go b/pkg/schemas/network_policy_gen.go new file mode 100644 index 0000000000..787f4e7840 --- /dev/null +++ b/pkg/schemas/network_policy_gen.go @@ -0,0 +1,56 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowNetworkPolicySchema represents output of SHOW query for the single NetworkPolicy. +var ShowNetworkPolicySchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "entries_in_allowed_ip_list": { + Type: schema.TypeInt, + Computed: true, + }, + "entries_in_blocked_ip_list": { + Type: schema.TypeInt, + Computed: true, + }, + "entries_in_allowed_network_rules": { + Type: schema.TypeInt, + Computed: true, + }, + "entries_in_blocked_network_rules": { + Type: schema.TypeInt, + Computed: true, + }, +} + +var _ = ShowNetworkPolicySchema + +func NetworkPolicyToSchema(networkPolicy *sdk.NetworkPolicy) map[string]any { + networkPolicySchema := make(map[string]any) + networkPolicySchema["created_on"] = networkPolicy.CreatedOn + networkPolicySchema["name"] = networkPolicy.Name + networkPolicySchema["comment"] = networkPolicy.Comment + networkPolicySchema["entries_in_allowed_ip_list"] = networkPolicy.EntriesInAllowedIpList + networkPolicySchema["entries_in_blocked_ip_list"] = networkPolicy.EntriesInBlockedIpList + networkPolicySchema["entries_in_allowed_network_rules"] = networkPolicy.EntriesInAllowedNetworkRules + networkPolicySchema["entries_in_blocked_network_rules"] = networkPolicy.EntriesInBlockedNetworkRules + return networkPolicySchema +} + +var _ = NetworkPolicyToSchema diff --git a/pkg/schemas/network_rule_gen.go b/pkg/schemas/network_rule_gen.go new file mode 100644 index 0000000000..88265ac4a7 --- /dev/null +++ b/pkg/schemas/network_rule_gen.go @@ -0,0 +1,71 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowNetworkRuleSchema represents output of SHOW query for the single NetworkRule. +var ShowNetworkRuleSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "database_name": { + Type: schema.TypeString, + Computed: true, + }, + "schema_name": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "mode": { + Type: schema.TypeString, + Computed: true, + }, + "entries_in_value_list": { + Type: schema.TypeInt, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowNetworkRuleSchema + +func NetworkRuleToSchema(networkRule *sdk.NetworkRule) map[string]any { + networkRuleSchema := make(map[string]any) + networkRuleSchema["created_on"] = networkRule.CreatedOn.String() + networkRuleSchema["name"] = networkRule.Name + networkRuleSchema["database_name"] = networkRule.DatabaseName + networkRuleSchema["schema_name"] = networkRule.SchemaName + networkRuleSchema["owner"] = networkRule.Owner + networkRuleSchema["comment"] = networkRule.Comment + networkRuleSchema["type"] = string(networkRule.Type) + networkRuleSchema["mode"] = string(networkRule.Mode) + networkRuleSchema["entries_in_value_list"] = networkRule.EntriesInValueList + networkRuleSchema["owner_role_type"] = networkRule.OwnerRoleType + return networkRuleSchema +} + +var _ = NetworkRuleToSchema diff --git a/pkg/schemas/notification_integration_gen.go b/pkg/schemas/notification_integration_gen.go new file mode 100644 index 0000000000..3f6868626f --- /dev/null +++ b/pkg/schemas/notification_integration_gen.go @@ -0,0 +1,51 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowNotificationIntegrationSchema represents output of SHOW query for the single NotificationIntegration. +var ShowNotificationIntegrationSchema = map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "notification_type": { + Type: schema.TypeString, + Computed: true, + }, + "category": { + Type: schema.TypeString, + Computed: true, + }, + "enabled": { + Type: schema.TypeBool, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "created_on": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowNotificationIntegrationSchema + +func NotificationIntegrationToSchema(notificationIntegration *sdk.NotificationIntegration) map[string]any { + notificationIntegrationSchema := make(map[string]any) + notificationIntegrationSchema["name"] = notificationIntegration.Name + notificationIntegrationSchema["notification_type"] = notificationIntegration.NotificationType + notificationIntegrationSchema["category"] = notificationIntegration.Category + notificationIntegrationSchema["enabled"] = notificationIntegration.Enabled + notificationIntegrationSchema["comment"] = notificationIntegration.Comment + notificationIntegrationSchema["created_on"] = notificationIntegration.CreatedOn.String() + return notificationIntegrationSchema +} + +var _ = NotificationIntegrationToSchema diff --git a/pkg/schemas/parameter_gen.go b/pkg/schemas/parameter_gen.go new file mode 100644 index 0000000000..6768669b9b --- /dev/null +++ b/pkg/schemas/parameter_gen.go @@ -0,0 +1,46 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowParameterSchema represents output of SHOW query for the single Parameter. +var ShowParameterSchema = map[string]*schema.Schema{ + "key": { + Type: schema.TypeString, + Computed: true, + }, + "value": { + Type: schema.TypeString, + Computed: true, + }, + "default": { + Type: schema.TypeString, + Computed: true, + }, + "level": { + Type: schema.TypeString, + Computed: true, + }, + "description": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowParameterSchema + +func ParameterToSchema(parameter *sdk.Parameter) map[string]any { + parameterSchema := make(map[string]any) + parameterSchema["key"] = parameter.Key + parameterSchema["value"] = parameter.Value + parameterSchema["default"] = parameter.Default + parameterSchema["level"] = string(parameter.Level) + parameterSchema["description"] = parameter.Description + return parameterSchema +} + +var _ = ParameterToSchema diff --git a/pkg/schemas/password_policy_gen.go b/pkg/schemas/password_policy_gen.go new file mode 100644 index 0000000000..659ded7898 --- /dev/null +++ b/pkg/schemas/password_policy_gen.go @@ -0,0 +1,61 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowPasswordPolicySchema represents output of SHOW query for the single PasswordPolicy. +var ShowPasswordPolicySchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "database_name": { + Type: schema.TypeString, + Computed: true, + }, + "schema_name": { + Type: schema.TypeString, + Computed: true, + }, + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowPasswordPolicySchema + +func PasswordPolicyToSchema(passwordPolicy *sdk.PasswordPolicy) map[string]any { + passwordPolicySchema := make(map[string]any) + passwordPolicySchema["created_on"] = passwordPolicy.CreatedOn.String() + passwordPolicySchema["name"] = passwordPolicy.Name + passwordPolicySchema["database_name"] = passwordPolicy.DatabaseName + passwordPolicySchema["schema_name"] = passwordPolicy.SchemaName + passwordPolicySchema["kind"] = passwordPolicy.Kind + passwordPolicySchema["owner"] = passwordPolicy.Owner + passwordPolicySchema["comment"] = passwordPolicy.Comment + passwordPolicySchema["owner_role_type"] = passwordPolicy.OwnerRoleType + return passwordPolicySchema +} + +var _ = PasswordPolicyToSchema diff --git a/pkg/schemas/pipe_gen.go b/pkg/schemas/pipe_gen.go new file mode 100644 index 0000000000..788242af64 --- /dev/null +++ b/pkg/schemas/pipe_gen.go @@ -0,0 +1,86 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowPipeSchema represents output of SHOW query for the single Pipe. +var ShowPipeSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "database_name": { + Type: schema.TypeString, + Computed: true, + }, + "schema_name": { + Type: schema.TypeString, + Computed: true, + }, + "definition": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "notification_channel": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "integration": { + Type: schema.TypeString, + Computed: true, + }, + "pattern": { + Type: schema.TypeString, + Computed: true, + }, + "error_integration": { + Type: schema.TypeString, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, + "invalid_reason": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowPipeSchema + +func PipeToSchema(pipe *sdk.Pipe) map[string]any { + pipeSchema := make(map[string]any) + pipeSchema["created_on"] = pipe.CreatedOn + pipeSchema["name"] = pipe.Name + pipeSchema["database_name"] = pipe.DatabaseName + pipeSchema["schema_name"] = pipe.SchemaName + pipeSchema["definition"] = pipe.Definition + pipeSchema["owner"] = pipe.Owner + pipeSchema["notification_channel"] = pipe.NotificationChannel + pipeSchema["comment"] = pipe.Comment + pipeSchema["integration"] = pipe.Integration + pipeSchema["pattern"] = pipe.Pattern + pipeSchema["error_integration"] = pipe.ErrorIntegration + pipeSchema["owner_role_type"] = pipe.OwnerRoleType + pipeSchema["invalid_reason"] = pipe.InvalidReason + return pipeSchema +} + +var _ = PipeToSchema diff --git a/pkg/schemas/policy_reference_gen.go b/pkg/schemas/policy_reference_gen.go new file mode 100644 index 0000000000..5927ed2da0 --- /dev/null +++ b/pkg/schemas/policy_reference_gen.go @@ -0,0 +1,111 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowPolicyReferenceSchema represents output of SHOW query for the single PolicyReference. +var ShowPolicyReferenceSchema = map[string]*schema.Schema{ + "policy_db": { + Type: schema.TypeString, + Computed: true, + }, + "policy_schema": { + Type: schema.TypeString, + Computed: true, + }, + "policy_name": { + Type: schema.TypeString, + Computed: true, + }, + "policy_kind": { + Type: schema.TypeString, + Computed: true, + }, + "ref_database_name": { + Type: schema.TypeString, + Computed: true, + }, + "ref_schema_name": { + Type: schema.TypeString, + Computed: true, + }, + "ref_entity_name": { + Type: schema.TypeString, + Computed: true, + }, + "ref_entity_domain": { + Type: schema.TypeString, + Computed: true, + }, + "ref_column_name": { + Type: schema.TypeString, + Computed: true, + }, + "ref_arg_column_names": { + Type: schema.TypeString, + Computed: true, + }, + "tag_database": { + Type: schema.TypeString, + Computed: true, + }, + "tag_schema": { + Type: schema.TypeString, + Computed: true, + }, + "tag_name": { + Type: schema.TypeString, + Computed: true, + }, + "policy_status": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowPolicyReferenceSchema + +func PolicyReferenceToSchema(policyReference *sdk.PolicyReference) map[string]any { + policyReferenceSchema := make(map[string]any) + if policyReference.PolicyDb != nil { + policyReferenceSchema["policy_db"] = policyReference.PolicyDb + } + if policyReference.PolicySchema != nil { + policyReferenceSchema["policy_schema"] = policyReference.PolicySchema + } + policyReferenceSchema["policy_name"] = policyReference.PolicyName + policyReferenceSchema["policy_kind"] = policyReference.PolicyKind + if policyReference.RefDatabaseName != nil { + policyReferenceSchema["ref_database_name"] = policyReference.RefDatabaseName + } + if policyReference.RefSchemaName != nil { + policyReferenceSchema["ref_schema_name"] = policyReference.RefSchemaName + } + policyReferenceSchema["ref_entity_name"] = policyReference.RefEntityName + policyReferenceSchema["ref_entity_domain"] = policyReference.RefEntityDomain + if policyReference.RefColumnName != nil { + policyReferenceSchema["ref_column_name"] = policyReference.RefColumnName + } + if policyReference.RefArgColumnNames != nil { + policyReferenceSchema["ref_arg_column_names"] = policyReference.RefArgColumnNames + } + if policyReference.TagDatabase != nil { + policyReferenceSchema["tag_database"] = policyReference.TagDatabase + } + if policyReference.TagSchema != nil { + policyReferenceSchema["tag_schema"] = policyReference.TagSchema + } + if policyReference.TagName != nil { + policyReferenceSchema["tag_name"] = policyReference.TagName + } + if policyReference.PolicyStatus != nil { + policyReferenceSchema["policy_status"] = policyReference.PolicyStatus + } + return policyReferenceSchema +} + +var _ = PolicyReferenceToSchema diff --git a/pkg/schemas/procedure_gen.go b/pkg/schemas/procedure_gen.go new file mode 100644 index 0000000000..eae6eb0b7d --- /dev/null +++ b/pkg/schemas/procedure_gen.go @@ -0,0 +1,91 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowProcedureSchema represents output of SHOW query for the single Procedure. +var ShowProcedureSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "schema_name": { + Type: schema.TypeString, + Computed: true, + }, + "is_builtin": { + Type: schema.TypeBool, + Computed: true, + }, + "is_aggregate": { + Type: schema.TypeBool, + Computed: true, + }, + "is_ansi": { + Type: schema.TypeBool, + Computed: true, + }, + "min_num_arguments": { + Type: schema.TypeInt, + Computed: true, + }, + "max_num_arguments": { + Type: schema.TypeInt, + Computed: true, + }, + "arguments": { + Type: schema.TypeString, + Computed: true, + }, + "description": { + Type: schema.TypeString, + Computed: true, + }, + "catalog_name": { + Type: schema.TypeString, + Computed: true, + }, + "is_table_function": { + Type: schema.TypeBool, + Computed: true, + }, + "valid_for_clustering": { + Type: schema.TypeBool, + Computed: true, + }, + "is_secure": { + Type: schema.TypeBool, + Computed: true, + }, +} + +var _ = ShowProcedureSchema + +func ProcedureToSchema(procedure *sdk.Procedure) map[string]any { + procedureSchema := make(map[string]any) + procedureSchema["created_on"] = procedure.CreatedOn + procedureSchema["name"] = procedure.Name + procedureSchema["schema_name"] = procedure.SchemaName + procedureSchema["is_builtin"] = procedure.IsBuiltin + procedureSchema["is_aggregate"] = procedure.IsAggregate + procedureSchema["is_ansi"] = procedure.IsAnsi + procedureSchema["min_num_arguments"] = procedure.MinNumArguments + procedureSchema["max_num_arguments"] = procedure.MaxNumArguments + procedureSchema["arguments"] = procedure.Arguments + procedureSchema["description"] = procedure.Description + procedureSchema["catalog_name"] = procedure.CatalogName + procedureSchema["is_table_function"] = procedure.IsTableFunction + procedureSchema["valid_for_clustering"] = procedure.ValidForClustering + procedureSchema["is_secure"] = procedure.IsSecure + return procedureSchema +} + +var _ = ProcedureToSchema diff --git a/pkg/schemas/region_gen.go b/pkg/schemas/region_gen.go new file mode 100644 index 0000000000..e750a1f10b --- /dev/null +++ b/pkg/schemas/region_gen.go @@ -0,0 +1,46 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowRegionSchema represents output of SHOW query for the single Region. +var ShowRegionSchema = map[string]*schema.Schema{ + "region_group": { + Type: schema.TypeString, + Computed: true, + }, + "snowflake_region": { + Type: schema.TypeString, + Computed: true, + }, + "cloud_type": { + Type: schema.TypeString, + Computed: true, + }, + "region": { + Type: schema.TypeString, + Computed: true, + }, + "display_name": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowRegionSchema + +func RegionToSchema(region *sdk.Region) map[string]any { + regionSchema := make(map[string]any) + regionSchema["region_group"] = region.RegionGroup + regionSchema["snowflake_region"] = region.SnowflakeRegion + regionSchema["cloud_type"] = string(region.CloudType) + regionSchema["region"] = region.Region + regionSchema["display_name"] = region.DisplayName + return regionSchema +} + +var _ = RegionToSchema diff --git a/pkg/schemas/replication_account_gen.go b/pkg/schemas/replication_account_gen.go new file mode 100644 index 0000000000..214d1602e5 --- /dev/null +++ b/pkg/schemas/replication_account_gen.go @@ -0,0 +1,56 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowReplicationAccountSchema represents output of SHOW query for the single ReplicationAccount. +var ShowReplicationAccountSchema = map[string]*schema.Schema{ + "snowflake_region": { + Type: schema.TypeString, + Computed: true, + }, + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + }, + "account_locator": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "organization_name": { + Type: schema.TypeString, + Computed: true, + }, + "is_org_admin": { + Type: schema.TypeBool, + Computed: true, + }, +} + +var _ = ShowReplicationAccountSchema + +func ReplicationAccountToSchema(replicationAccount *sdk.ReplicationAccount) map[string]any { + replicationAccountSchema := make(map[string]any) + replicationAccountSchema["snowflake_region"] = replicationAccount.SnowflakeRegion + replicationAccountSchema["created_on"] = replicationAccount.CreatedOn.String() + replicationAccountSchema["account_name"] = replicationAccount.AccountName + replicationAccountSchema["account_locator"] = replicationAccount.AccountLocator + replicationAccountSchema["comment"] = replicationAccount.Comment + replicationAccountSchema["organization_name"] = replicationAccount.OrganizationName + replicationAccountSchema["is_org_admin"] = replicationAccount.IsOrgAdmin + return replicationAccountSchema +} + +var _ = ReplicationAccountToSchema diff --git a/pkg/schemas/replication_database_gen.go b/pkg/schemas/replication_database_gen.go new file mode 100644 index 0000000000..c121465956 --- /dev/null +++ b/pkg/schemas/replication_database_gen.go @@ -0,0 +1,81 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowReplicationDatabaseSchema represents output of SHOW query for the single ReplicationDatabase. +var ShowReplicationDatabaseSchema = map[string]*schema.Schema{ + "region_group": { + Type: schema.TypeString, + Computed: true, + }, + "snowflake_region": { + Type: schema.TypeString, + Computed: true, + }, + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "is_primary": { + Type: schema.TypeBool, + Computed: true, + }, + "primary_database": { + Type: schema.TypeString, + Computed: true, + }, + "replication_allowed_to_accounts": { + Type: schema.TypeString, + Computed: true, + }, + "failover_allowed_to_accounts": { + Type: schema.TypeString, + Computed: true, + }, + "organization_name": { + Type: schema.TypeString, + Computed: true, + }, + "account_locator": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowReplicationDatabaseSchema + +func ReplicationDatabaseToSchema(replicationDatabase *sdk.ReplicationDatabase) map[string]any { + replicationDatabaseSchema := make(map[string]any) + replicationDatabaseSchema["region_group"] = replicationDatabase.RegionGroup + replicationDatabaseSchema["snowflake_region"] = replicationDatabase.SnowflakeRegion + replicationDatabaseSchema["created_on"] = replicationDatabase.CreatedOn + replicationDatabaseSchema["account_name"] = replicationDatabase.AccountName + replicationDatabaseSchema["name"] = replicationDatabase.Name + replicationDatabaseSchema["comment"] = replicationDatabase.Comment + replicationDatabaseSchema["is_primary"] = replicationDatabase.IsPrimary + replicationDatabaseSchema["primary_database"] = replicationDatabase.PrimaryDatabase + replicationDatabaseSchema["replication_allowed_to_accounts"] = replicationDatabase.ReplicationAllowedToAccounts + replicationDatabaseSchema["failover_allowed_to_accounts"] = replicationDatabase.FailoverAllowedToAccounts + replicationDatabaseSchema["organization_name"] = replicationDatabase.OrganizationName + replicationDatabaseSchema["account_locator"] = replicationDatabase.AccountLocator + return replicationDatabaseSchema +} + +var _ = ReplicationDatabaseToSchema diff --git a/pkg/schemas/resource_monitor_gen.go b/pkg/schemas/resource_monitor_gen.go new file mode 100644 index 0000000000..01977298ec --- /dev/null +++ b/pkg/schemas/resource_monitor_gen.go @@ -0,0 +1,90 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowResourceMonitorSchema represents output of SHOW query for the single ResourceMonitor. +var ShowResourceMonitorSchema = map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "credit_quota": { + Type: schema.TypeFloat, + Computed: true, + }, + "used_credits": { + Type: schema.TypeFloat, + Computed: true, + }, + "remaining_credits": { + Type: schema.TypeFloat, + Computed: true, + }, + "frequency": { + Type: schema.TypeString, + Computed: true, + }, + "start_time": { + Type: schema.TypeString, + Computed: true, + }, + "end_time": { + Type: schema.TypeString, + Computed: true, + }, + "suspend_at": { + Type: schema.TypeInt, + Computed: true, + }, + "suspend_immediate_at": { + Type: schema.TypeInt, + Computed: true, + }, + "notify_triggers": { + Type: schema.TypeInvalid, + Computed: true, + }, + "level": { + Type: schema.TypeInt, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "notify_users": { + Type: schema.TypeInvalid, + Computed: true, + }, +} + +var _ = ShowResourceMonitorSchema + +func ResourceMonitorToSchema(resourceMonitor *sdk.ResourceMonitor) map[string]any { + resourceMonitorSchema := make(map[string]any) + resourceMonitorSchema["name"] = resourceMonitor.Name + resourceMonitorSchema["credit_quota"] = resourceMonitor.CreditQuota + resourceMonitorSchema["used_credits"] = resourceMonitor.UsedCredits + resourceMonitorSchema["remaining_credits"] = resourceMonitor.RemainingCredits + resourceMonitorSchema["frequency"] = string(resourceMonitor.Frequency) + resourceMonitorSchema["start_time"] = resourceMonitor.StartTime + resourceMonitorSchema["end_time"] = resourceMonitor.EndTime + if resourceMonitor.SuspendAt != nil { + resourceMonitorSchema["suspend_at"] = resourceMonitor.SuspendAt + } + if resourceMonitor.SuspendImmediateAt != nil { + resourceMonitorSchema["suspend_immediate_at"] = resourceMonitor.SuspendImmediateAt + } + resourceMonitorSchema["notify_triggers"] = resourceMonitor.NotifyTriggers + resourceMonitorSchema["level"] = int(resourceMonitor.Level) + resourceMonitorSchema["comment"] = resourceMonitor.Comment + resourceMonitorSchema["notify_users"] = resourceMonitor.NotifyUsers + return resourceMonitorSchema +} + +var _ = ResourceMonitorToSchema diff --git a/pkg/schemas/role_gen.go b/pkg/schemas/role_gen.go new file mode 100644 index 0000000000..4c766a2950 --- /dev/null +++ b/pkg/schemas/role_gen.go @@ -0,0 +1,71 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowRoleSchema represents output of SHOW query for the single Role. +var ShowRoleSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "is_default": { + Type: schema.TypeBool, + Computed: true, + }, + "is_current": { + Type: schema.TypeBool, + Computed: true, + }, + "is_inherited": { + Type: schema.TypeBool, + Computed: true, + }, + "assigned_to_users": { + Type: schema.TypeInt, + Computed: true, + }, + "granted_to_roles": { + Type: schema.TypeInt, + Computed: true, + }, + "granted_roles": { + Type: schema.TypeInt, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowRoleSchema + +func RoleToSchema(role *sdk.Role) map[string]any { + roleSchema := make(map[string]any) + roleSchema["created_on"] = role.CreatedOn.String() + roleSchema["name"] = role.Name + roleSchema["is_default"] = role.IsDefault + roleSchema["is_current"] = role.IsCurrent + roleSchema["is_inherited"] = role.IsInherited + roleSchema["assigned_to_users"] = role.AssignedToUsers + roleSchema["granted_to_roles"] = role.GrantedToRoles + roleSchema["granted_roles"] = role.GrantedRoles + roleSchema["owner"] = role.Owner + roleSchema["comment"] = role.Comment + return roleSchema +} + +var _ = RoleToSchema diff --git a/pkg/schemas/row_access_policy_gen.go b/pkg/schemas/row_access_policy_gen.go new file mode 100644 index 0000000000..19ee8c6375 --- /dev/null +++ b/pkg/schemas/row_access_policy_gen.go @@ -0,0 +1,66 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowRowAccessPolicySchema represents output of SHOW query for the single RowAccessPolicy. +var ShowRowAccessPolicySchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "database_name": { + Type: schema.TypeString, + Computed: true, + }, + "schema_name": { + Type: schema.TypeString, + Computed: true, + }, + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "options": { + Type: schema.TypeString, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowRowAccessPolicySchema + +func RowAccessPolicyToSchema(rowAccessPolicy *sdk.RowAccessPolicy) map[string]any { + rowAccessPolicySchema := make(map[string]any) + rowAccessPolicySchema["created_on"] = rowAccessPolicy.CreatedOn + rowAccessPolicySchema["name"] = rowAccessPolicy.Name + rowAccessPolicySchema["database_name"] = rowAccessPolicy.DatabaseName + rowAccessPolicySchema["schema_name"] = rowAccessPolicy.SchemaName + rowAccessPolicySchema["kind"] = rowAccessPolicy.Kind + rowAccessPolicySchema["owner"] = rowAccessPolicy.Owner + rowAccessPolicySchema["comment"] = rowAccessPolicy.Comment + rowAccessPolicySchema["options"] = rowAccessPolicy.Options + rowAccessPolicySchema["owner_role_type"] = rowAccessPolicy.OwnerRoleType + return rowAccessPolicySchema +} + +var _ = RowAccessPolicyToSchema diff --git a/pkg/schemas/schema_gen.go b/pkg/schemas/schema_gen.go new file mode 100644 index 0000000000..9587726d19 --- /dev/null +++ b/pkg/schemas/schema_gen.go @@ -0,0 +1,75 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowSchemaSchema represents output of SHOW query for the single Schema. +var ShowSchemaSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "is_default": { + Type: schema.TypeBool, + Computed: true, + }, + "is_current": { + Type: schema.TypeBool, + Computed: true, + }, + "database_name": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "options": { + Type: schema.TypeString, + Computed: true, + }, + "retention_time": { + Type: schema.TypeString, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowSchemaSchema + +func SchemaToSchema(schema *sdk.Schema) map[string]any { + schemaSchema := make(map[string]any) + schemaSchema["created_on"] = schema.CreatedOn.String() + schemaSchema["name"] = schema.Name + schemaSchema["is_default"] = schema.IsDefault + schemaSchema["is_current"] = schema.IsCurrent + schemaSchema["database_name"] = schema.DatabaseName + schemaSchema["owner"] = schema.Owner + if schema.Comment != nil { + schemaSchema["comment"] = schema.Comment + } + if schema.Options != nil { + schemaSchema["options"] = schema.Options + } + schemaSchema["retention_time"] = schema.RetentionTime + schemaSchema["owner_role_type"] = schema.OwnerRoleType + return schemaSchema +} + +var _ = SchemaToSchema diff --git a/pkg/schemas/security_integration_gen.go b/pkg/schemas/security_integration_gen.go new file mode 100644 index 0000000000..81f27db2e7 --- /dev/null +++ b/pkg/schemas/security_integration_gen.go @@ -0,0 +1,51 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowSecurityIntegrationSchema represents output of SHOW query for the single SecurityIntegration. +var ShowSecurityIntegrationSchema = map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "integration_type": { + Type: schema.TypeString, + Computed: true, + }, + "category": { + Type: schema.TypeString, + Computed: true, + }, + "enabled": { + Type: schema.TypeBool, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "created_on": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowSecurityIntegrationSchema + +func SecurityIntegrationToSchema(securityIntegration *sdk.SecurityIntegration) map[string]any { + securityIntegrationSchema := make(map[string]any) + securityIntegrationSchema["name"] = securityIntegration.Name + securityIntegrationSchema["integration_type"] = securityIntegration.IntegrationType + securityIntegrationSchema["category"] = securityIntegration.Category + securityIntegrationSchema["enabled"] = securityIntegration.Enabled + securityIntegrationSchema["comment"] = securityIntegration.Comment + securityIntegrationSchema["created_on"] = securityIntegration.CreatedOn.String() + return securityIntegrationSchema +} + +var _ = SecurityIntegrationToSchema diff --git a/pkg/schemas/sequence_gen.go b/pkg/schemas/sequence_gen.go new file mode 100644 index 0000000000..99e6a9f3f8 --- /dev/null +++ b/pkg/schemas/sequence_gen.go @@ -0,0 +1,71 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowSequenceSchema represents output of SHOW query for the single Sequence. +var ShowSequenceSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "schema_name": { + Type: schema.TypeString, + Computed: true, + }, + "database_name": { + Type: schema.TypeString, + Computed: true, + }, + "next_value": { + Type: schema.TypeInt, + Computed: true, + }, + "interval": { + Type: schema.TypeInt, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "ordered": { + Type: schema.TypeBool, + Computed: true, + }, +} + +var _ = ShowSequenceSchema + +func SequenceToSchema(sequence *sdk.Sequence) map[string]any { + sequenceSchema := make(map[string]any) + sequenceSchema["created_on"] = sequence.CreatedOn + sequenceSchema["name"] = sequence.Name + sequenceSchema["schema_name"] = sequence.SchemaName + sequenceSchema["database_name"] = sequence.DatabaseName + sequenceSchema["next_value"] = sequence.NextValue + sequenceSchema["interval"] = sequence.Interval + sequenceSchema["owner"] = sequence.Owner + sequenceSchema["owner_role_type"] = sequence.OwnerRoleType + sequenceSchema["comment"] = sequence.Comment + sequenceSchema["ordered"] = sequence.Ordered + return sequenceSchema +} + +var _ = SequenceToSchema diff --git a/pkg/schemas/session_policy_gen.go b/pkg/schemas/session_policy_gen.go new file mode 100644 index 0000000000..93b2f57752 --- /dev/null +++ b/pkg/schemas/session_policy_gen.go @@ -0,0 +1,66 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowSessionPolicySchema represents output of SHOW query for the single SessionPolicy. +var ShowSessionPolicySchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "database_name": { + Type: schema.TypeString, + Computed: true, + }, + "schema_name": { + Type: schema.TypeString, + Computed: true, + }, + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "options": { + Type: schema.TypeString, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowSessionPolicySchema + +func SessionPolicyToSchema(sessionPolicy *sdk.SessionPolicy) map[string]any { + sessionPolicySchema := make(map[string]any) + sessionPolicySchema["created_on"] = sessionPolicy.CreatedOn + sessionPolicySchema["name"] = sessionPolicy.Name + sessionPolicySchema["database_name"] = sessionPolicy.DatabaseName + sessionPolicySchema["schema_name"] = sessionPolicy.SchemaName + sessionPolicySchema["kind"] = sessionPolicy.Kind + sessionPolicySchema["owner"] = sessionPolicy.Owner + sessionPolicySchema["comment"] = sessionPolicy.Comment + sessionPolicySchema["options"] = sessionPolicy.Options + sessionPolicySchema["owner_role_type"] = sessionPolicy.OwnerRoleType + return sessionPolicySchema +} + +var _ = SessionPolicyToSchema diff --git a/pkg/schemas/share_gen.go b/pkg/schemas/share_gen.go new file mode 100644 index 0000000000..958392ea8e --- /dev/null +++ b/pkg/schemas/share_gen.go @@ -0,0 +1,56 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowShareSchema represents output of SHOW query for the single Share. +var ShowShareSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "database_name": { + Type: schema.TypeString, + Computed: true, + }, + "to": { + Type: schema.TypeInvalid, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowShareSchema + +func ShareToSchema(share *sdk.Share) map[string]any { + shareSchema := make(map[string]any) + shareSchema["created_on"] = share.CreatedOn.String() + shareSchema["kind"] = string(share.Kind) + shareSchema["name"] = share.Name.FullyQualifiedName() + shareSchema["database_name"] = share.DatabaseName.FullyQualifiedName() + shareSchema["to"] = share.To + shareSchema["owner"] = share.Owner + shareSchema["comment"] = share.Comment + return shareSchema +} + +var _ = ShareToSchema diff --git a/pkg/schemas/stage_gen.go b/pkg/schemas/stage_gen.go new file mode 100644 index 0000000000..ba06a80a5e --- /dev/null +++ b/pkg/schemas/stage_gen.go @@ -0,0 +1,111 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowStageSchema represents output of SHOW query for the single Stage. +var ShowStageSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "database_name": { + Type: schema.TypeString, + Computed: true, + }, + "schema_name": { + Type: schema.TypeString, + Computed: true, + }, + "url": { + Type: schema.TypeString, + Computed: true, + }, + "has_credentials": { + Type: schema.TypeBool, + Computed: true, + }, + "has_encryption_key": { + Type: schema.TypeBool, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "region": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "cloud": { + Type: schema.TypeString, + Computed: true, + }, + "storage_integration": { + Type: schema.TypeString, + Computed: true, + }, + "endpoint": { + Type: schema.TypeString, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, + "directory_enabled": { + Type: schema.TypeBool, + Computed: true, + }, +} + +var _ = ShowStageSchema + +func StageToSchema(stage *sdk.Stage) map[string]any { + stageSchema := make(map[string]any) + stageSchema["created_on"] = stage.CreatedOn.String() + stageSchema["name"] = stage.Name + stageSchema["database_name"] = stage.DatabaseName + stageSchema["schema_name"] = stage.SchemaName + stageSchema["url"] = stage.Url + stageSchema["has_credentials"] = stage.HasCredentials + stageSchema["has_encryption_key"] = stage.HasEncryptionKey + stageSchema["owner"] = stage.Owner + stageSchema["comment"] = stage.Comment + if stage.Region != nil { + stageSchema["region"] = stage.Region + } + stageSchema["type"] = stage.Type + if stage.Cloud != nil { + stageSchema["cloud"] = stage.Cloud + } + if stage.StorageIntegration != nil { + stageSchema["storage_integration"] = stage.StorageIntegration + } + if stage.Endpoint != nil { + stageSchema["endpoint"] = stage.Endpoint + } + if stage.OwnerRoleType != nil { + stageSchema["owner_role_type"] = stage.OwnerRoleType + } + stageSchema["directory_enabled"] = stage.DirectoryEnabled + return stageSchema +} + +var _ = StageToSchema diff --git a/pkg/schemas/storage_integration_gen.go b/pkg/schemas/storage_integration_gen.go new file mode 100644 index 0000000000..81e32ec308 --- /dev/null +++ b/pkg/schemas/storage_integration_gen.go @@ -0,0 +1,51 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowStorageIntegrationSchema represents output of SHOW query for the single StorageIntegration. +var ShowStorageIntegrationSchema = map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "storage_type": { + Type: schema.TypeString, + Computed: true, + }, + "category": { + Type: schema.TypeString, + Computed: true, + }, + "enabled": { + Type: schema.TypeBool, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "created_on": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowStorageIntegrationSchema + +func StorageIntegrationToSchema(storageIntegration *sdk.StorageIntegration) map[string]any { + storageIntegrationSchema := make(map[string]any) + storageIntegrationSchema["name"] = storageIntegration.Name + storageIntegrationSchema["storage_type"] = storageIntegration.StorageType + storageIntegrationSchema["category"] = storageIntegration.Category + storageIntegrationSchema["enabled"] = storageIntegration.Enabled + storageIntegrationSchema["comment"] = storageIntegration.Comment + storageIntegrationSchema["created_on"] = storageIntegration.CreatedOn.String() + return storageIntegrationSchema +} + +var _ = StorageIntegrationToSchema diff --git a/pkg/schemas/stream_gen.go b/pkg/schemas/stream_gen.go new file mode 100644 index 0000000000..21ad574b81 --- /dev/null +++ b/pkg/schemas/stream_gen.go @@ -0,0 +1,125 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowStreamSchema represents output of SHOW query for the single Stream. +var ShowStreamSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "database_name": { + Type: schema.TypeString, + Computed: true, + }, + "schema_name": { + Type: schema.TypeString, + Computed: true, + }, + "table_on": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "table_name": { + Type: schema.TypeString, + Computed: true, + }, + "source_type": { + Type: schema.TypeString, + Computed: true, + }, + "base_tables": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "stale": { + Type: schema.TypeString, + Computed: true, + }, + "mode": { + Type: schema.TypeString, + Computed: true, + }, + "stale_after": { + Type: schema.TypeString, + Computed: true, + }, + "invalid_reason": { + Type: schema.TypeString, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowStreamSchema + +func StreamToSchema(stream *sdk.Stream) map[string]any { + streamSchema := make(map[string]any) + streamSchema["created_on"] = stream.CreatedOn.String() + streamSchema["name"] = stream.Name + streamSchema["database_name"] = stream.DatabaseName + streamSchema["schema_name"] = stream.SchemaName + if stream.TableOn != nil { + streamSchema["table_on"] = stream.TableOn + } + if stream.Owner != nil { + streamSchema["owner"] = stream.Owner + } + if stream.Comment != nil { + streamSchema["comment"] = stream.Comment + } + if stream.TableName != nil { + streamSchema["table_name"] = stream.TableName + } + if stream.SourceType != nil { + streamSchema["source_type"] = stream.SourceType + } + if stream.BaseTables != nil { + streamSchema["base_tables"] = stream.BaseTables + } + if stream.Type != nil { + streamSchema["type"] = stream.Type + } + if stream.Stale != nil { + streamSchema["stale"] = stream.Stale + } + if stream.Mode != nil { + streamSchema["mode"] = stream.Mode + } + if stream.StaleAfter != nil { + streamSchema["stale_after"] = stream.StaleAfter.String() + } + if stream.InvalidReason != nil { + streamSchema["invalid_reason"] = stream.InvalidReason + } + if stream.OwnerRoleType != nil { + streamSchema["owner_role_type"] = stream.OwnerRoleType + } + return streamSchema +} + +var _ = StreamToSchema diff --git a/pkg/schemas/streamlit_gen.go b/pkg/schemas/streamlit_gen.go new file mode 100644 index 0000000000..c4da84ca7b --- /dev/null +++ b/pkg/schemas/streamlit_gen.go @@ -0,0 +1,71 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowStreamlitSchema represents output of SHOW query for the single Streamlit. +var ShowStreamlitSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "database_name": { + Type: schema.TypeString, + Computed: true, + }, + "schema_name": { + Type: schema.TypeString, + Computed: true, + }, + "title": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "query_warehouse": { + Type: schema.TypeString, + Computed: true, + }, + "url_id": { + Type: schema.TypeString, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowStreamlitSchema + +func StreamlitToSchema(streamlit *sdk.Streamlit) map[string]any { + streamlitSchema := make(map[string]any) + streamlitSchema["created_on"] = streamlit.CreatedOn + streamlitSchema["name"] = streamlit.Name + streamlitSchema["database_name"] = streamlit.DatabaseName + streamlitSchema["schema_name"] = streamlit.SchemaName + streamlitSchema["title"] = streamlit.Title + streamlitSchema["owner"] = streamlit.Owner + streamlitSchema["comment"] = streamlit.Comment + streamlitSchema["query_warehouse"] = streamlit.QueryWarehouse + streamlitSchema["url_id"] = streamlit.UrlId + streamlitSchema["owner_role_type"] = streamlit.OwnerRoleType + return streamlitSchema +} + +var _ = StreamlitToSchema diff --git a/pkg/schemas/table_gen.go b/pkg/schemas/table_gen.go new file mode 100644 index 0000000000..a9b845b897 --- /dev/null +++ b/pkg/schemas/table_gen.go @@ -0,0 +1,139 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowTableSchema represents output of SHOW query for the single Table. +var ShowTableSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "database_name": { + Type: schema.TypeString, + Computed: true, + }, + "schema_name": { + Type: schema.TypeString, + Computed: true, + }, + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "cluster_by": { + Type: schema.TypeString, + Computed: true, + }, + "rows": { + Type: schema.TypeInt, + Computed: true, + }, + "bytes": { + Type: schema.TypeInt, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "retention_time": { + Type: schema.TypeInt, + Computed: true, + }, + "dropped_on": { + Type: schema.TypeString, + Computed: true, + }, + "automatic_clustering": { + Type: schema.TypeBool, + Computed: true, + }, + "change_tracking": { + Type: schema.TypeBool, + Computed: true, + }, + "search_optimization": { + Type: schema.TypeBool, + Computed: true, + }, + "search_optimization_progress": { + Type: schema.TypeString, + Computed: true, + }, + "search_optimization_bytes": { + Type: schema.TypeInt, + Computed: true, + }, + "is_external": { + Type: schema.TypeBool, + Computed: true, + }, + "enable_schema_evolution": { + Type: schema.TypeBool, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, + "is_event": { + Type: schema.TypeBool, + Computed: true, + }, + "budget": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowTableSchema + +func TableToSchema(table *sdk.Table) map[string]any { + tableSchema := make(map[string]any) + tableSchema["created_on"] = table.CreatedOn + tableSchema["name"] = table.Name + tableSchema["database_name"] = table.DatabaseName + tableSchema["schema_name"] = table.SchemaName + tableSchema["kind"] = table.Kind + tableSchema["comment"] = table.Comment + tableSchema["cluster_by"] = table.ClusterBy + tableSchema["rows"] = table.Rows + if table.Bytes != nil { + tableSchema["bytes"] = table.Bytes + } + tableSchema["owner"] = table.Owner + tableSchema["retention_time"] = table.RetentionTime + if table.DroppedOn != nil { + tableSchema["dropped_on"] = table.DroppedOn + } + tableSchema["automatic_clustering"] = table.AutomaticClustering + tableSchema["change_tracking"] = table.ChangeTracking + tableSchema["search_optimization"] = table.SearchOptimization + tableSchema["search_optimization_progress"] = table.SearchOptimizationProgress + if table.SearchOptimizationBytes != nil { + tableSchema["search_optimization_bytes"] = table.SearchOptimizationBytes + } + tableSchema["is_external"] = table.IsExternal + tableSchema["enable_schema_evolution"] = table.EnableSchemaEvolution + tableSchema["owner_role_type"] = table.OwnerRoleType + tableSchema["is_event"] = table.IsEvent + if table.Budget != nil { + tableSchema["budget"] = table.Budget + } + return tableSchema +} + +var _ = TableToSchema diff --git a/pkg/schemas/tag_gen.go b/pkg/schemas/tag_gen.go new file mode 100644 index 0000000000..dc9cc242fe --- /dev/null +++ b/pkg/schemas/tag_gen.go @@ -0,0 +1,61 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowTagSchema represents output of SHOW query for the single Tag. +var ShowTagSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "database_name": { + Type: schema.TypeString, + Computed: true, + }, + "schema_name": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "allowed_values": { + Type: schema.TypeInvalid, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowTagSchema + +func TagToSchema(tag *sdk.Tag) map[string]any { + tagSchema := make(map[string]any) + tagSchema["created_on"] = tag.CreatedOn.String() + tagSchema["name"] = tag.Name + tagSchema["database_name"] = tag.DatabaseName + tagSchema["schema_name"] = tag.SchemaName + tagSchema["owner"] = tag.Owner + tagSchema["comment"] = tag.Comment + tagSchema["allowed_values"] = tag.AllowedValues + tagSchema["owner_role_type"] = tag.OwnerRoleType + return tagSchema +} + +var _ = TagToSchema diff --git a/pkg/schemas/task_gen.go b/pkg/schemas/task_gen.go new file mode 100644 index 0000000000..a9daac5198 --- /dev/null +++ b/pkg/schemas/task_gen.go @@ -0,0 +1,121 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowTaskSchema represents output of SHOW query for the single Task. +var ShowTaskSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "id": { + Type: schema.TypeString, + Computed: true, + }, + "database_name": { + Type: schema.TypeString, + Computed: true, + }, + "schema_name": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "warehouse": { + Type: schema.TypeString, + Computed: true, + }, + "schedule": { + Type: schema.TypeString, + Computed: true, + }, + "predecessors": { + Type: schema.TypeInvalid, + Computed: true, + }, + "state": { + Type: schema.TypeString, + Computed: true, + }, + "definition": { + Type: schema.TypeString, + Computed: true, + }, + "condition": { + Type: schema.TypeString, + Computed: true, + }, + "allow_overlapping_execution": { + Type: schema.TypeBool, + Computed: true, + }, + "error_integration": { + Type: schema.TypeString, + Computed: true, + }, + "last_committed_on": { + Type: schema.TypeString, + Computed: true, + }, + "last_suspended_on": { + Type: schema.TypeString, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, + "config": { + Type: schema.TypeString, + Computed: true, + }, + "budget": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowTaskSchema + +func TaskToSchema(task *sdk.Task) map[string]any { + taskSchema := make(map[string]any) + taskSchema["created_on"] = task.CreatedOn + taskSchema["name"] = task.Name + taskSchema["id"] = task.Id + taskSchema["database_name"] = task.DatabaseName + taskSchema["schema_name"] = task.SchemaName + taskSchema["owner"] = task.Owner + taskSchema["comment"] = task.Comment + taskSchema["warehouse"] = task.Warehouse + taskSchema["schedule"] = task.Schedule + taskSchema["predecessors"] = task.Predecessors + taskSchema["state"] = string(task.State) + taskSchema["definition"] = task.Definition + taskSchema["condition"] = task.Condition + taskSchema["allow_overlapping_execution"] = task.AllowOverlappingExecution + taskSchema["error_integration"] = task.ErrorIntegration + taskSchema["last_committed_on"] = task.LastCommittedOn + taskSchema["last_suspended_on"] = task.LastSuspendedOn + taskSchema["owner_role_type"] = task.OwnerRoleType + taskSchema["config"] = task.Config + taskSchema["budget"] = task.Budget + return taskSchema +} + +var _ = TaskToSchema diff --git a/pkg/schemas/user_gen.go b/pkg/schemas/user_gen.go new file mode 100644 index 0000000000..75b1c9128e --- /dev/null +++ b/pkg/schemas/user_gen.go @@ -0,0 +1,151 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowUserSchema represents output of SHOW query for the single User. +var ShowUserSchema = map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "login_name": { + Type: schema.TypeString, + Computed: true, + }, + "display_name": { + Type: schema.TypeString, + Computed: true, + }, + "first_name": { + Type: schema.TypeString, + Computed: true, + }, + "last_name": { + Type: schema.TypeString, + Computed: true, + }, + "email": { + Type: schema.TypeString, + Computed: true, + }, + "mins_to_unlock": { + Type: schema.TypeString, + Computed: true, + }, + "days_to_expiry": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "disabled": { + Type: schema.TypeBool, + Computed: true, + }, + "must_change_password": { + Type: schema.TypeBool, + Computed: true, + }, + "snowflake_lock": { + Type: schema.TypeBool, + Computed: true, + }, + "default_warehouse": { + Type: schema.TypeString, + Computed: true, + }, + "default_namespace": { + Type: schema.TypeString, + Computed: true, + }, + "default_role": { + Type: schema.TypeString, + Computed: true, + }, + "default_secondary_roles": { + Type: schema.TypeString, + Computed: true, + }, + "ext_authn_duo": { + Type: schema.TypeBool, + Computed: true, + }, + "ext_authn_uid": { + Type: schema.TypeString, + Computed: true, + }, + "mins_to_bypass_mfa": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "last_success_login": { + Type: schema.TypeString, + Computed: true, + }, + "expires_at_time": { + Type: schema.TypeString, + Computed: true, + }, + "locked_until_time": { + Type: schema.TypeString, + Computed: true, + }, + "has_password": { + Type: schema.TypeBool, + Computed: true, + }, + "has_rsa_public_key": { + Type: schema.TypeBool, + Computed: true, + }, +} + +var _ = ShowUserSchema + +func UserToSchema(user *sdk.User) map[string]any { + userSchema := make(map[string]any) + userSchema["name"] = user.Name + userSchema["created_on"] = user.CreatedOn.String() + userSchema["login_name"] = user.LoginName + userSchema["display_name"] = user.DisplayName + userSchema["first_name"] = user.FirstName + userSchema["last_name"] = user.LastName + userSchema["email"] = user.Email + userSchema["mins_to_unlock"] = user.MinsToUnlock + userSchema["days_to_expiry"] = user.DaysToExpiry + userSchema["comment"] = user.Comment + userSchema["disabled"] = user.Disabled + userSchema["must_change_password"] = user.MustChangePassword + userSchema["snowflake_lock"] = user.SnowflakeLock + userSchema["default_warehouse"] = user.DefaultWarehouse + userSchema["default_namespace"] = user.DefaultNamespace + userSchema["default_role"] = user.DefaultRole + userSchema["default_secondary_roles"] = user.DefaultSecondaryRoles + userSchema["ext_authn_duo"] = user.ExtAuthnDuo + userSchema["ext_authn_uid"] = user.ExtAuthnUid + userSchema["mins_to_bypass_mfa"] = user.MinsToBypassMfa + userSchema["owner"] = user.Owner + userSchema["last_success_login"] = user.LastSuccessLogin.String() + userSchema["expires_at_time"] = user.ExpiresAtTime.String() + userSchema["locked_until_time"] = user.LockedUntilTime.String() + userSchema["has_password"] = user.HasPassword + userSchema["has_rsa_public_key"] = user.HasRsaPublicKey + return userSchema +} + +var _ = UserToSchema diff --git a/pkg/schemas/view_gen.go b/pkg/schemas/view_gen.go new file mode 100644 index 0000000000..243afff641 --- /dev/null +++ b/pkg/schemas/view_gen.go @@ -0,0 +1,86 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowViewSchema represents output of SHOW query for the single View. +var ShowViewSchema = map[string]*schema.Schema{ + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "kind": { + Type: schema.TypeString, + Computed: true, + }, + "reserved": { + Type: schema.TypeString, + Computed: true, + }, + "database_name": { + Type: schema.TypeString, + Computed: true, + }, + "schema_name": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "text": { + Type: schema.TypeString, + Computed: true, + }, + "is_secure": { + Type: schema.TypeBool, + Computed: true, + }, + "is_materialized": { + Type: schema.TypeBool, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, + "change_tracking": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowViewSchema + +func ViewToSchema(view *sdk.View) map[string]any { + viewSchema := make(map[string]any) + viewSchema["created_on"] = view.CreatedOn + viewSchema["name"] = view.Name + viewSchema["kind"] = view.Kind + viewSchema["reserved"] = view.Reserved + viewSchema["database_name"] = view.DatabaseName + viewSchema["schema_name"] = view.SchemaName + viewSchema["owner"] = view.Owner + viewSchema["comment"] = view.Comment + viewSchema["text"] = view.Text + viewSchema["is_secure"] = view.IsSecure + viewSchema["is_materialized"] = view.IsMaterialized + viewSchema["owner_role_type"] = view.OwnerRoleType + viewSchema["change_tracking"] = view.ChangeTracking + return viewSchema +} + +var _ = ViewToSchema diff --git a/pkg/schemas/warehouse_gen.go b/pkg/schemas/warehouse_gen.go new file mode 100644 index 0000000000..21ee709de6 --- /dev/null +++ b/pkg/schemas/warehouse_gen.go @@ -0,0 +1,156 @@ +// Code generated by sdk-to-schema generator; DO NOT EDIT. + +package schemas + +import ( + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// ShowWarehouseSchema represents output of SHOW query for the single Warehouse. +var ShowWarehouseSchema = map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "state": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "size": { + Type: schema.TypeString, + Computed: true, + }, + "min_cluster_count": { + Type: schema.TypeInt, + Computed: true, + }, + "max_cluster_count": { + Type: schema.TypeInt, + Computed: true, + }, + "started_clusters": { + Type: schema.TypeInt, + Computed: true, + }, + "running": { + Type: schema.TypeInt, + Computed: true, + }, + "queued": { + Type: schema.TypeInt, + Computed: true, + }, + "is_default": { + Type: schema.TypeBool, + Computed: true, + }, + "is_current": { + Type: schema.TypeBool, + Computed: true, + }, + "auto_suspend": { + Type: schema.TypeInt, + Computed: true, + }, + "auto_resume": { + Type: schema.TypeBool, + Computed: true, + }, + "available": { + Type: schema.TypeFloat, + Computed: true, + }, + "provisioning": { + Type: schema.TypeFloat, + Computed: true, + }, + "quiescing": { + Type: schema.TypeFloat, + Computed: true, + }, + "other": { + Type: schema.TypeFloat, + Computed: true, + }, + "created_on": { + Type: schema.TypeString, + Computed: true, + }, + "resumed_on": { + Type: schema.TypeString, + Computed: true, + }, + "updated_on": { + Type: schema.TypeString, + Computed: true, + }, + "owner": { + Type: schema.TypeString, + Computed: true, + }, + "comment": { + Type: schema.TypeString, + Computed: true, + }, + "enable_query_acceleration": { + Type: schema.TypeBool, + Computed: true, + }, + "query_acceleration_max_scale_factor": { + Type: schema.TypeInt, + Computed: true, + }, + "resource_monitor": { + Type: schema.TypeString, + Computed: true, + }, + "scaling_policy": { + Type: schema.TypeString, + Computed: true, + }, + "owner_role_type": { + Type: schema.TypeString, + Computed: true, + }, +} + +var _ = ShowWarehouseSchema + +func WarehouseToSchema(warehouse *sdk.Warehouse) map[string]any { + warehouseSchema := make(map[string]any) + warehouseSchema["name"] = warehouse.Name + warehouseSchema["state"] = string(warehouse.State) + warehouseSchema["type"] = string(warehouse.Type) + warehouseSchema["size"] = string(warehouse.Size) + warehouseSchema["min_cluster_count"] = warehouse.MinClusterCount + warehouseSchema["max_cluster_count"] = warehouse.MaxClusterCount + warehouseSchema["started_clusters"] = warehouse.StartedClusters + warehouseSchema["running"] = warehouse.Running + warehouseSchema["queued"] = warehouse.Queued + warehouseSchema["is_default"] = warehouse.IsDefault + warehouseSchema["is_current"] = warehouse.IsCurrent + warehouseSchema["auto_suspend"] = warehouse.AutoSuspend + warehouseSchema["auto_resume"] = warehouse.AutoResume + warehouseSchema["available"] = warehouse.Available + warehouseSchema["provisioning"] = warehouse.Provisioning + warehouseSchema["quiescing"] = warehouse.Quiescing + warehouseSchema["other"] = warehouse.Other + warehouseSchema["created_on"] = warehouse.CreatedOn.String() + warehouseSchema["resumed_on"] = warehouse.ResumedOn.String() + warehouseSchema["updated_on"] = warehouse.UpdatedOn.String() + warehouseSchema["owner"] = warehouse.Owner + warehouseSchema["comment"] = warehouse.Comment + warehouseSchema["enable_query_acceleration"] = warehouse.EnableQueryAcceleration + warehouseSchema["query_acceleration_max_scale_factor"] = warehouse.QueryAccelerationMaxScaleFactor + warehouseSchema["resource_monitor"] = warehouse.ResourceMonitor + warehouseSchema["scaling_policy"] = string(warehouse.ScalingPolicy) + warehouseSchema["owner_role_type"] = warehouse.OwnerRoleType + return warehouseSchema +} + +var _ = WarehouseToSchema From b250f0fda211ef0f52901eb0b02d8557532985af Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 24 Jun 2024 13:58:15 +0200 Subject: [PATCH 23/28] Improve README --- pkg/schemas/gen/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/schemas/gen/README.md b/pkg/schemas/gen/README.md index c8f57d644b..7799cdb632 100644 --- a/pkg/schemas/gen/README.md +++ b/pkg/schemas/gen/README.md @@ -39,6 +39,14 @@ The following types are supported currently in the generator (schema and mapping - `sdk.TableColumnIdentifier` - `sdk.ObjectIdentifier` interface +##### To schema mappings + +Given SDK struct field can be mapped to the generated schema depending on its type: +- no mapping (`Identity`) - used for `string` and other basic types +- string value mapping (`ToString`) - used e.g. for `time.Time` +- fully qualified name mapping (`FullyQualifiedName`) - used for all identifiers and `sdk.ObjectIdentifier` interface +- casting (`CastToString` and `CastToInt`) - used for enums with underlying type `string` or `int` + ##### Changing the SDK object's show output If you change the show output struct in the SDK: @@ -60,6 +68,7 @@ If you change the show output struct in the SDK: - The following types (already existing in the SDK show output structs) are not yet supported (for all of them the schema will be generated with `schema.TypeInvalid`: + - other basic types (e.g. `int8`, etc.) - slices of basic types (`[]int`, `[]string`) - slices of identifiers (`[]sdk.AccountIdentifier`, `[]sdk.SchemaObjectIdentifier`) - slices of enums (`[]sdk.IntegrationType`, `[]sdk.PluralObjectType`) From 30183eaaf6ae08f617e8db4302cc358dacae2215 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 24 Jun 2024 13:58:38 +0200 Subject: [PATCH 24/28] Use the generated schemas and mappers instead of the manually created ones --- pkg/schemas/parameter.go | 41 -------- pkg/schemas/warehouse.go | 153 ---------------------------- pkg/schemas/warehouse_parameters.go | 6 +- 3 files changed, 3 insertions(+), 197 deletions(-) delete mode 100644 pkg/schemas/parameter.go delete mode 100644 pkg/schemas/warehouse.go diff --git a/pkg/schemas/parameter.go b/pkg/schemas/parameter.go deleted file mode 100644 index d123875228..0000000000 --- a/pkg/schemas/parameter.go +++ /dev/null @@ -1,41 +0,0 @@ -package schemas - -import ( - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) - -// ParameterSchema represents Snowflake parameter object. -// TODO [SNOW-1473425]: should be generated later based on the sdk.Parameter -var ParameterSchema = map[string]*schema.Schema{ - "key": { - Type: schema.TypeString, - Computed: true, - }, - "value": { - Type: schema.TypeString, - Computed: true, - }, - "default": { - Type: schema.TypeString, - Computed: true, - }, - "level": { - Type: schema.TypeString, - Computed: true, - }, - "description": { - Type: schema.TypeString, - Computed: true, - }, -} - -func ParameterToSchema(parameter *sdk.Parameter) map[string]any { - parameterSchema := make(map[string]any) - parameterSchema["key"] = parameter.Key - parameterSchema["value"] = parameter.Value - parameterSchema["default"] = parameter.Default - parameterSchema["level"] = parameter.Level - parameterSchema["description"] = parameter.Description - return parameterSchema -} diff --git a/pkg/schemas/warehouse.go b/pkg/schemas/warehouse.go deleted file mode 100644 index b4360aa792..0000000000 --- a/pkg/schemas/warehouse.go +++ /dev/null @@ -1,153 +0,0 @@ -package schemas - -import ( - "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) - -// ShowWarehouseSchema represents output of SHOW WAREHOUSES query for the single warehouse. -// TODO [SNOW-1473425]: should be generated later based on the sdk.Warehouse -var ShowWarehouseSchema = map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Computed: true, - }, - "state": { - Type: schema.TypeString, - Computed: true, - }, - "type": { - Type: schema.TypeString, - Computed: true, - }, - "size": { - Type: schema.TypeString, - Computed: true, - }, - "min_cluster_count": { - Type: schema.TypeInt, - Computed: true, - }, - "max_cluster_count": { - Type: schema.TypeInt, - Computed: true, - }, - "started_clusters": { - Type: schema.TypeInt, - Computed: true, - }, - "running": { - Type: schema.TypeInt, - Computed: true, - }, - "queued": { - Type: schema.TypeInt, - Computed: true, - }, - "is_default": { - Type: schema.TypeBool, - Computed: true, - }, - "is_current": { - Type: schema.TypeBool, - Computed: true, - }, - "auto_suspend": { - Type: schema.TypeInt, - Computed: true, - }, - "auto_resume": { - Type: schema.TypeBool, - Computed: true, - }, - "available": { - Type: schema.TypeFloat, - Computed: true, - }, - "provisioning": { - Type: schema.TypeFloat, - Computed: true, - }, - "quiescing": { - Type: schema.TypeFloat, - Computed: true, - }, - "other": { - Type: schema.TypeFloat, - Computed: true, - }, - "created_on": { - Type: schema.TypeString, - Computed: true, - }, - "resumed_on": { - Type: schema.TypeString, - Computed: true, - }, - "updated_on": { - Type: schema.TypeString, - Computed: true, - }, - "owner": { - Type: schema.TypeString, - Computed: true, - }, - "comment": { - Type: schema.TypeString, - Computed: true, - }, - "enable_query_acceleration": { - Type: schema.TypeBool, - Computed: true, - }, - "query_acceleration_max_scale_factor": { - Type: schema.TypeInt, - Computed: true, - }, - "resource_monitor": { - Type: schema.TypeString, - Computed: true, - }, - "scaling_policy": { - Type: schema.TypeString, - Computed: true, - }, - "owner_role_type": { - Type: schema.TypeString, - Computed: true, - }, -} - -// TODO [SNOW-1473425]: better name? -// TODO [SNOW-1473425]: interface (e.g. asMap)? in SDK? -func WarehouseToSchema(warehouse *sdk.Warehouse) map[string]any { - warehouseSchema := make(map[string]any) - warehouseSchema["name"] = warehouse.Name - warehouseSchema["state"] = warehouse.State - warehouseSchema["type"] = warehouse.Type - warehouseSchema["size"] = warehouse.Size - warehouseSchema["min_cluster_count"] = warehouse.MinClusterCount - warehouseSchema["max_cluster_count"] = warehouse.MaxClusterCount - warehouseSchema["started_clusters"] = warehouse.StartedClusters - warehouseSchema["running"] = warehouse.Running - warehouseSchema["queued"] = warehouse.Queued - warehouseSchema["is_default"] = warehouse.IsDefault - warehouseSchema["is_current"] = warehouse.IsCurrent - warehouseSchema["auto_suspend"] = warehouse.AutoSuspend - warehouseSchema["auto_resume"] = warehouse.AutoResume - warehouseSchema["available"] = warehouse.Available - warehouseSchema["provisioning"] = warehouse.Provisioning - warehouseSchema["quiescing"] = warehouse.Quiescing - warehouseSchema["other"] = warehouse.Other - warehouseSchema["created_on"] = warehouse.CreatedOn.String() - warehouseSchema["resumed_on"] = warehouse.ResumedOn.String() - warehouseSchema["updated_on"] = warehouse.UpdatedOn.String() - warehouseSchema["owner"] = warehouse.Owner - warehouseSchema["comment"] = warehouse.Comment - warehouseSchema["enable_query_acceleration"] = warehouse.EnableQueryAcceleration - warehouseSchema["query_acceleration_max_scale_factor"] = warehouse.QueryAccelerationMaxScaleFactor - warehouseSchema["resource_monitor"] = warehouse.ResourceMonitor - warehouseSchema["scaling_policy"] = warehouse.ScalingPolicy - warehouseSchema["owner_role_type"] = warehouse.OwnerRoleType - return warehouseSchema -} diff --git a/pkg/schemas/warehouse_parameters.go b/pkg/schemas/warehouse_parameters.go index 49dfe7aa96..c0df6b1666 100644 --- a/pkg/schemas/warehouse_parameters.go +++ b/pkg/schemas/warehouse_parameters.go @@ -15,21 +15,21 @@ var ShowWarehouseParametersSchema = map[string]*schema.Schema{ Type: schema.TypeList, Computed: true, Elem: &schema.Resource{ - Schema: ParameterSchema, + Schema: ShowParameterSchema, }, }, "statement_queued_timeout_in_seconds": { Type: schema.TypeList, Computed: true, Elem: &schema.Resource{ - Schema: ParameterSchema, + Schema: ShowParameterSchema, }, }, "statement_timeout_in_seconds": { Type: schema.TypeList, Computed: true, Elem: &schema.Resource{ - Schema: ParameterSchema, + Schema: ShowParameterSchema, }, }, } From cdc8053c58cdf3c30ed150996a94e2f040d88b8d Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Mon, 24 Jun 2024 14:10:04 +0200 Subject: [PATCH 25/28] Run make pre-push --- go.mod | 2 +- pkg/schemas/gen/README.md | 1 + pkg/schemas/gen/schema_field_mapper.go | 12 +++++++----- pkg/schemas/gen/schema_field_mapper_test.go | 4 +--- pkg/schemas/gen/struct_details_extractor.go | 1 - pkg/schemas/gen/struct_details_extractor_test.go | 1 - pkg/schemas/gen/util.go | 6 ++++-- pkg/schemas/gen/util_test.go | 1 - 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 05ab63b451..b5f3159a0b 100644 --- a/go.mod +++ b/go.mod @@ -27,6 +27,7 @@ require ( github.com/stretchr/testify v1.8.4 github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a golang.org/x/crypto v0.23.0 + golang.org/x/exp v0.0.0-20231006140011-7918f672742d golang.org/x/text v0.15.0 ) @@ -110,7 +111,6 @@ require ( github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect github.com/zclconf/go-cty v1.14.2 // indirect github.com/zeebo/xxh3 v1.0.2 // indirect - golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.25.0 // indirect golang.org/x/sync v0.7.0 // indirect diff --git a/pkg/schemas/gen/README.md b/pkg/schemas/gen/README.md index 7799cdb632..79b1abbf99 100644 --- a/pkg/schemas/gen/README.md +++ b/pkg/schemas/gen/README.md @@ -82,6 +82,7 @@ Functional improvements: - generate only given object(s) - now all are always generated - manage the output - currently, the output consists of all structs displayed with fields, unique types grouped, and schemas generated - (optional) parametrize the output directory - currently, it's always written to `schemas` package +- discover a change and generate as part of a `make pre-push` Implementation improvements: - add acceptance test for a `testStruct` (the one from [struct_details_extractor_test.go](./struct_details_extractor_test.go)) for the whole generation flow diff --git a/pkg/schemas/gen/schema_field_mapper.go b/pkg/schemas/gen/schema_field_mapper.go index 66369eb037..00ee4891ed 100644 --- a/pkg/schemas/gen/schema_field_mapper.go +++ b/pkg/schemas/gen/schema_field_mapper.go @@ -17,11 +17,13 @@ type SchemaField struct { Mapper Mapper } -var Identity = func(field string) string { return field } -var ToString = func(field string) string { return fmt.Sprintf("%s.String()", field) } -var FullyQualifiedName = func(field string) string { return fmt.Sprintf("%s.FullyQualifiedName()", field) } -var CastToString = func(field string) string { return fmt.Sprintf("string(%s)", field) } -var CastToInt = func(field string) string { return fmt.Sprintf("int(%s)", field) } +var ( + Identity = func(field string) string { return field } + ToString = func(field string) string { return fmt.Sprintf("%s.String()", field) } + FullyQualifiedName = func(field string) string { return fmt.Sprintf("%s.FullyQualifiedName()", field) } + CastToString = func(field string) string { return fmt.Sprintf("string(%s)", field) } + CastToInt = func(field string) string { return fmt.Sprintf("int(%s)", field) } +) // TODO [SNOW-1501905]: handle other basic type variants // TODO [SNOW-1501905]: handle any other interface (error) diff --git a/pkg/schemas/gen/schema_field_mapper_test.go b/pkg/schemas/gen/schema_field_mapper_test.go index 1dbef95948..b13053fac3 100644 --- a/pkg/schemas/gen/schema_field_mapper_test.go +++ b/pkg/schemas/gen/schema_field_mapper_test.go @@ -1,7 +1,6 @@ package gen import ( - "fmt" "reflect" "testing" @@ -10,7 +9,6 @@ import ( ) func Test_MapToSchemaField(t *testing.T) { - type expectedValues struct { name string schemaType schema.ValueType @@ -142,7 +140,7 @@ func Test_MapToSchemaField(t *testing.T) { } for _, tc := range testCases { - t.Run(fmt.Sprintf("%s", tc.field.Name), func(t *testing.T) { + t.Run(tc.field.Name, func(t *testing.T) { schemaField := MapToSchemaField(tc.field) assertSchemaFieldMapped(schemaField, tc.field, tc.expected) diff --git a/pkg/schemas/gen/struct_details_extractor.go b/pkg/schemas/gen/struct_details_extractor.go index 1a5e24c759..4e92004ff8 100644 --- a/pkg/schemas/gen/struct_details_extractor.go +++ b/pkg/schemas/gen/struct_details_extractor.go @@ -35,7 +35,6 @@ func ExtractStructDetails(s any) Struct { currentField := v.Field(i) currentName := v.Type().Field(i).Name currentType := v.Type().Field(i).Type.String() - //currentValue := currentField.Interface() var kind reflect.Kind var isPtr bool diff --git a/pkg/schemas/gen/struct_details_extractor_test.go b/pkg/schemas/gen/struct_details_extractor_test.go index d72727b8c5..098e081f47 100644 --- a/pkg/schemas/gen/struct_details_extractor_test.go +++ b/pkg/schemas/gen/struct_details_extractor_test.go @@ -16,7 +16,6 @@ import ( // // TODO [SNOW-1501905]: test type of slice fields func Test_ExtractStructDetails(t *testing.T) { - type testStruct struct { unexportedString string unexportedInt int diff --git a/pkg/schemas/gen/util.go b/pkg/schemas/gen/util.go index d610de8609..d1d08399bc 100644 --- a/pkg/schemas/gen/util.go +++ b/pkg/schemas/gen/util.go @@ -5,8 +5,10 @@ import ( "strings" ) -var splitOnTheWordsBeginnings = regexp.MustCompile(`(.)([A-Z][a-z]+)`) -var splitRemainingWordBreaks = regexp.MustCompile("([a-z0-9])([A-Z]+)") +var ( + splitOnTheWordsBeginnings = regexp.MustCompile(`(.)([A-Z][a-z]+)`) + splitRemainingWordBreaks = regexp.MustCompile("([a-z0-9])([A-Z]+)") +) // ToSnakeCase allows converting a CamelCase text to camel_case one (needed for schema attribute names). Examples: // - CamelCase -> camel_case diff --git a/pkg/schemas/gen/util_test.go b/pkg/schemas/gen/util_test.go index 3a2fba257f..dd1ea30251 100644 --- a/pkg/schemas/gen/util_test.go +++ b/pkg/schemas/gen/util_test.go @@ -9,7 +9,6 @@ import ( ) func Test_ToSnakeCase(t *testing.T) { - type test struct { input string expected string From 306100a140fec9eae913c31794848e54463fb42b Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Tue, 25 Jun 2024 11:58:40 +0200 Subject: [PATCH 26/28] Fix after review --- pkg/schemas/gen/schema_field_mapper.go | 5 +++-- pkg/schemas/gen/templates/schema.tmpl | 8 ++++---- pkg/schemas/gen/templates/to_schema_mapper.tmpl | 16 ++++++++-------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/pkg/schemas/gen/schema_field_mapper.go b/pkg/schemas/gen/schema_field_mapper.go index 00ee4891ed..fc5b7072ab 100644 --- a/pkg/schemas/gen/schema_field_mapper.go +++ b/pkg/schemas/gen/schema_field_mapper.go @@ -53,10 +53,11 @@ func MapToSchemaField(field Field) SchemaField { } underlyingTypeWithoutPtr, _ := strings.CutPrefix(field.UnderlyingType, "*") + isSdkDeclaredObject := strings.HasPrefix(concreteTypeWithoutPtr, "sdk.") switch { - case strings.HasPrefix(concreteTypeWithoutPtr, "sdk.") && underlyingTypeWithoutPtr == "string": + case isSdkDeclaredObject && underlyingTypeWithoutPtr == "string": return SchemaField{name, schema.TypeString, field.Name, isPointer, CastToString} - case strings.HasPrefix(concreteTypeWithoutPtr, "sdk.") && underlyingTypeWithoutPtr == "int": + case isSdkDeclaredObject && underlyingTypeWithoutPtr == "int": return SchemaField{name, schema.TypeInt, field.Name, isPointer, CastToInt} } return SchemaField{name, schema.TypeInvalid, field.Name, isPointer, Identity} diff --git a/pkg/schemas/gen/templates/schema.tmpl b/pkg/schemas/gen/templates/schema.tmpl index 1ac71205b9..3b805fbd6a 100644 --- a/pkg/schemas/gen/templates/schema.tmpl +++ b/pkg/schemas/gen/templates/schema.tmpl @@ -3,10 +3,10 @@ // Show{{ .Name }}Schema represents output of SHOW query for the single {{ .Name }}. var Show{{ .Name }}Schema = map[string]*schema.Schema{ {{- range .SchemaFields }} - "{{ .Name }}": { - Type: schema.{{ .SchemaType }}, - Computed: true, - }, + "{{ .Name }}": { + Type: schema.{{ .SchemaType }}, + Computed: true, + }, {{- end }} } diff --git a/pkg/schemas/gen/templates/to_schema_mapper.tmpl b/pkg/schemas/gen/templates/to_schema_mapper.tmpl index a9d91b11c0..65d7883c43 100644 --- a/pkg/schemas/gen/templates/to_schema_mapper.tmpl +++ b/pkg/schemas/gen/templates/to_schema_mapper.tmpl @@ -5,15 +5,15 @@ func {{ .Name }}ToSchema({{ $nameLowerCase }} *{{ .SdkType }}) map[string]any { {{ $schemaName }} := make(map[string]any) {{- range .SchemaFields }} - {{ if .IsOriginalTypePointer -}} - if {{ $nameLowerCase }}.{{ .OriginalName }} != nil { - {{ $schemaName }}["{{ .Name }}"] = {{ runMapper .Mapper $nameLowerCase "." .OriginalName }} - } - {{- else -}} - {{ $schemaName }}["{{ .Name }}"] = {{ runMapper .Mapper $nameLowerCase "." .OriginalName }} - {{- end -}} + {{ if .IsOriginalTypePointer -}} + if {{ $nameLowerCase }}.{{ .OriginalName }} != nil { + {{ $schemaName }}["{{ .Name }}"] = {{ runMapper .Mapper $nameLowerCase "." .OriginalName }} + } + {{- else -}} + {{ $schemaName }}["{{ .Name }}"] = {{ runMapper .Mapper $nameLowerCase "." .OriginalName }} + {{- end -}} {{- end }} - return {{ $nameLowerCase }}Schema + return {{ $schemaName }} } var _ = {{ .Name }}ToSchema From 9f96f50c6186c7dd99efaa47dd532edb4f1d5abc Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Tue, 25 Jun 2024 20:22:08 +0200 Subject: [PATCH 27/28] Fix after merge --- docs/data-sources/databases.md | 3 +- pkg/datasources/databases.go | 3 +- pkg/schemas/database.go | 73 ----------------------------- pkg/schemas/database_parameters.go | 2 +- pkg/schemas/parameters.go | 12 +++++ pkg/schemas/warehouse_parameters.go | 27 ++--------- 6 files changed, 20 insertions(+), 100 deletions(-) create mode 100644 pkg/schemas/parameters.go diff --git a/docs/data-sources/databases.md b/docs/data-sources/databases.md index b7deae35bf..48a5bc1fff 100644 --- a/docs/data-sources/databases.md +++ b/docs/data-sources/databases.md @@ -356,9 +356,9 @@ Read-Only: - `comment` (String) - `created_on` (String) +- `dropped_on` (String) - `is_current` (Boolean) - `is_default` (Boolean) -- `is_transient` (Boolean) - `kind` (String) - `name` (String) - `options` (String) @@ -367,3 +367,4 @@ Read-Only: - `owner_role_type` (String) - `resource_group` (String) - `retention_time` (Number) +- `transient` (Boolean) diff --git a/pkg/datasources/databases.go b/pkg/datasources/databases.go index 4315f401f4..8142955008 100644 --- a/pkg/datasources/databases.go +++ b/pkg/datasources/databases.go @@ -135,6 +135,7 @@ func ReadDatabases(ctx context.Context, d *schema.ResourceData, meta any) diag.D flattenedDatabases := make([]map[string]any, len(databases)) for i, database := range databases { + database := database var databaseDescription []map[string]any if d.Get("with_describe").(bool) { describeResult, err := client.Databases.Describe(ctx, database.ID()) @@ -158,7 +159,7 @@ func ReadDatabases(ctx context.Context, d *schema.ResourceData, meta any) diag.D } flattenedDatabases[i] = map[string]any{ - "show_output": []map[string]any{schemas.DatabaseShowToSchema(database)}, + "show_output": []map[string]any{schemas.DatabaseToSchema(&database)}, "describe_output": databaseDescription, "parameters": databaseParameters, } diff --git a/pkg/schemas/database.go b/pkg/schemas/database.go index e1aa3dc6bd..91cd57c3b1 100644 --- a/pkg/schemas/database.go +++ b/pkg/schemas/database.go @@ -5,79 +5,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -var ShowDatabaseSchema = map[string]*schema.Schema{ - "created_on": { - Type: schema.TypeString, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - "kind": { - Type: schema.TypeString, - Computed: true, - }, - "is_transient": { - Type: schema.TypeBool, - Computed: true, - }, - "is_default": { - Type: schema.TypeBool, - Computed: true, - }, - "is_current": { - Type: schema.TypeBool, - Computed: true, - }, - "origin": { - Type: schema.TypeString, - Computed: true, - }, - "owner": { - Type: schema.TypeString, - Computed: true, - }, - "comment": { - Type: schema.TypeString, - Computed: true, - }, - "options": { - Type: schema.TypeString, - Computed: true, - }, - "retention_time": { - Type: schema.TypeInt, - Computed: true, - }, - "resource_group": { - Type: schema.TypeString, - Computed: true, - }, - "owner_role_type": { - Type: schema.TypeString, - Computed: true, - }, -} - -func DatabaseShowToSchema(database sdk.Database) map[string]any { - return map[string]any{ - "created_on": database.CreatedOn.String(), - "name": database.Name, - "kind": database.Kind, - "is_transient": database.Transient, - "is_default": database.IsDefault, - "is_current": database.IsCurrent, - "origin": database.Origin, - "owner": database.Owner, - "comment": database.Comment, - "options": database.Options, - "retention_time": database.RetentionTime, - "resource_group": database.ResourceGroup, - "owner_role_type": database.OwnerRoleType, - } -} - var DatabaseDescribeSchema = map[string]*schema.Schema{ "created_on": { Type: schema.TypeString, diff --git a/pkg/schemas/database_parameters.go b/pkg/schemas/database_parameters.go index 11e7650048..94b52912fe 100644 --- a/pkg/schemas/database_parameters.go +++ b/pkg/schemas/database_parameters.go @@ -32,7 +32,7 @@ var ( func init() { for _, param := range databaseParameters { - ShowDatabaseParametersSchema[strings.ToLower(string(param))] = ParameterSchema + ShowDatabaseParametersSchema[strings.ToLower(string(param))] = ParameterListSchema } } diff --git a/pkg/schemas/parameters.go b/pkg/schemas/parameters.go new file mode 100644 index 0000000000..b81d3b0786 --- /dev/null +++ b/pkg/schemas/parameters.go @@ -0,0 +1,12 @@ +package schemas + +import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + +// ParameterListSchema represents Snowflake parameter object. +var ParameterListSchema = &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: ShowParameterSchema, + }, +} diff --git a/pkg/schemas/warehouse_parameters.go b/pkg/schemas/warehouse_parameters.go index 18422591e1..2c250678ec 100644 --- a/pkg/schemas/warehouse_parameters.go +++ b/pkg/schemas/warehouse_parameters.go @@ -11,30 +11,9 @@ import ( // TODO [SNOW-1473425]: descriptions (take from .Description; tool to validate changes later) // TODO [SNOW-1473425]: should be generated later based on sdk.WarehouseParameters var ShowWarehouseParametersSchema = map[string]*schema.Schema{ - "max_concurrency_level": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: ShowParameterSchema, - }, - }, - "statement_queued_timeout_in_seconds": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: ShowParameterSchema, - }, - }, - "statement_timeout_in_seconds": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: ShowParameterSchema, - }, - }, - //"max_concurrency_level": ParameterSchema, - //"statement_queued_timeout_in_seconds": ParameterSchema, - //"statement_timeout_in_seconds": ParameterSchema, + "max_concurrency_level": ParameterListSchema, + "statement_queued_timeout_in_seconds": ParameterListSchema, + "statement_timeout_in_seconds": ParameterListSchema, } // TODO [SNOW-1473425]: validate all present? From b2cdf9449a500a8695c1e83bca07f0a1359b1ca7 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Wed, 26 Jun 2024 15:21:30 +0200 Subject: [PATCH 28/28] Fix the test --- pkg/datasources/databases_acceptance_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/datasources/databases_acceptance_test.go b/pkg/datasources/databases_acceptance_test.go index e938706c99..2a8e6356ab 100644 --- a/pkg/datasources/databases_acceptance_test.go +++ b/pkg/datasources/databases_acceptance_test.go @@ -40,7 +40,7 @@ func TestAcc_Databases_Complete(t *testing.T) { resource.TestCheckResourceAttrSet("data.snowflake_databases.test", "databases.0.show_output.0.created_on"), resource.TestCheckResourceAttr("data.snowflake_databases.test", "databases.0.show_output.0.name", databaseName), resource.TestCheckResourceAttr("data.snowflake_databases.test", "databases.0.show_output.0.kind", "STANDARD"), - resource.TestCheckResourceAttr("data.snowflake_databases.test", "databases.0.show_output.0.is_transient", "false"), + resource.TestCheckResourceAttr("data.snowflake_databases.test", "databases.0.show_output.0.transient", "false"), resource.TestCheckResourceAttr("data.snowflake_databases.test", "databases.0.show_output.0.is_default", "false"), // Commenting as this value depends on the currently used database, which is different when running as a single test and multiple tests (e.g., on CI) // resource.TestCheckResourceAttr("data.snowflake_databases.test", "databases.0.is_current", "true"), @@ -83,7 +83,7 @@ func TestAcc_Databases_Complete(t *testing.T) { resource.TestCheckResourceAttrSet("data.snowflake_databases.test", "databases.0.show_output.0.created_on"), resource.TestCheckResourceAttr("data.snowflake_databases.test", "databases.0.show_output.0.name", databaseName), resource.TestCheckResourceAttr("data.snowflake_databases.test", "databases.0.show_output.0.kind", "STANDARD"), - resource.TestCheckResourceAttr("data.snowflake_databases.test", "databases.0.show_output.0.is_transient", "false"), + resource.TestCheckResourceAttr("data.snowflake_databases.test", "databases.0.show_output.0.transient", "false"), resource.TestCheckResourceAttr("data.snowflake_databases.test", "databases.0.show_output.0.is_default", "false"), // Commenting for the same reason as above // resource.TestCheckResourceAttr("data.snowflake_databases.test", "databases.0.is_current", "false"),