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

fix: default_role should ignore diffs of the form "thing" -> "\"thing\"" #2836

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions pkg/resources/common.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package resources

import (
"fmt"
"strings"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/helpers"
Expand Down Expand Up @@ -42,6 +43,22 @@ func suppressIdentifierQuoting(_, oldValue, newValue string, _ *schema.ResourceD
}
}

// Snowflake by nature requires identifiers with spaces to be surrounded by quotes.
// Why would you have an identifier with spaces, you ask?
// Well, for instance, if SAML usergroups are mapped directly to roles,
// then default_role might end up being "\"ENGINEERING STAFF\"",
// but this is read afterwards as "ENGINEERING STAFF", causing a permanent diff.
// This seems oddly specific, but this is a real issue we're having in production!

// Suppress a diff of the nature "SOMETHING" -> "\"SOMETHING\""
func suppressEscapeQuotes(_, oldValue, newValue string, _ *schema.ResourceData) bool {
if oldValue == "" || newValue == "" {
return false
} else {
return oldValue == fmt.Sprintf("\"%s\"", newValue) || newValue == fmt.Sprintf("\"%s\"", oldValue)
}
}

// TODO [SNOW-1325214]: address during stage resource rework
func suppressCopyOptionsQuoting(_, oldValue, newValue string, _ *schema.ResourceData) bool {
if oldValue == "" || newValue == "" {
Expand Down
7 changes: 6 additions & 1 deletion pkg/resources/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ var diffCaseInsensitive = func(k, old, new string, d *schema.ResourceData) bool
return strings.EqualFold(old, new)
}

var diffDefaultRole = func(k, old, new string, d *schema.ResourceData) bool {
return diffCaseInsensitive(k, old, new, d) || suppressEscapeQuotes(k, old, new, d)
}


var userSchema = map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -66,7 +71,7 @@ var userSchema = map[string]*schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
DiffSuppressFunc: diffCaseInsensitive,
DiffSuppressFunc: diffDefaultRole,
Description: "Specifies the role that is active by default for the user’s session upon login.",
},
"default_secondary_roles": {
Expand Down