diff --git a/internal/terraform/context_apply2_test.go b/internal/terraform/context_apply2_test.go index afbe9db044..119c4658c2 100644 --- a/internal/terraform/context_apply2_test.go +++ b/internal/terraform/context_apply2_test.go @@ -1042,11 +1042,38 @@ output "out" { state, diags := ctx.Apply(plan, m) assertNoErrors(t, diags) - // TODO: extend this to ensure the otherProvider is always properly - // configured during the destroy plan + otherProvider.ConfigureProviderCalled = false + otherProvider.ConfigureProviderFn = func(req providers.ConfigureProviderRequest) (resp providers.ConfigureProviderResponse) { + // check that our config is complete, even during a destroy plan + expected := cty.ObjectVal(map[string]cty.Value{ + "local": cty.ListVal([]cty.Value{cty.StringVal("first-ok"), cty.StringVal("second-ok")}), + "output": cty.ListVal([]cty.Value{cty.StringVal("first-ok"), cty.StringVal("second-ok")}), + "var": cty.MapVal(map[string]cty.Value{ + "a": cty.StringVal("first"), + "b": cty.StringVal("second"), + }), + }) + + if !req.Config.RawEquals(expected) { + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf( + `incorrect provider config: +expected: %#v +got: %#v`, + expected, req.Config)) + } + + return resp + } opts.Mode = plans.DestroyMode + // skip refresh so that we don't configure the provider before the destroy plan + opts.SkipRefresh = true + // destroy only a single instance not included in the moved statements _, diags = ctx.Plan(m, state, opts) assertNoErrors(t, diags) + + if !otherProvider.ConfigureProviderCalled { + t.Fatal("failed to configure provider during destroy plan") + } } diff --git a/internal/terraform/node_provider.go b/internal/terraform/node_provider.go index 2e611d5660..c5b09136cb 100644 --- a/internal/terraform/node_provider.go +++ b/internal/terraform/node_provider.go @@ -37,10 +37,7 @@ func (n *NodeApplyableProvider) Execute(ctx EvalContext, op walkOperation) (diag case walkValidate: log.Printf("[TRACE] NodeApplyableProvider: validating configuration for %s", n.Addr) return diags.Append(n.ValidateProvider(ctx, provider)) - case walkPlan, walkApply, walkDestroy: - // walkPlanDestroy is purposely skipped here, since the config is not - // evaluated, and the provider is not needed to create delete actions - // for all instances. + case walkPlan, walkPlanDestroy, walkApply, walkDestroy: log.Printf("[TRACE] NodeApplyableProvider: configuring %s", n.Addr) return diags.Append(n.ConfigureProvider(ctx, provider, false)) case walkImport: