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.
This commit is contained in:
Martin Atkins 2018-08-27 17:34:14 -07:00
parent 2f0e5d93c8
commit a7342de274
4 changed files with 24 additions and 6 deletions

View File

@ -91,6 +91,8 @@ func NewPlan(changes *plans.Changes) *Plan {
} }
switch rc.Action { switch rc.Action {
case plans.NoOp:
continue
case plans.Create: case plans.Create:
if dataSource { if dataSource {
// Use "refresh" as the action for display, but core // Use "refresh" as the action for display, but core

View File

@ -386,6 +386,15 @@ func (s *GRPCProviderServer) PlanResourceChange(_ context.Context, req *proto.Pl
return resp, nil 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 // now we need to apply the diff to the prior state, so get the planned state
plannedStateVal, err := schema.ApplyDiff(priorStateVal, diff, block) plannedStateVal, err := schema.ApplyDiff(priorStateVal, diff, block)
if err != nil { if err != nil {

View File

@ -6,6 +6,8 @@ import (
"log" "log"
"sync" "sync"
"github.com/zclconf/go-cty/cty"
plugin "github.com/hashicorp/go-plugin" plugin "github.com/hashicorp/go-plugin"
"github.com/hashicorp/terraform/plugin/convert" "github.com/hashicorp/terraform/plugin/convert"
"github.com/hashicorp/terraform/plugin/proto" "github.com/hashicorp/terraform/plugin/proto"
@ -398,13 +400,16 @@ func (p *GRPCProvider) ApplyResourceChange(r providers.ApplyResourceChangeReques
resp.Private = protoResp.Private resp.Private = protoResp.Private
if protoResp.NewState != nil {
state, err := msgpack.Unmarshal(protoResp.NewState.Msgpack, resSchema.Block.ImpliedType()) state, err := msgpack.Unmarshal(protoResp.NewState.Msgpack, resSchema.Block.ImpliedType())
if err != nil { if err != nil {
resp.Diagnostics = resp.Diagnostics.Append(err) resp.Diagnostics = resp.Diagnostics.Append(err)
return resp return resp
} }
resp.NewState = state resp.NewState = state
} else {
resp.NewState = cty.NullVal(resSchema.Block.ImpliedType())
}
return resp return resp
} }

View File

@ -34,6 +34,8 @@ func (t *DiffTransformer) Transform(g *Graph) error {
// other actions. // other actions.
var update, delete bool var update, delete bool
switch rc.Action { switch rc.Action {
case plans.NoOp:
continue
case plans.Delete: case plans.Delete:
delete = true delete = true
case plans.Replace: case plans.Replace: