Skip to content

Commit

Permalink
Merge branch 'main' into feature/add-external-tables-to-streams
Browse files Browse the repository at this point in the history
  • Loading branch information
alldoami authored May 31, 2022
2 parents ce964ea + d066d0b commit b1fc73b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
11 changes: 9 additions & 2 deletions pkg/datasources/procedures_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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" {
Expand Down
15 changes: 8 additions & 7 deletions pkg/resources/procedure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
24 changes: 16 additions & 8 deletions pkg/resources/procedure_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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" {
Expand All @@ -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" {
Expand All @@ -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 = <<EOT
var X=1
return X
EOT
language = "javascript"
statement = <<-EOF
var X=1
return X
EOF
}
`, db, schema, name, name, name)
}

0 comments on commit b1fc73b

Please sign in to comment.