set unknowns during initial PlanResourceChange
If ID is not set, make sure it's unknown. Use SetUnknowns to set the rest of the computed values to Unknown.
This commit is contained in:
parent
d17ba647a8
commit
32671241e0
|
@ -511,23 +511,30 @@ func (s *GRPCProviderServer) PlanResourceChange(_ context.Context, req *proto.Pl
|
||||||
|
|
||||||
// turn the proposed state into a legacy configuration
|
// turn the proposed state into a legacy configuration
|
||||||
cfg := terraform.NewResourceConfigShimmed(proposedNewStateVal, block)
|
cfg := terraform.NewResourceConfigShimmed(proposedNewStateVal, block)
|
||||||
|
|
||||||
diff, err := s.provider.SimpleDiff(info, priorState, cfg)
|
diff, err := s.provider.SimpleDiff(info, priorState, cfg)
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if this is a new instance, we need to make sure ID is going to be computed
|
||||||
|
if priorStateVal.IsNull() {
|
||||||
|
if diff == nil {
|
||||||
|
diff = terraform.NewInstanceDiff()
|
||||||
|
}
|
||||||
|
|
||||||
|
diff.Attributes["id"] = &terraform.ResourceAttrDiff{
|
||||||
|
NewComputed: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if diff == nil || len(diff.Attributes) == 0 {
|
if diff == nil || len(diff.Attributes) == 0 {
|
||||||
// schema.Provider.Diff returns nil if it ends up making a diff with no
|
// 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
|
// changes, but our new interface wants us to return an actual change
|
||||||
// description that _shows_ there are no changes. This is usually the
|
// description that _shows_ there are no changes. This is always the
|
||||||
// PriorSate, however if there was no prior state and no diff, then we
|
// prior state, because we force a diff above if this is a new instance.
|
||||||
// use the ProposedNewState.
|
|
||||||
if !priorStateVal.IsNull() {
|
|
||||||
resp.PlannedState = req.PriorState
|
resp.PlannedState = req.PriorState
|
||||||
} else {
|
|
||||||
resp.PlannedState = req.ProposedNewState
|
|
||||||
}
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -561,7 +568,7 @@ func (s *GRPCProviderServer) PlanResourceChange(_ context.Context, req *proto.Pl
|
||||||
|
|
||||||
plannedStateVal = copyTimeoutValues(plannedStateVal, proposedNewStateVal)
|
plannedStateVal = copyTimeoutValues(plannedStateVal, proposedNewStateVal)
|
||||||
|
|
||||||
// The old SDK code has some inprecisions that cause it to sometimes
|
// The old SDK code has some imprecisions that cause it to sometimes
|
||||||
// generate differences that the SDK itself does not consider significant
|
// generate differences that the SDK itself does not consider significant
|
||||||
// but Terraform Core would. To avoid producing weird do-nothing diffs
|
// but Terraform Core would. To avoid producing weird do-nothing diffs
|
||||||
// in that case, we'll check if the provider as produced something we
|
// in that case, we'll check if the provider as produced something we
|
||||||
|
@ -575,6 +582,12 @@ func (s *GRPCProviderServer) PlanResourceChange(_ context.Context, req *proto.Pl
|
||||||
forceNoChanges = true
|
forceNoChanges = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if this was creating the resource, we need to set any remaining computed
|
||||||
|
// fields
|
||||||
|
if priorStateVal.IsNull() {
|
||||||
|
plannedStateVal = SetUnknowns(plannedStateVal, block)
|
||||||
|
}
|
||||||
|
|
||||||
plannedMP, err := msgpack.Marshal(plannedStateVal, block.ImpliedType())
|
plannedMP, err := msgpack.Marshal(plannedStateVal, block.ImpliedType())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
||||||
|
|
Loading…
Reference in New Issue