From 22f21db2295c57d52a62ac0569f05fb4c5ddac55 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 16 Feb 2021 12:51:23 -0500 Subject: [PATCH] reverse call to TestConformance in objchange The call to TestConformance needs to be reversed, since we want to verify that the actual value returned conforms to the planned type. While the inverse (checking that the planned value conforms to the applied type) works for everything terraform has been exposed to up until now, this fails when the planned type has dynamic attributes which are allowed to become concrete types. --- plans/objchange/compatible.go | 2 +- plans/objchange/compatible_test.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/plans/objchange/compatible.go b/plans/objchange/compatible.go index efb4023d2..0ef4b01e7 100644 --- a/plans/objchange/compatible.go +++ b/plans/objchange/compatible.go @@ -219,7 +219,7 @@ func assertValueCompatible(planned, actual cty.Value, path cty.Path) []error { // Anything goes, then return errs } - if problems := planned.Type().TestConformance(actual.Type()); len(problems) > 0 { + if problems := actual.Type().TestConformance(planned.Type()); len(problems) > 0 { errs = append(errs, path.NewErrorf("wrong final value type: %s", convert.MismatchMessage(actual.Type(), planned.Type()))) // If the types don't match then we can't do any other comparisons, // so we bail early. diff --git a/plans/objchange/compatible_test.go b/plans/objchange/compatible_test.go index ac3793674..678ce8ce3 100644 --- a/plans/objchange/compatible_test.go +++ b/plans/objchange/compatible_test.go @@ -260,6 +260,28 @@ func TestAssertObjectCompatible(t *testing.T) { }), []string{}, }, + { + &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "obj": { + Type: cty.Object(map[string]cty.Type{ + "stuff": cty.DynamicPseudoType, + }), + }, + }, + }, + cty.ObjectVal(map[string]cty.Value{ + "obj": cty.ObjectVal(map[string]cty.Value{ + "stuff": cty.DynamicVal, + }), + }), + cty.ObjectVal(map[string]cty.Value{ + "obj": cty.ObjectVal(map[string]cty.Value{ + "stuff": cty.NumberIntVal(3), + }), + }), + []string{}, + }, { &configschema.Block{ Attributes: map[string]*configschema.Attribute{