Skip to content

Commit

Permalink
Fixes #1021 (#1332)
Browse files Browse the repository at this point in the history
Fixes #1021

Fixes accessing RawConfig panics on seeing a nil. This bug used to breaks providers that use GetRawConfig() in diff customizers, which is a common idiom in TF. The fix is along the same lines as #1314 - we propagate the current notion of rawConfigVal to populate the structure in question. This should be much better than panic in these situations but there's more work remaining in the future to make sure the rawConfigVal is similar to what TF would pass in the same situation to avoid logical discrepancies.
  • Loading branch information
t0yv0 authored Aug 7, 2023
1 parent e059ff2 commit 801d870
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/tfbridge/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func TestCustomizeDiff(t *testing.T) {
assert.Equal(t, expectedDiff, diff)
})

t.Run("CustomDiffDoesNotPanicOnGetRawState", func(t *testing.T) {
t.Run("CustomDiffDoesNotPanicOnGetRawStateOrRawConfig", func(t *testing.T) {
for _, diffStrat := range []shimv2.DiffStrategy{shimv2.PlanState, shimv2.ClassicDiff} {
diffStrat := diffStrat
t.Run(fmt.Sprintf("%v", diffStrat), func(t *testing.T) {
Expand All @@ -156,6 +156,10 @@ func TestCustomizeDiff(t *testing.T) {
if !rawStateType.HasAttribute("outp") {
return fmt.Errorf("Expected rawState type to have attribute: outp")
}
rawConfigType := diff.GetRawConfig().Type()
if !rawConfigType.HasAttribute("outp") {
return fmt.Errorf("Expected rawConfig type to have attribute: outp")
}
return nil
},
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/tfshim/sdk-v2/provider_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ func (p v2Provider) simpleDiff(
}
state.RawState = priorStateVal
}
if state.RawConfig.IsNull() {
// Same trick as above.
state.RawConfig = rawConfigVal
}
return res.SimpleDiff(ctx, state, c, meta)
case PlanState:
return simpleDiffViaPlanState(ctx, res, s, rawConfigVal, meta)
Expand Down Expand Up @@ -158,6 +162,9 @@ func simpleDiffViaPlanState(
if state.RawState.IsNull() {
state.RawState = priorStateVal
}
if state.RawConfig.IsNull() {
state.RawConfig = rawConfigVal
}
return res.SimpleDiff(ctx, state, planned, meta)
}

Expand Down

0 comments on commit 801d870

Please sign in to comment.