remove the applyError argument to apply

This was never assigned, and the empty value made the usage very
difficult to trace.
This commit is contained in:
James Bardin 2021-01-13 14:09:20 -05:00
parent 842c5b4136
commit 1707685350
5 changed files with 21 additions and 18 deletions

View File

@ -12553,15 +12553,15 @@ func TestContext2Apply_errorRestoreStatus(t *testing.T) {
state, diags = ctx.Apply()
if len(diags) != 2 {
t.Fatal("expected 1 error and 1 warning")
}
errString := diags.ErrWithWarnings().Error()
if !strings.Contains(errString, "oops") || !strings.Contains(errString, "warned") {
t.Fatalf("error missing expected info: %q", errString)
}
if len(diags) != 2 {
t.Fatalf("expected 1 error and 1 warning, got: %q", errString)
}
res := state.ResourceInstance(addr)
if res == nil {
t.Fatal("resource was removed from state")

View File

@ -1814,8 +1814,7 @@ func (n *NodeAbstractResourceInstance) apply(
state *states.ResourceInstanceObject,
change *plans.ResourceInstanceChange,
applyConfig *configs.Resource,
createBeforeDestroy bool,
applyError error) (*states.ResourceInstanceObject, tfdiags.Diagnostics, error) {
createBeforeDestroy bool) (*states.ResourceInstanceObject, tfdiags.Diagnostics, error) {
var diags tfdiags.Diagnostics
if state == nil {
@ -1824,13 +1823,13 @@ func (n *NodeAbstractResourceInstance) apply(
provider, providerSchema, err := getProvider(ctx, n.ResolvedProvider)
if err != nil {
return nil, diags.Append(err), applyError
return nil, diags.Append(err), nil
}
schema, _ := providerSchema.SchemaForResourceType(n.Addr.Resource.Resource.Mode, n.Addr.Resource.Resource.Type)
if schema == nil {
// Should be caught during validation, so we don't bother with a pretty error here
diags = diags.Append(fmt.Errorf("provider does not support resource type %q", n.Addr.Resource.Resource.Type))
return nil, diags, applyError
return nil, diags, nil
}
log.Printf("[INFO] Starting apply for %s", n.Addr)
@ -1843,7 +1842,7 @@ func (n *NodeAbstractResourceInstance) apply(
configVal, _, configDiags = ctx.EvaluateBlock(applyConfig.Config, schema, nil, keyData)
diags = diags.Append(configDiags)
if configDiags.HasErrors() {
return nil, diags, applyError
return nil, diags, nil
}
}
@ -1852,13 +1851,13 @@ func (n *NodeAbstractResourceInstance) apply(
"configuration for %s still contains unknown values during apply (this is a bug in Terraform; please report it!)",
n.Addr,
))
return nil, diags, applyError
return nil, diags, nil
}
metaConfigVal, metaDiags := n.providerMetas(ctx)
diags = diags.Append(metaDiags)
if diags.HasErrors() {
return nil, diags, applyError
return nil, diags, nil
}
log.Printf("[DEBUG] %s: applying the planned %s change", n.Addr, change.Action)
@ -1886,7 +1885,7 @@ func (n *NodeAbstractResourceInstance) apply(
Status: state.Status,
Value: change.After,
}
return newState, diags, applyError
return newState, diags, nil
}
resp := provider.ApplyResourceChange(providers.ApplyResourceChangeRequest{
@ -1955,7 +1954,7 @@ func (n *NodeAbstractResourceInstance) apply(
// Bail early in this particular case, because an object that doesn't
// conform to the schema can't be saved in the state anyway -- the
// serializer will reject it.
return nil, diags, applyError
return nil, diags, nil
}
// After this point we have a type-conforming result object and so we

View File

@ -264,8 +264,7 @@ func (n *NodeApplyableResourceInstance) managedResourceExecute(ctx EvalContext)
return diags
}
var applyError error
state, applyDiags, applyError := n.apply(ctx, state, diffApply, n.Config, n.CreateBeforeDestroy(), applyError)
state, applyDiags, applyError := n.apply(ctx, state, diffApply, n.Config, n.CreateBeforeDestroy())
diags = diags.Append(applyDiags)
if diags.HasErrors() {
return diags

View File

@ -4,6 +4,7 @@ import (
"fmt"
"log"
multierror "github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform/plans"
"github.com/hashicorp/terraform/tfdiags"
@ -194,12 +195,17 @@ func (n *NodeDestroyResourceInstance) Execute(ctx EvalContext, op walkOperation)
// are only removed from state.
if addr.Resource.Resource.Mode == addrs.ManagedResourceMode {
var applyDiags tfdiags.Diagnostics
var applyErr error
// we pass a nil configuration to apply because we are destroying
state, applyDiags, provisionerErr = n.apply(ctx, state, changeApply, nil, false, provisionerErr)
state, applyDiags, applyErr = n.apply(ctx, state, changeApply, nil, false)
diags.Append(applyDiags)
if diags.HasErrors() {
return diags
}
// if we got an apply error, combine it with the provisioner error
provisionerErr = multierror.Append(provisionerErr, applyErr)
diags = diags.Append(n.writeResourceInstanceState(ctx, state, n.Dependencies, workingState))
if diags.HasErrors() {
return diags

View File

@ -152,7 +152,6 @@ func (n *NodeDestroyDeposedResourceInstanceObject) ModifyCreateBeforeDestroy(v b
// GraphNodeExecutable impl.
func (n *NodeDestroyDeposedResourceInstanceObject) Execute(ctx EvalContext, op walkOperation) (diags tfdiags.Diagnostics) {
var change *plans.ResourceInstanceChange
var applyError error
// Read the state for the deposed resource instance
state, err := n.readResourceInstanceStateDeposed(ctx, n.Addr, n.DeposedKey)
@ -174,7 +173,7 @@ func (n *NodeDestroyDeposedResourceInstanceObject) Execute(ctx EvalContext, op w
}
// we pass a nil configuration to apply because we are destroying
state, applyDiags, applyError := n.apply(ctx, state, change, nil, false, applyError)
state, applyDiags, applyError := n.apply(ctx, state, change, nil, false)
diags = diags.Append(applyDiags)
if diags.HasErrors() {
return diags