-
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: add allowed values #1006
Merged
sfc-gh-swinkler
merged 23 commits into
Snowflake-Labs:main
from
sfc-gh-kumaurya:add_allowed_values
May 26, 2022
Merged
feat: add allowed values #1006
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
413162b
Add allowed_values field to the snowflake_tag resource
sfc-gh-kumaurya 5dd57f0
Add allowed_values field to the snowflake_tag resource
sfc-gh-kumaurya 4a6f354
Fixing doc and adding example for snowflake_tag resource
sfc-gh-kumaurya 45aec4e
Fixing doc and adding example for snowflake_tag resource
sfc-gh-kumaurya 8bd4e0e
testing allowed_values
sfc-gh-kumaurya ba38357
testing allowed_values
sfc-gh-kumaurya f6c9c10
testing allowed_values
sfc-gh-kumaurya 60722d5
testing allowed_values
sfc-gh-kumaurya f1ea611
testing allowed_values
sfc-gh-kumaurya 8f6cf9c
testing allowed_values
sfc-gh-kumaurya 3bf5861
adding example usage for snowflake_tag resource
sfc-gh-kumaurya 12d7e57
minor fixes
sfc-gh-kumaurya 19665c1
Moving ListToSnowflakeString functions to helpers directory
sfc-gh-kumaurya 9d33bfe
Moving ListToSnowflakeString functions to helpers directory
sfc-gh-kumaurya 909288f
pull changes from snowflakelabs/terraform-provider-snowflake
sfc-gh-kumaurya c6d0d23
Merge branch 'Snowflake-Labs-main' into add_allowed_values
sfc-gh-kumaurya 9302e1a
Updating with latest changes
sfc-gh-kumaurya 8d892b0
Merge branch 'Snowflake-Labs-main' into add_allowed_values
sfc-gh-kumaurya 239a98f
Updating import
sfc-gh-kumaurya fd8770c
Updating import for tag
sfc-gh-kumaurya 92c16cc
Updating import
sfc-gh-kumaurya bc1b0d9
Updating acceptance tests of table annd tag for allowed_values
sfc-gh-kumaurya 1ffdd57
Merge branch 'main' into add_allowed_values
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# format is database name | schema name | tag name | ||
terraform import snowflake_tag.example 'dbName|schemaName|tagName' |
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,10 @@ | ||
resource "snowflake_tag" "test_tag" { | ||
// Required | ||
name = "tag_name" | ||
database = "test_db" | ||
schema = "test_schema" | ||
|
||
// Optionals | ||
comment = "test comment" | ||
allowed_values = ["foo", "bar"] | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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,27 @@ | ||
package helpers | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// ToDo: We can merge these two functions together and also add more functions here with similar functionality | ||
|
||
// This function converts list of string into snowflake formated string like 'ele1', 'ele2' | ||
func ListToSnowflakeString(list []string) string { | ||
for index, element := range list { | ||
list[index] = fmt.Sprintf(`'%v'`, strings.ReplaceAll(element, "'", "\\'")) | ||
} | ||
|
||
str := fmt.Sprintf(strings.Join(list, ", ")) | ||
return str | ||
} | ||
|
||
// IpListToString formats a list of IPs into a Snowflake-DDL friendly string, e.g. ('192.168.1.0', '192.168.1.100') | ||
func IpListToSnowflakeString(ips []string) string { | ||
for index, element := range ips { | ||
ips[index] = fmt.Sprintf(`'%v'`, element) | ||
} | ||
|
||
return fmt.Sprintf("(%v)", strings.Join(ips, ", ")) | ||
} |
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
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 |
---|---|---|
|
@@ -23,17 +23,18 @@ func TestTagCreate(t *testing.T) { | |
r := require.New(t) | ||
|
||
in := map[string]interface{}{ | ||
"name": "good_name", | ||
"database": "test_db", | ||
"schema": "test_schema", | ||
"comment": "great comment", | ||
"name": "good_name", | ||
"database": "test_db", | ||
"schema": "test_schema", | ||
"comment": "great comment", | ||
"allowed_values": []interface{}{"marketing", "finance"}, | ||
} | ||
d := schema.TestResourceDataRaw(t, resources.Tag().Schema, in) | ||
r.NotNil(d) | ||
|
||
WithMockDb(t, func(db *sql.DB, mock sqlmock.Sqlmock) { | ||
mock.ExpectExec( | ||
`^CREATE TAG "test_db"."test_schema"."good_name" COMMENT = 'great comment'$`, | ||
`^CREATE TAG "test_db"."test_schema"."good_name" ALLOWED_VALUES 'marketing', 'finance' COMMENT = 'great comment'$`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add test case like |
||
).WillReturnResult(sqlmock.NewResult(1, 1)) | ||
|
||
expectReadTag(mock) | ||
|
@@ -46,19 +47,20 @@ func TestTagUpdate(t *testing.T) { | |
r := require.New(t) | ||
|
||
in := map[string]interface{}{ | ||
"name": "good_name", | ||
"database": "test_db", | ||
"schema": "test_schema", | ||
"comment": "great comment", | ||
"name": "good_name", | ||
"database": "test_db", | ||
"schema": "test_schema", | ||
"comment": "great comment", | ||
"allowed_values": []interface{}{"marketing", "finance"}, | ||
} | ||
|
||
d := tag(t, "test_db|test_schema|good_name", in) | ||
r.NotNil(d) | ||
|
||
WithMockDb(t, func(db *sql.DB, mock sqlmock.Sqlmock) { | ||
mock.ExpectExec( | ||
`^ALTER TAG "test_db"."test_schema"."good_name" SET COMMENT = 'great comment'$`, | ||
).WillReturnResult(sqlmock.NewResult(1, 1)) | ||
mock.ExpectExec(`^ALTER TAG "test_db"."test_schema"."good_name" SET COMMENT = 'great comment'$`).WillReturnResult(sqlmock.NewResult(1, 1)) | ||
mock.ExpectExec(`^ALTER TAG "test_db"."test_schema"."good_name" UNSET ALLOWED_VALUES$`).WillReturnResult(sqlmock.NewResult(1, 1)) | ||
mock.ExpectExec(`^ALTER TAG "test_db"."test_schema"."good_name" ADD ALLOWED_VALUES 'marketing', 'finance'$`).WillReturnResult(sqlmock.NewResult(1, 1)) | ||
|
||
expectReadTag(mock) | ||
err := resources.UpdateTag(d, db) | ||
|
@@ -114,7 +116,7 @@ func TestTagRead(t *testing.T) { | |
|
||
func expectReadTag(mock sqlmock.Sqlmock) { | ||
rows := sqlmock.NewRows([]string{ | ||
"created_on", "name", "database_name", "schema_name", "owner", "comment"}, | ||
).AddRow("2019-05-19 16:55:36.530 -0700", "good_name", "test_db", "test_schema", "admin", "great comment") | ||
"created_on", "name", "database_name", "schema_name", "owner", "comment", "allowed_values"}, | ||
).AddRow("2019-05-19 16:55:36.530 -0700", "good_name", "test_db", "test_schema", "admin", "great comment", "'al1','al2'") | ||
mock.ExpectQuery(`^SHOW TAGS LIKE 'good_name' IN SCHEMA "test_db"."test_schema"$`).WillReturnRows(rows) | ||
} |
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
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.
will this still work if someone wants a tag value like
foo[bar]
? instead of re-writing a partial parser, can we re-use an existing helper function?