use SimpleDiff and set "id" as RequiresReplace
Use the new SimpleDiff method of the provider so that the diff isn't altered by ForceNew attributes. Always set an "id" as RequiresReplace so core knows an instance will be replaced, even if all ForceNew attributes are filtered out due to ignore_changes.
This commit is contained in:
parent
72a7947cb7
commit
38163f2b37
|
@ -402,7 +402,7 @@ func (s *GRPCProviderServer) PlanResourceChange(_ context.Context, req *proto.Pl
|
||||||
// turn the propsed state into a legacy configuration
|
// turn the propsed state into a legacy configuration
|
||||||
config := terraform.NewResourceConfigShimmed(proposedNewStateVal, block)
|
config := terraform.NewResourceConfigShimmed(proposedNewStateVal, block)
|
||||||
|
|
||||||
diff, err := s.provider.Diff(info, priorState, config)
|
diff, err := s.provider.SimpleDiff(info, priorState, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
||||||
return resp, nil
|
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())
|
requiresReplace, err := hcl2shim.RequiresReplace(requiresNew, block.ImpliedType())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
||||||
|
|
|
@ -25,6 +25,11 @@ func mustShimNewState(newState *states.State, schemas *terraform.Schemas) *terra
|
||||||
func shimNewState(newState *states.State, schemas *terraform.Schemas) (*terraform.State, error) {
|
func shimNewState(newState *states.State, schemas *terraform.Schemas) (*terraform.State, error) {
|
||||||
state := terraform.NewState()
|
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 {
|
for _, newMod := range newState.Modules {
|
||||||
mod := state.AddModule(newMod.Addr)
|
mod := state.AddModule(newMod.Addr)
|
||||||
|
|
||||||
|
|
|
@ -2023,12 +2023,6 @@ func TestShimSchemaMap_Diff(t *testing.T) {
|
||||||
New: "foo",
|
New: "foo",
|
||||||
RequiresNew: true,
|
RequiresNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
// "address": &terraform.ResourceAttrDiff{
|
|
||||||
// Old: "foo",
|
|
||||||
// New: "",
|
|
||||||
// NewComputed: true,
|
|
||||||
// },
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -2074,12 +2068,6 @@ func TestShimSchemaMap_Diff(t *testing.T) {
|
||||||
New: "foo",
|
New: "foo",
|
||||||
RequiresNew: true,
|
RequiresNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
// "ports.#": &terraform.ResourceAttrDiff{
|
|
||||||
// Old: "1",
|
|
||||||
// New: "",
|
|
||||||
// NewComputed: true,
|
|
||||||
// },
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue