From a7342de274d4d498538131f3dd338a65f6fce74b Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Mon, 27 Aug 2018 17:34:14 -0700 Subject: [PATCH] core: Properly handle no-op changes in plan Previously we just left these out of the plan altogether, but in the new plan types we intentionally include change information for every resource instance, even if no changes are actually planned, to allow alternative plan file viewers to show what isn't changing as well as what is. --- command/format/plan.go | 2 ++ helper/plugin/grpc_provider.go | 9 +++++++++ plugin/grpc_provider.go | 17 +++++++++++------ terraform/transform_diff.go | 2 ++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/command/format/plan.go b/command/format/plan.go index a2a49c303..e02190f9e 100644 --- a/command/format/plan.go +++ b/command/format/plan.go @@ -91,6 +91,8 @@ func NewPlan(changes *plans.Changes) *Plan { } switch rc.Action { + case plans.NoOp: + continue case plans.Create: if dataSource { // Use "refresh" as the action for display, but core diff --git a/helper/plugin/grpc_provider.go b/helper/plugin/grpc_provider.go index 0c8417460..be3bbc61f 100644 --- a/helper/plugin/grpc_provider.go +++ b/helper/plugin/grpc_provider.go @@ -386,6 +386,15 @@ func (s *GRPCProviderServer) PlanResourceChange(_ context.Context, req *proto.Pl return resp, nil } + if diff == nil { + // schema.Provider.Diff returns nil if it ends up making a diff with + // no changes, but our new interface wants us to return an actual + // change description that _shows_ there are no changes, so we need + // to synthesize one here. + resp.PlannedState = req.PriorState + return resp, nil + } + // now we need to apply the diff to the prior state, so get the planned state plannedStateVal, err := schema.ApplyDiff(priorStateVal, diff, block) if err != nil { diff --git a/plugin/grpc_provider.go b/plugin/grpc_provider.go index 6d8cfe65c..3b066258d 100644 --- a/plugin/grpc_provider.go +++ b/plugin/grpc_provider.go @@ -6,6 +6,8 @@ import ( "log" "sync" + "github.com/zclconf/go-cty/cty" + plugin "github.com/hashicorp/go-plugin" "github.com/hashicorp/terraform/plugin/convert" "github.com/hashicorp/terraform/plugin/proto" @@ -398,14 +400,17 @@ func (p *GRPCProvider) ApplyResourceChange(r providers.ApplyResourceChangeReques resp.Private = protoResp.Private - state, err := msgpack.Unmarshal(protoResp.NewState.Msgpack, resSchema.Block.ImpliedType()) - if err != nil { - resp.Diagnostics = resp.Diagnostics.Append(err) - return resp + if protoResp.NewState != nil { + state, err := msgpack.Unmarshal(protoResp.NewState.Msgpack, resSchema.Block.ImpliedType()) + if err != nil { + resp.Diagnostics = resp.Diagnostics.Append(err) + return resp + } + resp.NewState = state + } else { + resp.NewState = cty.NullVal(resSchema.Block.ImpliedType()) } - resp.NewState = state - return resp } diff --git a/terraform/transform_diff.go b/terraform/transform_diff.go index 67a94fed9..f22c17f7b 100644 --- a/terraform/transform_diff.go +++ b/terraform/transform_diff.go @@ -34,6 +34,8 @@ func (t *DiffTransformer) Transform(g *Graph) error { // other actions. var update, delete bool switch rc.Action { + case plans.NoOp: + continue case plans.Delete: delete = true case plans.Replace: