Merge pull request #20595 from hashicorp/jbardin/normalize-objects

normalize all objects read from the provider
This commit is contained in:
James Bardin 2019-03-06 17:13:23 -05:00 committed by GitHub
commit a95d97f066
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 22 deletions

View File

@ -127,16 +127,6 @@ func ResourceChange(
panic(fmt.Sprintf("failed to decode plan for %s while rendering diff: %s", addr, err))
}
// We currently have an opt-out that permits the legacy SDK to return values
// that defy our usual conventions around handling of nesting blocks. To
// avoid the rendering code from needing to handle all of these, we'll
// normalize first.
// (Ideally we'd do this as part of the SDK opt-out implementation in core,
// but we've added it here for now to reduce risk of unexpected impacts
// on other code in core.)
changeV.Change.Before = objchange.NormalizeObjectFromLegacySDK(changeV.Change.Before, schema)
changeV.Change.After = objchange.NormalizeObjectFromLegacySDK(changeV.Change.After, schema)
bodyWritten := p.writeBlockBodyDiff(schema, changeV.Before, changeV.After, 6, path)
if bodyWritten {
buf.WriteString("\n")

View File

@ -9,6 +9,8 @@ import (
"strconv"
"strings"
"github.com/hashicorp/terraform/plans/objchange"
"github.com/zclconf/go-cty/cty"
ctyconvert "github.com/zclconf/go-cty/cty/convert"
"github.com/zclconf/go-cty/cty/msgpack"
@ -458,6 +460,7 @@ func (s *GRPCProviderServer) ReadResource(_ context.Context, req *proto.ReadReso
}
newStateVal = copyTimeoutValues(newStateVal, stateVal)
newStateVal = objchange.NormalizeObjectFromLegacySDK(newStateVal, block)
newStateMP, err := msgpack.Marshal(newStateVal, block.ImpliedType())
if err != nil {
@ -594,6 +597,7 @@ func (s *GRPCProviderServer) PlanResourceChange(_ context.Context, req *proto.Pl
}
plannedStateVal = copyTimeoutValues(plannedStateVal, proposedNewStateVal)
plannedStateVal = objchange.NormalizeObjectFromLegacySDK(plannedStateVal, block)
// The old SDK code has some imprecisions that cause it to sometimes
// generate differences that the SDK itself does not consider significant
@ -832,6 +836,7 @@ func (s *GRPCProviderServer) ApplyResourceChange(_ context.Context, req *proto.A
newStateVal = normalizeNullValues(newStateVal, plannedStateVal, false)
newStateVal = copyTimeoutValues(newStateVal, plannedStateVal)
newStateVal = objchange.NormalizeObjectFromLegacySDK(newStateVal, block)
newStateMP, err := msgpack.Marshal(newStateVal, block.ImpliedType())
if err != nil {
@ -955,6 +960,7 @@ func (s *GRPCProviderServer) ReadDataSource(_ context.Context, req *proto.ReadDa
}
newStateVal = copyTimeoutValues(newStateVal, configVal)
newStateVal = objchange.NormalizeObjectFromLegacySDK(newStateVal, block)
newStateMP, err := msgpack.Marshal(newStateVal, block.ImpliedType())
if err != nil {

View File

@ -203,12 +203,6 @@ func (n *EvalApply) Eval(ctx EvalContext) (interface{}, error) {
// on the planned value, and thus get a different result during the
// apply phase. This will usually lead to a "Provider produced invalid plan"
// error that incorrectly blames the downstream resource for the change.
//
// TODO: Ideally we should use objchange.NormalizeObjectFromLegacySDK
// here so the rest of Terraform is shielded from some of the oddities
// of the legacy SDK, but for the moment we've done that only in
// format.ResourceChange to reduce the risk of unexpected impacts
// elsewhere.
} else {
for _, err := range errs {

View File

@ -229,12 +229,6 @@ func (n *EvalDiff) Eval(ctx EvalContext) (interface{}, error) {
fmt.Fprintf(&buf, "\n - %s", tfdiags.FormatError(err))
}
log.Print(buf.String())
// TODO: Ideally we should use objchange.NormalizeObjectFromLegacySDK
// here so the rest of Terraform is shielded from some of the oddities
// of the legacy SDK, but for the moment we've done that only in
// format.ResourceChange to reduce the risk of unexpected impacts
// elsewhere.
} else {
for _, err := range errs {
diags = diags.Append(tfdiags.Sourceless(