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:
parent
842c5b4136
commit
1707685350
|
@ -12553,15 +12553,15 @@ func TestContext2Apply_errorRestoreStatus(t *testing.T) {
|
||||||
|
|
||||||
state, diags = ctx.Apply()
|
state, diags = ctx.Apply()
|
||||||
|
|
||||||
if len(diags) != 2 {
|
|
||||||
t.Fatal("expected 1 error and 1 warning")
|
|
||||||
}
|
|
||||||
|
|
||||||
errString := diags.ErrWithWarnings().Error()
|
errString := diags.ErrWithWarnings().Error()
|
||||||
if !strings.Contains(errString, "oops") || !strings.Contains(errString, "warned") {
|
if !strings.Contains(errString, "oops") || !strings.Contains(errString, "warned") {
|
||||||
t.Fatalf("error missing expected info: %q", errString)
|
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)
|
res := state.ResourceInstance(addr)
|
||||||
if res == nil {
|
if res == nil {
|
||||||
t.Fatal("resource was removed from state")
|
t.Fatal("resource was removed from state")
|
||||||
|
|
|
@ -1814,8 +1814,7 @@ func (n *NodeAbstractResourceInstance) apply(
|
||||||
state *states.ResourceInstanceObject,
|
state *states.ResourceInstanceObject,
|
||||||
change *plans.ResourceInstanceChange,
|
change *plans.ResourceInstanceChange,
|
||||||
applyConfig *configs.Resource,
|
applyConfig *configs.Resource,
|
||||||
createBeforeDestroy bool,
|
createBeforeDestroy bool) (*states.ResourceInstanceObject, tfdiags.Diagnostics, error) {
|
||||||
applyError error) (*states.ResourceInstanceObject, tfdiags.Diagnostics, error) {
|
|
||||||
|
|
||||||
var diags tfdiags.Diagnostics
|
var diags tfdiags.Diagnostics
|
||||||
if state == nil {
|
if state == nil {
|
||||||
|
@ -1824,13 +1823,13 @@ func (n *NodeAbstractResourceInstance) apply(
|
||||||
|
|
||||||
provider, providerSchema, err := getProvider(ctx, n.ResolvedProvider)
|
provider, providerSchema, err := getProvider(ctx, n.ResolvedProvider)
|
||||||
if err != nil {
|
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)
|
schema, _ := providerSchema.SchemaForResourceType(n.Addr.Resource.Resource.Mode, n.Addr.Resource.Resource.Type)
|
||||||
if schema == nil {
|
if schema == nil {
|
||||||
// Should be caught during validation, so we don't bother with a pretty error here
|
// 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))
|
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)
|
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)
|
configVal, _, configDiags = ctx.EvaluateBlock(applyConfig.Config, schema, nil, keyData)
|
||||||
diags = diags.Append(configDiags)
|
diags = diags.Append(configDiags)
|
||||||
if configDiags.HasErrors() {
|
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!)",
|
"configuration for %s still contains unknown values during apply (this is a bug in Terraform; please report it!)",
|
||||||
n.Addr,
|
n.Addr,
|
||||||
))
|
))
|
||||||
return nil, diags, applyError
|
return nil, diags, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
metaConfigVal, metaDiags := n.providerMetas(ctx)
|
metaConfigVal, metaDiags := n.providerMetas(ctx)
|
||||||
diags = diags.Append(metaDiags)
|
diags = diags.Append(metaDiags)
|
||||||
if diags.HasErrors() {
|
if diags.HasErrors() {
|
||||||
return nil, diags, applyError
|
return nil, diags, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[DEBUG] %s: applying the planned %s change", n.Addr, change.Action)
|
log.Printf("[DEBUG] %s: applying the planned %s change", n.Addr, change.Action)
|
||||||
|
@ -1886,7 +1885,7 @@ func (n *NodeAbstractResourceInstance) apply(
|
||||||
Status: state.Status,
|
Status: state.Status,
|
||||||
Value: change.After,
|
Value: change.After,
|
||||||
}
|
}
|
||||||
return newState, diags, applyError
|
return newState, diags, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := provider.ApplyResourceChange(providers.ApplyResourceChangeRequest{
|
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
|
// 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
|
// conform to the schema can't be saved in the state anyway -- the
|
||||||
// serializer will reject it.
|
// 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
|
// After this point we have a type-conforming result object and so we
|
||||||
|
|
|
@ -264,8 +264,7 @@ func (n *NodeApplyableResourceInstance) managedResourceExecute(ctx EvalContext)
|
||||||
return diags
|
return diags
|
||||||
}
|
}
|
||||||
|
|
||||||
var applyError error
|
state, applyDiags, applyError := n.apply(ctx, state, diffApply, n.Config, n.CreateBeforeDestroy())
|
||||||
state, applyDiags, applyError := n.apply(ctx, state, diffApply, n.Config, n.CreateBeforeDestroy(), applyError)
|
|
||||||
diags = diags.Append(applyDiags)
|
diags = diags.Append(applyDiags)
|
||||||
if diags.HasErrors() {
|
if diags.HasErrors() {
|
||||||
return diags
|
return diags
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
multierror "github.com/hashicorp/go-multierror"
|
||||||
"github.com/hashicorp/terraform/plans"
|
"github.com/hashicorp/terraform/plans"
|
||||||
"github.com/hashicorp/terraform/tfdiags"
|
"github.com/hashicorp/terraform/tfdiags"
|
||||||
|
|
||||||
|
@ -194,12 +195,17 @@ func (n *NodeDestroyResourceInstance) Execute(ctx EvalContext, op walkOperation)
|
||||||
// are only removed from state.
|
// are only removed from state.
|
||||||
if addr.Resource.Resource.Mode == addrs.ManagedResourceMode {
|
if addr.Resource.Resource.Mode == addrs.ManagedResourceMode {
|
||||||
var applyDiags tfdiags.Diagnostics
|
var applyDiags tfdiags.Diagnostics
|
||||||
|
var applyErr error
|
||||||
// we pass a nil configuration to apply because we are destroying
|
// 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)
|
diags.Append(applyDiags)
|
||||||
if diags.HasErrors() {
|
if diags.HasErrors() {
|
||||||
return diags
|
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))
|
diags = diags.Append(n.writeResourceInstanceState(ctx, state, n.Dependencies, workingState))
|
||||||
if diags.HasErrors() {
|
if diags.HasErrors() {
|
||||||
return diags
|
return diags
|
||||||
|
|
|
@ -152,7 +152,6 @@ func (n *NodeDestroyDeposedResourceInstanceObject) ModifyCreateBeforeDestroy(v b
|
||||||
// GraphNodeExecutable impl.
|
// GraphNodeExecutable impl.
|
||||||
func (n *NodeDestroyDeposedResourceInstanceObject) Execute(ctx EvalContext, op walkOperation) (diags tfdiags.Diagnostics) {
|
func (n *NodeDestroyDeposedResourceInstanceObject) Execute(ctx EvalContext, op walkOperation) (diags tfdiags.Diagnostics) {
|
||||||
var change *plans.ResourceInstanceChange
|
var change *plans.ResourceInstanceChange
|
||||||
var applyError error
|
|
||||||
|
|
||||||
// Read the state for the deposed resource instance
|
// Read the state for the deposed resource instance
|
||||||
state, err := n.readResourceInstanceStateDeposed(ctx, n.Addr, n.DeposedKey)
|
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
|
// 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)
|
diags = diags.Append(applyDiags)
|
||||||
if diags.HasErrors() {
|
if diags.HasErrors() {
|
||||||
return diags
|
return diags
|
||||||
|
|
Loading…
Reference in New Issue