diff --git a/Makefile b/Makefile index 5a941676641..f080b23aaad 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,7 @@ SHA=$(shell git rev-parse --short HEAD) -VERSION=$(shell cat VERSION) export DIRTY=$(shell if `git diff-index --quiet HEAD --`; then echo false; else echo true; fi) -LDFLAGS=-ldflags "-w -s -X github.com/chanzuckerberg/go-misc/ver.GitSha=${SHA} -X github.com/chanzuckerberg/go-misc/ver.Version=${VERSION} -X github.com/chanzuckerberg/go-misc/ver.Dirty=${DIRTY}" -export BASE_BINARY_NAME=terraform-provider-snowflake_v$(VERSION) +LDFLAGS=-ldflags "-w -s -X github.com/chanzuckerberg/go-misc/ver.GitSha=${SHA} -X github.com/chanzuckerberg/go-misc/ver.Dirty=${DIRTY}" +export BASE_BINARY_NAME=terraform-provider-snowflake export GO111MODULE=on export TF_ACC_TERRAFORM_VERSION=0.13.0 export SKIP_EXTERNAL_TABLE_TESTS=true @@ -23,7 +22,7 @@ setup: ## setup development dependencies curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh bash .download-tfproviderlint.sh - go get golang.org/x/tools/cmd/goimports + go install golang.org/x/tools/cmd/goimports@latest .PHONY: setup lint: fmt ## run the fast go linters diff --git a/pkg/datasources/procedures_acceptance_test.go b/pkg/datasources/procedures_acceptance_test.go index 4334dea77b4..3898232b081 100644 --- a/pkg/datasources/procedures_acceptance_test.go +++ b/pkg/datasources/procedures_acceptance_test.go @@ -50,7 +50,10 @@ resource "snowflake_procedure" "test_proc_simple" { database = snowflake_database.test_database.name schema = snowflake_schema.test_schema.name return_type = "VARCHAR" - statement = "return \"Hi\"" + language = "JAVASCRIPT" + statement = <<-EOF + return "Hi" + EOF } resource "snowflake_procedure" "test_proc" { @@ -63,7 +66,11 @@ resource "snowflake_procedure" "test_proc" { } comment = "Terraform acceptance test" return_type = "varchar" - statement = "var X=3\nreturn X" + language = "JAVASCRIPT" + statement = <<-EOF + var X=1 + return X + EOF } data snowflake_procedures "t" { diff --git a/pkg/resources/procedure.go b/pkg/resources/procedure.go index c634f52f0a1..af6927d74b8 100644 --- a/pkg/resources/procedure.go +++ b/pkg/resources/procedure.go @@ -13,7 +13,7 @@ import ( "github.com/pkg/errors" ) -var procedureLanguages = []string{"JAVASCRIPT", "JAVA", "SCALA", "SQL"} +var procedureLanguages = []string{"javascript", "java", "scala", "SQL"} var procedureSchema = map[string]*schema.Schema{ "name": { @@ -76,7 +76,9 @@ var procedureSchema = map[string]*schema.Schema{ Type: schema.TypeString, Optional: true, Default: "SQL", - ValidateFunc: validation.StringInSlice(procedureLanguages, false), + // Suppress the diff shown if the values are equal when both compared in lower case. + DiffSuppressFunc: DiffTypes, + ValidateFunc: validation.StringInSlice(procedureLanguages, true), Description: "Specifies the language of the stored procedure code.", }, "execute_as": { @@ -170,7 +172,7 @@ func CreateProcedure(d *schema.ResourceData, meta interface{}) error { // Set optionals, default is SQL if v, ok := d.GetOk("language"); ok { - builder.WithLanguage(v.(string)) + builder.WithLanguage(strings.ToUpper(v.(string))) } if v, ok := d.GetOk("comment"); ok { @@ -273,11 +275,10 @@ func ReadProcedure(d *schema.ResourceData, meta interface{}) error { return err } case "language": - if snowflake.Contains(languages, desc.Value.String) { - if err = d.Set("language", desc.Value.String); err != nil { - return err - } + if err = d.Set("language", desc.Value.String); err != nil { + return err } + default: log.Printf("[WARN] unexpected procedure property %v returned from Snowflake", desc.Property.String) } diff --git a/pkg/resources/procedure_acceptance_test.go b/pkg/resources/procedure_acceptance_test.go index c8857a5346a..4675b89731a 100644 --- a/pkg/resources/procedure_acceptance_test.go +++ b/pkg/resources/procedure_acceptance_test.go @@ -18,8 +18,8 @@ func TestAcc_Procedure(t *testing.T) { dbName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) schemaName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) procName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) - expBody1 := "return \"Hi\"" - expBody2 := "var X=3\nreturn X" + expBody1 := "return \"Hi\"\n" + expBody2 := "var X=3\nreturn X\n" expBody3 := "var X=1\nreturn X\n" resource.Test(t, resource.TestCase{ @@ -79,7 +79,10 @@ func procedureConfig(db, schema, name string) string { database = snowflake_database.test_database.name schema = snowflake_schema.test_schema.name return_type = "varchar" - statement = "return \"Hi\"" + language = "javascript" + statement = <<-EOF + return "Hi" + EOF } resource "snowflake_procedure" "test_proc" { @@ -91,8 +94,12 @@ func procedureConfig(db, schema, name string) string { type = "varchar" } comment = "Terraform acceptance test" + language = "javascript" return_type = "varchar" - statement = "var X=3\nreturn X" + statement = <<-EOF + var X=3 + return X + EOF } resource "snowflake_procedure" "test_proc_complex" { @@ -112,10 +119,11 @@ func procedureConfig(db, schema, name string) string { execute_as = "CALLER" return_behavior = "IMMUTABLE" null_input_behavior = "RETURNS NULL ON NULL INPUT" - statement = <