Skip to content
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 user parameters to resource #2968

Merged
merged 35 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a761520
add user parameters to resource starts here
sfc-gh-asawicki Jul 25, 2024
290e70e
Add user parameters to schema (WIP)
sfc-gh-asawicki Jul 25, 2024
d430300
Use context funcs in user schema def
sfc-gh-asawicki Jul 25, 2024
d5b2157
Prepare user parameters schema (WIP)
sfc-gh-asawicki Jul 26, 2024
3ae2d09
Add the rest of user parameters
sfc-gh-asawicki Jul 26, 2024
65b1c4f
Add parameter docs enricher
sfc-gh-asawicki Jul 26, 2024
f7b815c
Remove unnecessary Snowflake docs reference
sfc-gh-asawicki Jul 26, 2024
f4bf7d5
Use user parameters schema inside the resource
sfc-gh-asawicki Jul 26, 2024
0d51b8a
Regenerate config builder and resource assertions
sfc-gh-asawicki Jul 26, 2024
cbe44b3
Add user parameters custom diff
sfc-gh-asawicki Jul 26, 2024
b10df4d
Handle user parameters read
sfc-gh-asawicki Jul 26, 2024
b1190c0
Handle user parameters create
sfc-gh-asawicki Jul 26, 2024
f125152
Handle user parameters update
sfc-gh-asawicki Jul 26, 2024
f955c73
Add set/unset parameters logic to the user resource
sfc-gh-asawicki Jul 26, 2024
36fdaa1
Test parameters setting/unsetting through resource
sfc-gh-asawicki Jul 26, 2024
f9fe53b
Add unit test to mappers
sfc-gh-asawicki Jul 26, 2024
0424e13
Add gh issues
sfc-gh-asawicki Jul 30, 2024
2e52cf7
Use new resource parameter methods in database, schema, and warehouse
sfc-gh-asawicki Jul 30, 2024
98fd231
Extract resource parameters commons
sfc-gh-asawicki Jul 30, 2024
fa163ab
Use generic create for database, shared database, secondary database,…
sfc-gh-asawicki Jul 30, 2024
4a4f0c0
Extract schema parameters
sfc-gh-asawicki Jul 30, 2024
e2d3ca0
Run make pre-push
sfc-gh-asawicki Jul 30, 2024
9ea6bc9
Make the parameter methods unexported
sfc-gh-asawicki Jul 30, 2024
5174c87
Add migration guide
sfc-gh-asawicki Jul 30, 2024
202b83f
Fix a few things before the review
sfc-gh-asawicki Jul 30, 2024
e4ea65d
Update migration guide
sfc-gh-asawicki Jul 30, 2024
e8ea492
Fix acceptance tests
sfc-gh-asawicki Jul 30, 2024
c008d12
Fix one more test
sfc-gh-asawicki Jul 30, 2024
9bd3da5
Add missing issues to the list
sfc-gh-asawicki Jul 31, 2024
32df79f
Fix after review
sfc-gh-asawicki Aug 2, 2024
e7923b3
Use new methods in resources and datasources
sfc-gh-asawicki Aug 2, 2024
fae051d
Run pre-push
sfc-gh-asawicki Aug 2, 2024
8c6ce69
Merge branch 'main' into add-user-parameters-to-resource
sfc-gh-asawicki Aug 5, 2024
a7cf32f
Fix the tests after using the sdk function
sfc-gh-asawicki Aug 5, 2024
81243d8
Fix the migration reference
sfc-gh-asawicki Aug 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/resources/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: |-

---

!> **V1 release candidate** This resource was reworked and is a release candidate for the V1. We do not expect significant changes in it before the V1. We will welcome any feedback and adjust the resource if needed. Any errors reported will be resolved with a higher priority. We encourage checking this resource out before the V1 release. Please follow the [migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/MIGRATION_GUIDE.md#v0920--v0930) to use it.
!> **V1 release candidate** This resource was reworked and is a release candidate for the V1. We do not expect significant changes in it before the V1. We will welcome any feedback and adjust the resource if needed. Any errors reported will be resolved with a higher priority. We encourage checking this resource out before the V1 release. Please follow the [migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/MIGRATION_GUIDE.md#v094x--v0950) to use it.

# snowflake_user (Resource)

Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func GetReadUserFunc(withExternalChangesMarking bool) schema.ReadContextFunc {

var defaultSecondaryRoles []string
if user.DefaultSecondaryRoles != nil && len(user.DefaultSecondaryRoles.Value) > 0 {
defaultSecondaryRoles = sdk.ParseCommaSeparatedStringArray(user.DefaultSecondaryRoles.Value, false)
defaultSecondaryRoles = sdk.ParseCommaSeparatedStringArray(user.DefaultSecondaryRoles.Value, true)
}
if err = d.Set("default_secondary_roles", defaultSecondaryRoles); err != nil {
return diag.FromErr(err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/sdk/parsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func ParseCommaSeparatedStringArray(value string, trimQuotes bool) []string {
for i, item := range listItems {
trimmedListItems[i] = strings.TrimSpace(item)
if trimQuotes {
trimmedListItems[i] = strings.Trim(trimmedListItems[i], "'")
trimmedListItems[i] = strings.Trim(trimmedListItems[i], "'\"")
}
}
return trimmedListItems
Expand Down
32 changes: 31 additions & 1 deletion pkg/sdk/parsers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,41 @@ func TestParseCommaSeparatedStringArray(t *testing.T) {
Result: []string{"one", "two", "three"},
},
{
Name: "list without brackets - with quotes",
Name: "list without brackets - with single quotes",
Value: "'one','two','three'",
TrimQuotes: true,
Result: []string{"one", "two", "three"},
},
{
Name: "list without brackets - with double quotes",
Value: `"one","two","three"`,
TrimQuotes: true,
Result: []string{"one", "two", "three"},
},
{
Name: "list with brackets - with double quotes",
Value: `"one","two","three"`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should have brackets (same in the next test case)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change the name of the test in the follow-up PR

TrimQuotes: true,
Result: []string{"one", "two", "three"},
},
{
Name: "list with brackets - with double quotes, no trimming",
Value: `"one","two","three"`,
TrimQuotes: false,
Result: []string{"\"one\"", "\"two\"", "\"three\""},
},
{
Name: "list with brackets - with double quotes",
Value: `["one","two","three"]`,
TrimQuotes: true,
Result: []string{"one", "two", "three"},
},
{
Name: "multiple quote types",
Value: `['"'one'"',"'two",'"three'"]`,
TrimQuotes: true,
Result: []string{"one", "two", "three"},
},
}

for _, tc := range testCases {
Expand Down
2 changes: 1 addition & 1 deletion templates/resources/user.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description: |-
{{- end }}
---

!> **V1 release candidate** This resource was reworked and is a release candidate for the V1. We do not expect significant changes in it before the V1. We will welcome any feedback and adjust the resource if needed. Any errors reported will be resolved with a higher priority. We encourage checking this resource out before the V1 release. Please follow the [migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/MIGRATION_GUIDE.md#v0920--v0930) to use it.
!> **V1 release candidate** This resource was reworked and is a release candidate for the V1. We do not expect significant changes in it before the V1. We will welcome any feedback and adjust the resource if needed. Any errors reported will be resolved with a higher priority. We encourage checking this resource out before the V1 release. Please follow the [migration guide](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/MIGRATION_GUIDE.md#v094x--v0950) to use it.

# {{.Name}} ({{.Type}})

Expand Down
Loading