existing fields cannot become computed during plan
Fields with no change can only become computed during initial creation.
This commit is contained in:
parent
9a39af5047
commit
49230f8198
|
@ -492,6 +492,8 @@ func (s *GRPCProviderServer) PlanResourceChange(_ context.Context, req *proto.Pl
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
create := priorStateVal.IsNull()
|
||||||
|
|
||||||
proposedNewStateVal, err := msgpack.Unmarshal(req.ProposedNewState.Msgpack, block.ImpliedType())
|
proposedNewStateVal, err := msgpack.Unmarshal(req.ProposedNewState.Msgpack, block.ImpliedType())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
||||||
|
@ -533,7 +535,7 @@ func (s *GRPCProviderServer) PlanResourceChange(_ context.Context, req *proto.Pl
|
||||||
}
|
}
|
||||||
|
|
||||||
// if this is a new instance, we need to make sure ID is going to be computed
|
// if this is a new instance, we need to make sure ID is going to be computed
|
||||||
if priorStateVal.IsNull() {
|
if create {
|
||||||
if diff == nil {
|
if diff == nil {
|
||||||
diff = terraform.NewInstanceDiff()
|
diff = terraform.NewInstanceDiff()
|
||||||
}
|
}
|
||||||
|
@ -556,6 +558,17 @@ func (s *GRPCProviderServer) PlanResourceChange(_ context.Context, req *proto.Pl
|
||||||
priorState = &terraform.InstanceState{}
|
priorState = &terraform.InstanceState{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if we're not creating a new resource, remove any new computed fields
|
||||||
|
if !create {
|
||||||
|
for attr, d := range diff.Attributes {
|
||||||
|
// If there's no change, then don't let this go through as NewComputed.
|
||||||
|
// This usually only happens when Old and New are both empty.
|
||||||
|
if d.NewComputed && d.Old == d.New {
|
||||||
|
delete(diff.Attributes, attr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 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
|
||||||
plannedAttrs, err := diff.Apply(priorState.Attributes, block)
|
plannedAttrs, err := diff.Apply(priorState.Attributes, block)
|
||||||
|
|
||||||
|
@ -598,7 +611,7 @@ func (s *GRPCProviderServer) PlanResourceChange(_ context.Context, req *proto.Pl
|
||||||
|
|
||||||
// if this was creating the resource, we need to set any remaining computed
|
// if this was creating the resource, we need to set any remaining computed
|
||||||
// fields
|
// fields
|
||||||
if priorStateVal.IsNull() {
|
if create {
|
||||||
plannedStateVal = SetUnknowns(plannedStateVal, block)
|
plannedStateVal = SetUnknowns(plannedStateVal, block)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue