Skip to content

Commit

Permalink
fix: use suppressQuoting to fix stage file_format permadiff (#2885)
Browse files Browse the repository at this point in the history
We are getting permadiff on stage `file_format` parameter when it
contains quotes, as it used to be the case with `copy_options` (see
#2679)

To fix it, re-using the same `DiffSuppressFunc` seems to do the trick.

## Test Plan
* [x] acceptance tests
* [x] locally built tested
  • Loading branch information
guillaumelecerf authored Jun 27, 2024
1 parent 873a1ed commit fd70f6e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/resources/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func suppressIdentifierQuoting(_, oldValue, newValue string, _ *schema.ResourceD
}

// TODO [SNOW-1325214]: address during stage resource rework
func suppressCopyOptionsQuoting(_, oldValue, newValue string, _ *schema.ResourceData) bool {
func suppressQuoting(_, oldValue, newValue string, _ *schema.ResourceData) bool {
if oldValue == "" || newValue == "" {
return false
} else {
Expand Down
9 changes: 5 additions & 4 deletions pkg/resources/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ var stageSchema = map[string]*schema.Schema{
Description: "Specifies the name of the storage integration used to delegate authentication responsibility for external cloud storage to a Snowflake identity and access management (IAM) entity.",
},
"file_format": {
Type: schema.TypeString,
Optional: true,
Description: "Specifies the file format for the stage.",
Type: schema.TypeString,
Optional: true,
Description: "Specifies the file format for the stage.",
DiffSuppressFunc: suppressQuoting,
},
"copy_options": {
Type: schema.TypeString,
Optional: true,
Description: "Specifies the copy options for the stage.",
DiffSuppressFunc: suppressCopyOptionsQuoting,
DiffSuppressFunc: suppressQuoting,
},
"encryption": {
Type: schema.TypeString,
Expand Down
20 changes: 20 additions & 0 deletions pkg/resources/stage_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func TestAcc_Stage_CreateAndAlter(t *testing.T) {
changedStorageIntegration := ids.PrecreatedS3StorageIntegration
changedEncryption := "TYPE = 'AWS_SSE_S3'"
changedFileFormat := "TYPE = JSON NULL_IF = []"
changedFileFormatWithQuotes := "FIELD_DELIMITER = '|' PARSE_HEADER = true"
changedComment := random.Comment()
copyOptionsWithoutQuotes := "ON_ERROR = CONTINUE"

Expand Down Expand Up @@ -129,6 +130,25 @@ func TestAcc_Stage_CreateAndAlter(t *testing.T) {
PostApplyPreRefresh: []plancheck.PlanCheck{plancheck.ExpectEmptyPlan()},
},
},
{
ConfigDirectory: config.TestNameDirectory(),
ConfigVariables: configVariables(changedUrl, changedStorageIntegration.Name(), credentials, changedEncryption, changedFileFormatWithQuotes, changedComment, copyOptionsWithoutQuotes),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "database", databaseName),
resource.TestCheckResourceAttr(resourceName, "schema", schemaName),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "storage_integration", changedStorageIntegration.Name()),
resource.TestCheckResourceAttr(resourceName, "credentials", credentials),
resource.TestCheckResourceAttr(resourceName, "encryption", changedEncryption),
resource.TestCheckResourceAttr(resourceName, "file_format", changedFileFormatWithQuotes),
resource.TestCheckResourceAttr(resourceName, "copy_options", copyOptionsWithoutQuotes),
resource.TestCheckResourceAttr(resourceName, "url", changedUrl),
resource.TestCheckResourceAttr(resourceName, "comment", changedComment),
),
ConfigPlanChecks: resource.ConfigPlanChecks{
PostApplyPreRefresh: []plancheck.PlanCheck{plancheck.ExpectEmptyPlan()},
},
},
{
ConfigDirectory: config.TestNameDirectory(),
ConfigVariables: configVariables(changedUrl, changedStorageIntegration.Name(), credentials, changedEncryption, changedFileFormat, changedComment, copyOptionsWithoutQuotes),
Expand Down

0 comments on commit fd70f6e

Please sign in to comment.