Skip to content
Open
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
10 changes: 10 additions & 0 deletions internal/lang/function_results.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ func (f *FunctionResults) CheckPrior(name string, args []cty.Value, result cty.V
// CheckPriorProvider compares the provider function call against any cached
// results, and returns an error if the result does not match a prior call.
func (f *FunctionResults) CheckPriorProvider(provider addrs.Provider, name string, args []cty.Value, result cty.Value) error {
// Don't cache unknown values. We could technically store types and
// refinements for validation, but we don't currently have a way to
// serialize those in the plan. Unknowns are also handled much more
// gracefully throughout the evaluation system, whereas invalid data is
// harder to trace back to the source since it's usually only visible due to
// unexpected side-effects.
if !result.IsKnown() {
return nil
}

argSum := sha256.New()

if !provider.IsZero() {
Expand Down
5 changes: 4 additions & 1 deletion internal/lang/function_results_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestFunctionCache(t *testing.T) {
result: cty.False,
},
// result changed from unknown => false
expectErr: true,
expectErr: false,
},
{
first: testCall{
Expand Down Expand Up @@ -172,6 +172,9 @@ func TestFunctionCache(t *testing.T) {
if err != nil && !test.expectErr {
t.Fatal(err)
}
if err == nil && test.expectErr {
t.Fatal("expected error")
}

// reload the data to ensure we validate identically
newResults := NewFunctionResultsTable(results.GetHashes())
Expand Down
Loading