Skip to content

Commit a7e2c9f

Browse files
authored
Merge pull request #37810 from hashicorp/jbardin/unknown-pure-results
filesystem functions, don't cache unknown function results
2 parents 620264e + 2227441 commit a7e2c9f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

internal/lang/function_results.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ func (f *FunctionResults) CheckPrior(name string, args []cty.Value, result cty.V
5151
// CheckPriorProvider compares the provider function call against any cached
5252
// results, and returns an error if the result does not match a prior call.
5353
func (f *FunctionResults) CheckPriorProvider(provider addrs.Provider, name string, args []cty.Value, result cty.Value) error {
54+
// Don't cache unknown values. We could technically store types and
55+
// refinements for validation, but we don't currently have a way to
56+
// serialize those in the plan. Unknowns are also handled much more
57+
// gracefully throughout the evaluation system, whereas invalid data is
58+
// harder to trace back to the source since it's usually only visible due to
59+
// unexpected side-effects.
60+
if !result.IsKnown() {
61+
return nil
62+
}
63+
5464
argSum := sha256.New()
5565

5666
if !provider.IsZero() {

internal/lang/function_results_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func TestFunctionCache(t *testing.T) {
7272
result: cty.False,
7373
},
7474
// result changed from unknown => false
75-
expectErr: true,
75+
expectErr: false,
7676
},
7777
{
7878
first: testCall{
@@ -172,6 +172,9 @@ func TestFunctionCache(t *testing.T) {
172172
if err != nil && !test.expectErr {
173173
t.Fatal(err)
174174
}
175+
if err == nil && test.expectErr {
176+
t.Fatal("expected error")
177+
}
175178

176179
// reload the data to ensure we validate identically
177180
newResults := NewFunctionResultsTable(results.GetHashes())

0 commit comments

Comments
 (0)