-
Notifications
You must be signed in to change notification settings - Fork 427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: use sdk for procedures #2450
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2d93573
use sdk for procedures
sfc-gh-swinkler 8b9b04e
fix
sfc-gh-swinkler cebb7c4
updatae procedures
sfc-gh-swinkler 3b8cb2f
Merge branch 'main' into use-proc
sfc-gh-swinkler 21d8601
update migration guide
sfc-gh-swinkler 2f63d7e
Merge branch 'main' into use-proc
sfc-gh-swinkler b813938
update
sfc-gh-swinkler 118400b
Merge branch 'main' into use-proc
sfc-gh-swinkler 87a2598
comment out broken test
sfc-gh-swinkler 8f022a6
revert migration guide change
sfc-gh-swinkler 6ec3403
update
sfc-gh-swinkler 9a3c39e
Merge branch 'main' into use-proc
sfc-gh-swinkler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,48 @@ | ||
package datasources_test | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance" | ||
"github.com/hashicorp/terraform-plugin-testing/config" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-testing/tfversion" | ||
) | ||
|
||
func TestAcc_Procedures(t *testing.T) { | ||
databaseName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) | ||
schemaName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) | ||
procedureName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) | ||
procedureWithArgumentsName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) | ||
resource.ParallelTest(t, resource.TestCase{ | ||
Providers: providers(), | ||
procNameOne := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) | ||
procNameTwo := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) | ||
dataSourceName := "data.snowflake_procedures.procedures" | ||
m := func() map[string]config.Variable { | ||
return map[string]config.Variable{ | ||
"database": config.StringVariable(acc.TestDatabaseName), | ||
"schema": config.StringVariable(acc.TestSchemaName), | ||
"proc_name_one": config.StringVariable(procNameOne), | ||
"proc_name_two": config.StringVariable(procNameTwo), | ||
} | ||
} | ||
configVariables := m() | ||
resource.Test(t, resource.TestCase{ | ||
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories, | ||
PreCheck: func() { acc.TestAccPreCheck(t) }, | ||
TerraformVersionChecks: []tfversion.TerraformVersionCheck{ | ||
tfversion.RequireAbove(tfversion.Version1_5_0), | ||
}, | ||
CheckDestroy: nil, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: procedures(databaseName, schemaName, procedureName, procedureWithArgumentsName), | ||
ConfigDirectory: acc.ConfigurationDirectory("TestAcc_Procedures/complete"), | ||
ConfigVariables: configVariables, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.snowflake_procedures.t", "database", databaseName), | ||
resource.TestCheckResourceAttr("data.snowflake_procedures.t", "schema", schemaName), | ||
resource.TestCheckResourceAttrSet("data.snowflake_procedures.t", "procedures.#"), | ||
// resource.TestCheckResourceAttr("data.snowflake_procedures.t", "procedures.#", "3"), | ||
resource.TestCheckResourceAttr(dataSourceName, "database", acc.TestDatabaseName), | ||
resource.TestCheckResourceAttr(dataSourceName, "schema", acc.TestSchemaName), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "procedures.#"), | ||
// resource.TestCheckResourceAttr(dataSourceName, "procedures.#", "3"), | ||
sfc-gh-jcieslak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Extra 1 in procedure count above due to ASSOCIATE_SEMANTIC_CATEGORY_TAGS appearing in all "SHOW PROCEDURES IN ..." commands | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func procedures(databaseName string, schemaName string, procedureName string, procedureWithArgumentsName string) string { | ||
s := ` | ||
resource "snowflake_database" "test_database" { | ||
name = "%v" | ||
comment = "Terraform acceptance test" | ||
} | ||
|
||
resource "snowflake_schema" "test_schema" { | ||
name = "%v" | ||
database = snowflake_database.test_database.name | ||
comment = "Terraform acceptance test" | ||
} | ||
|
||
resource "snowflake_procedure" "test_proc_simple" { | ||
name = "%v" | ||
database = snowflake_database.test_database.name | ||
schema = snowflake_schema.test_schema.name | ||
return_type = "VARCHAR" | ||
language = "JAVASCRIPT" | ||
statement = <<-EOF | ||
return "Hi" | ||
EOF | ||
} | ||
|
||
resource "snowflake_procedure" "test_proc" { | ||
name = "%v" | ||
database = snowflake_database.test_database.name | ||
schema = snowflake_schema.test_schema.name | ||
arguments { | ||
name = "arg1" | ||
type = "varchar" | ||
} | ||
comment = "Terraform acceptance test" | ||
return_type = "varchar" | ||
language = "JAVASCRIPT" | ||
statement = <<-EOF | ||
var X=1 | ||
return X | ||
EOF | ||
} | ||
|
||
data snowflake_procedures "t" { | ||
database = snowflake_database.test_database.name | ||
schema = snowflake_schema.test_schema.name | ||
depends_on = [snowflake_procedure.test_proc_simple, snowflake_procedure.test_proc] | ||
} | ||
` | ||
return fmt.Sprintf(s, databaseName, schemaName, procedureName, procedureWithArgumentsName) | ||
} |
49 changes: 49 additions & 0 deletions
49
pkg/datasources/testdata/TestAcc_Procedures/complete/test.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
variable "proc_name_one" { | ||
type = string | ||
} | ||
|
||
variable "proc_name_two" { | ||
type = string | ||
} | ||
|
||
variable "database" { | ||
type = string | ||
} | ||
|
||
variable "schema" { | ||
type = string | ||
} | ||
|
||
resource "snowflake_procedure" "test_proc_one" { | ||
name = var.proc_name_one | ||
database = var.database | ||
schema = var.schema | ||
return_type = "VARCHAR" | ||
language = "JAVASCRIPT" | ||
statement = <<-EOF | ||
return "Hi" | ||
EOF | ||
} | ||
|
||
resource "snowflake_procedure" "test_proc_two" { | ||
name = var.proc_name_two | ||
database = var.database | ||
schema = var.schema | ||
arguments { | ||
name = "arg1" | ||
type = "varchar" | ||
} | ||
comment = "Terraform acceptance test" | ||
return_type = "varchar" | ||
language = "JAVASCRIPT" | ||
statement = <<-EOF | ||
var X=1 | ||
return X | ||
EOF | ||
} | ||
|
||
data "snowflake_procedures" "procedures" { | ||
database = var.database | ||
schema = var.schema | ||
depends_on = [snowflake_procedure.test_proc_one, snowflake_procedure.test_proc_two] | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this is removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looked like it was re-written? at the top is a new migration guide intro.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was added to point the users to the resource migration guide, I would leave it as it was
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please revert this whole paragraph. Also,
TestInt_CreateProcedures
is failing, so we cannot merge it yet.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-added paragraph. Commented out problem in TestInt_CreateProcedures, its an issue I already filed with docs-discuss channel. Included jira ticket in the comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test still failing, but passes locally:
unsure what is going on, going to re-run tests