From 6cdf9ff566484af45ac56fb9f0c87c49c281f44c Mon Sep 17 00:00:00 2001 From: James Bardin Date: Fri, 8 Mar 2019 17:32:37 -0500 Subject: [PATCH 1/2] Revert "normalize all objects read from the provider" This reverts commit 209a0a460a6ae553b2b728308bda3cdb50b67851. --- helper/plugin/grpc_provider.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/helper/plugin/grpc_provider.go b/helper/plugin/grpc_provider.go index 99877bd3d2..1b046f9d91 100644 --- a/helper/plugin/grpc_provider.go +++ b/helper/plugin/grpc_provider.go @@ -9,8 +9,6 @@ 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" @@ -460,7 +458,6 @@ 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 { @@ -597,7 +594,6 @@ 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 @@ -836,7 +832,6 @@ 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 { @@ -960,7 +955,6 @@ 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 { From b8e53255b477d8172f1bed44570016d07b388d93 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Fri, 8 Mar 2019 17:32:41 -0500 Subject: [PATCH 2/2] Revert "remove NormalizeObjectFromLegacySDK from diff" This reverts commit 5c40d6610cf4ec77b929ba0c22920107d133d0c7. --- command/format/diff.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/command/format/diff.go b/command/format/diff.go index bc9a5763cf..00179da882 100644 --- a/command/format/diff.go +++ b/command/format/diff.go @@ -127,6 +127,16 @@ 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")