diff --git a/helper/plugin/grpc_provider.go b/helper/plugin/grpc_provider.go index d99e8bb29..ff66486b8 100644 --- a/helper/plugin/grpc_provider.go +++ b/helper/plugin/grpc_provider.go @@ -402,7 +402,7 @@ func (s *GRPCProviderServer) PlanResourceChange(_ context.Context, req *proto.Pl // turn the propsed state into a legacy configuration config := terraform.NewResourceConfigShimmed(proposedNewStateVal, block) - diff, err := s.provider.Diff(info, priorState, config) + diff, err := s.provider.SimpleDiff(info, priorState, config) if err != nil { resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err) return resp, nil @@ -450,6 +450,15 @@ func (s *GRPCProviderServer) PlanResourceChange(_ context.Context, req *proto.Pl } } + // If anything requires a new resource already, or the "id" field indicates + // that we will be creating a new resource, then we need to add that to + // RequiresReplace so that core can tell if the instance is being replaced + // even if changes are being suppressed via "ignore_changes". + id := plannedStateVal.GetAttr("id") + if len(requiresNew) > 0 || id.IsNull() || !id.IsKnown() { + requiresNew = append(requiresNew, "id") + } + requiresReplace, err := hcl2shim.RequiresReplace(requiresNew, block.ImpliedType()) if err != nil { resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err) diff --git a/helper/resource/state_shim.go b/helper/resource/state_shim.go index 16f13cdac..9ad30d3ac 100644 --- a/helper/resource/state_shim.go +++ b/helper/resource/state_shim.go @@ -25,6 +25,11 @@ func mustShimNewState(newState *states.State, schemas *terraform.Schemas) *terra func shimNewState(newState *states.State, schemas *terraform.Schemas) (*terraform.State, error) { state := terraform.NewState() + // in the odd case of a nil state, let the helper packages handle it + if newState == nil { + return nil, nil + } + for _, newMod := range newState.Modules { mod := state.AddModule(newMod.Addr) diff --git a/helper/schema/shims_test.go b/helper/schema/shims_test.go index 61919f3cc..e08126893 100644 --- a/helper/schema/shims_test.go +++ b/helper/schema/shims_test.go @@ -2023,12 +2023,6 @@ func TestShimSchemaMap_Diff(t *testing.T) { New: "foo", RequiresNew: true, }, - - // "address": &terraform.ResourceAttrDiff{ - // Old: "foo", - // New: "", - // NewComputed: true, - // }, }, }, @@ -2074,12 +2068,6 @@ func TestShimSchemaMap_Diff(t *testing.T) { New: "foo", RequiresNew: true, }, - - // "ports.#": &terraform.ResourceAttrDiff{ - // Old: "1", - // New: "", - // NewComputed: true, - // }, }, },