core: Always set ProviderAddr on EvalDiffDestroy

If we don't set it, we end up creating an invalid plan where the destroy
changes don't have a provider address set, which then later fails
decoding when round-tripped through a planfile.

This also includes some extra safety checks in EvalDiff and
EvalDiffDestroy so that we can catch this bug sooner in future.

This change is verified by
TestContext2Apply_plannedDestroyInterpolatedCount, which is now passing.
pull/19086/head
Martin Atkins 8 years ago
parent 48dd8ddec5
commit 49fa2b3f35

@ -123,6 +123,9 @@ func (n *EvalDiff) Eval(ctx EvalContext) (interface{}, error) {
if providerSchema == nil {
return nil, fmt.Errorf("provider schema is unavailable for %s", n.Addr)
}
if n.ProviderAddr.ProviderConfig.Type == "" {
panic(fmt.Sprintf("EvalDiff for %s does not have ProviderAddr set", n.Addr.Absolute(ctx.Path())))
}
var diags tfdiags.Diagnostics
@ -707,6 +710,14 @@ func (n *EvalDiffDestroy) Eval(ctx EvalContext) (interface{}, error) {
absAddr := n.Addr.Absolute(ctx.Path())
state := *n.State
if n.ProviderAddr.ProviderConfig.Type == "" {
if n.DeposedKey == "" {
panic(fmt.Sprintf("EvalDiffDestroy for %s does not have ProviderAddr set", absAddr))
} else {
panic(fmt.Sprintf("EvalDiffDestroy for %s (deposed %s) does not have ProviderAddr set", absAddr, n.DeposedKey))
}
}
// If there is no state or our attributes object is null then we're already
// destroyed.
if state == nil || state.Value.IsNull() {

@ -131,10 +131,11 @@ func (n *NodePlanDeposedResourceInstanceObject) EvalTree() EvalNode {
ProviderSchema: &providerSchema,
},
&EvalDiffDestroy{
Addr: addr.Resource,
DeposedKey: n.DeposedKey,
State: &state,
Output: &change,
Addr: addr.Resource,
ProviderAddr: n.ResolvedProvider,
DeposedKey: n.DeposedKey,
State: &state,
Output: &change,
},
&EvalWriteDiff{
Addr: addr.Resource,
@ -244,9 +245,10 @@ func (n *NodeDestroyDeposedResourceInstanceObject) EvalTree() EvalNode {
ProviderSchema: &providerSchema,
},
&EvalDiffDestroy{
Addr: addr.Resource,
State: &state,
Output: &change,
Addr: addr.Resource,
ProviderAddr: n.ResolvedProvider,
State: &state,
Output: &change,
},
// Call pre-apply hook
&EvalApplyPre{

@ -68,9 +68,10 @@ func (n *NodePlanDestroyableResourceInstance) EvalTree() EvalNode {
Output: &state,
},
&EvalDiffDestroy{
Addr: addr.Resource,
State: &state,
Output: &change,
Addr: addr.Resource,
ProviderAddr: n.ResolvedProvider,
State: &state,
Output: &change,
},
&EvalCheckPreventDestroy{
Addr: addr.Resource,

Loading…
Cancel
Save