Skip to content

Commit

Permalink
Changes after review + fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jcieslak committed Jun 14, 2024
1 parent 4e2ba31 commit 91d0d50
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions pkg/resources/custom_diffs.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func ParameterValueComputedIf(key string, parameters []*sdk.Parameter, objectPar
// For cases where currently set value (in the config) is equal to the parameter, but not set on the right level.
// The parameter is set somewhere higher in the hierarchy, and we need to "forcefully" set the value to
// perform the actual set on Snowflake (and set the parameter on the correct level).
if ok && !configValue.IsNull() && parameter.Level != objectParameterLevel && parameter.Value == valueToString(d.Get(key)) {
if ok && !configValue.IsNull() && parameter.Level != objectParameterLevel {
return d.SetNewComputed(key)
}

Expand All @@ -50,8 +50,10 @@ func ParameterValueComputedIf(key string, parameters []*sdk.Parameter, objectPar
return nil
}

// Check if the parameter is set on the object level (if so, it means that it was set externally, and we have to unset it).
if parameter.Level == objectParameterLevel {
// If the configuration is not set, perform SetNewComputed for cases like:
// 1. Check if the parameter value differs from the one saved in state (if they differ, we'll update the computed value).
// 2. Check if the parameter is set on the object level (if so, it means that it was set externally, and we have to unset it).
if parameter.Value != valueToString(d.Get(key)) || parameter.Level == objectParameterLevel {
return d.SetNewComputed(key)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/custom_diffs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestParameterValueComputedIf(t *testing.T) {
}), map[string]any{
"value": string(sdk.LogLevelInfo),
})
assert.False(t, diff.Attributes["value"].NewComputed)
assert.True(t, diff.Attributes["value"].NewComputed)
})

t.Run("config: true - state: true - level: same - value: same", func(t *testing.T) {
Expand Down

0 comments on commit 91d0d50

Please sign in to comment.