tofu: Context.Apply now takes a context.Context

This continues our ongoing effort to get a coherent chain of
context.Context all the way from "package main" to all of our calls to
external components.

Context.Apply does not yet do anything with its new context, but this gets
the context plumbed in enough that we should be able to pass values like
telemetry spans all the way from the top-level in future.

OpenTofu has some historical situational private uses of context.Context
to handle the graceful shutdown behaviors. Those use context.Context as
a private implementation detail rather than public API, and so this commit
leaves them as-is and adds a new "primary context" alongside. Hopefully
in future refactoring we can simplify this to use the primary context also
as the primary cancellation signal, but that's too risky a change to bundle
in with this otherwise-mostly-harmless context plumbing.

All of the _test.go file updates here are purely mechanical additions of
the extra argument. No test is materially modified by this change, which
is intentional to get some assurance that isn't a breaking change.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
This commit is contained in:
Martin Atkins 2024-11-12 15:27:55 -08:00
parent 3d5039f1f3
commit 1134f19467
9 changed files with 334 additions and 333 deletions

View File

@ -270,7 +270,7 @@ func (b *Local) opApply(
defer panicHandler()
defer close(doneCh)
log.Printf("[INFO] backend/local: apply calling Apply")
applyState, applyDiags = lr.Core.Apply(plan, lr.Config)
applyState, applyDiags = lr.Core.Apply(ctx, plan, lr.Config)
}()
if b.opWait(doneCh, stopCtx, cancelCtx, lr.Core, opState, op.View) {

View File

@ -605,7 +605,7 @@ func (runner *TestFileRunner) ExecuteTestRun(ctx context.Context, run *moduletes
}
run.Diagnostics = filteredDiags
applyCtx, updated, applyDiags := runner.apply(plan, state, config, run, file)
applyCtx, updated, applyDiags := runner.apply(ctx, plan, state, config, run, file)
// Remove expected diagnostics, and add diagnostics in case anything that should have failed didn't.
applyDiags = run.ValidateExpectedFailures(expectedFailures, sourceRanges, applyDiags)
@ -748,7 +748,7 @@ func (runner *TestFileRunner) destroy(ctx context.Context, config *configs.Confi
return state, diags
}
_, updated, applyDiags := runner.apply(plan, state, config, run, file)
_, updated, applyDiags := runner.apply(ctx, plan, state, config, run, file)
diags = diags.Append(applyDiags)
return updated, diags
}
@ -824,7 +824,7 @@ func (runner *TestFileRunner) plan(ctx context.Context, config *configs.Config,
return tfCtx, plan, diags
}
func (runner *TestFileRunner) apply(plan *plans.Plan, state *states.State, config *configs.Config, run *moduletest.Run, file *moduletest.File) (*tofu.Context, *states.State, tfdiags.Diagnostics) {
func (runner *TestFileRunner) apply(ctx context.Context, plan *plans.Plan, state *states.State, config *configs.Config, run *moduletest.Run, file *moduletest.File) (*tofu.Context, *states.State, tfdiags.Diagnostics) {
log.Printf("[TRACE] TestFileRunner: called apply for %s/%s", file.Name, run.Name)
var diags tfdiags.Diagnostics
@ -854,7 +854,7 @@ func (runner *TestFileRunner) apply(plan *plans.Plan, state *states.State, confi
return nil, state, diags
}
runningCtx, done := context.WithCancel(context.Background())
runningCtx, done := context.WithCancel(context.WithoutCancel(ctx))
var updated *states.State
var applyDiags tfdiags.Diagnostics
@ -864,7 +864,7 @@ func (runner *TestFileRunner) apply(plan *plans.Plan, state *states.State, confi
defer panicHandler()
defer done()
log.Printf("[DEBUG] TestFileRunner: starting apply for %s/%s", file.Name, run.Name)
updated, applyDiags = tfCtx.Apply(plan, config)
updated, applyDiags = tfCtx.Apply(ctx, plan, config)
log.Printf("[DEBUG] TestFileRunner: completed apply for %s/%s", file.Name, run.Name)
}()
waitDiags, cancelled := runner.wait(tfCtx, runningCtx, run, file, created)

View File

@ -6,6 +6,7 @@
package tofu
import (
"context"
"fmt"
"log"
@ -26,7 +27,7 @@ import (
//
// Even if the returned diagnostics contains errors, Apply always returns the
// resulting state which is likely to have been partially-updated.
func (c *Context) Apply(plan *plans.Plan, config *configs.Config) (*states.State, tfdiags.Diagnostics) {
func (c *Context) Apply(ctx context.Context, plan *plans.Plan, config *configs.Config) (*states.State, tfdiags.Diagnostics) {
defer c.acquireRun("apply")()
log.Printf("[DEBUG] Building and walking apply graph for %s plan", plan.UIMode)

View File

@ -79,7 +79,7 @@ func TestContext2Apply_createBeforeDestroy_deposedKeyPreApply(t *testing.T) {
t.Logf(legacyDiffComparisonString(plan.Changes))
}
_, diags = ctx.Apply(plan, m)
_, diags = ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
@ -171,7 +171,7 @@ output "data" {
t.Fatal(diags.Err())
}
_, diags = ctx.Apply(plan, m)
_, diags = ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatal(diags.Err())
}
@ -194,7 +194,7 @@ output "data" {
return resp
}
_, diags = ctx.Apply(plan, m)
_, diags = ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatal(diags.Err())
}
@ -256,7 +256,7 @@ resource "test_instance" "a" {
plan, diags := ctx.Plan(context.Background(), m, state, DefaultPlanOpts)
assertNoErrors(t, diags)
_, diags = ctx.Apply(plan, m)
_, diags = ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatal(diags.Err())
}
@ -368,7 +368,7 @@ resource "aws_instance" "bin" {
t.Fatalf("baz should depend on bam after refresh, but got %s", baz.Current.Dependencies)
}
state, diags = ctx.Apply(plan, m)
state, diags = ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatal(diags.Err())
}
@ -452,7 +452,7 @@ resource "test_resource" "b" {
plan, diags := ctx.Plan(context.Background(), m, state, SimplePlanOpts(plans.NormalMode, testInputValuesUnset(m.Module.Variables)))
assertNoErrors(t, diags)
_, diags = ctx.Apply(plan, m)
_, diags = ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatal(diags.ErrWithWarnings())
}
@ -493,7 +493,7 @@ output "out" {
plan, diags := ctx.Plan(context.Background(), m, states.NewState(), DefaultPlanOpts)
assertNoErrors(t, diags)
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatal(diags.ErrWithWarnings())
}
@ -556,7 +556,7 @@ resource "test_object" "y" {
plan, diags := ctx.Plan(context.Background(), m, states.NewState(), SimplePlanOpts(plans.NormalMode, testInputValuesUnset(m.Module.Variables)))
assertNoErrors(t, diags)
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
// FINAL PLAN:
@ -614,7 +614,7 @@ resource "test_object" "x" {
t.Fatalf("plan: %s", diags.Err())
}
_, diags = ctx.Apply(plan, m)
_, diags = ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("apply: %s", diags.Err())
}
@ -629,7 +629,7 @@ func TestContext2Apply_nullableVariables(t *testing.T) {
if diags.HasErrors() {
t.Fatalf("plan: %s", diags.Err())
}
state, diags = ctx.Apply(plan, m)
state, diags = ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("apply: %s", diags.Err())
}
@ -692,7 +692,7 @@ resource "test_object" "s" {
plan, diags := ctx.Plan(context.Background(), m, states.NewState(), DefaultPlanOpts)
assertNoErrors(t, diags)
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
// destroy only a single instance not included in the moved statements
@ -742,7 +742,7 @@ resource "test_object" "s" {
plan, diags := ctx.Plan(context.Background(), m, states.NewState(), DefaultPlanOpts)
assertNoErrors(t, diags)
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
// destroy excluding the module in the moved statements
@ -807,7 +807,7 @@ resource "test_object" "b" {
testObjA := plan.PriorState.Modules[""].Resources["test_object.a"].Instances[addrs.NoKey].Current
testObjA.Dependencies = append(testObjA.Dependencies, mustResourceInstanceAddr("test_object.b").ContainingResource().Config())
_, diags = ctx.Apply(plan, m)
_, diags = ctx.Apply(context.Background(), plan, m)
if !diags.HasErrors() {
t.Fatal("expected cycle error from apply")
}
@ -893,7 +893,7 @@ resource "test_resource" "c" {
resp.NewState = cty.ObjectVal(m)
return resp
}
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
wantResourceAttrs := map[string]struct{ value, output string }{
@ -949,7 +949,7 @@ resource "test_resource" "c" {
resp.NewState = cty.ObjectVal(m)
return resp
}
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
if !diags.HasErrors() {
t.Fatal("succeeded; want errors")
}
@ -1054,7 +1054,7 @@ func TestContext2Apply_outputValuePrecondition(t *testing.T) {
}
}
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
assertNoDiagnostics(t, diags)
for _, addr := range checkableObjects {
result := state.CheckResults.GetObjectResult(addr)
@ -1207,7 +1207,7 @@ func TestContext2Apply_resourceConditionApplyTimeFail(t *testing.T) {
t.Fatalf("incorrect initial plan for instance B\nwant a 'create' change\ngot: %s", spew.Sdump(planB))
}
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
stateA := state.ResourceInstance(instA)
@ -1244,7 +1244,7 @@ func TestContext2Apply_resourceConditionApplyTimeFail(t *testing.T) {
t.Fatalf("incorrect initial plan for instance B\nwant a 'no-op' change\ngot: %s", spew.Sdump(planB))
}
_, diags = ctx.Apply(plan, m)
_, diags = ctx.Apply(context.Background(), plan, m)
if !diags.HasErrors() {
t.Fatal("final apply succeeded, but should've failed with a postcondition error")
}
@ -1382,7 +1382,7 @@ output "out" {
plan, diags := ctx.Plan(context.Background(), m, states.NewState(), opts)
assertNoErrors(t, diags)
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
// Resource changes which have dependencies across providers which
@ -1507,7 +1507,7 @@ resource "test_object" "x" {
t.Fatalf("plan: %s", diags.Err())
}
_, diags = ctx.Apply(plan, m)
_, diags = ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("apply: %s", diags.Err())
}
@ -1553,7 +1553,7 @@ resource "test_object" "y" {
plan, diags := ctx.Plan(context.Background(), m, state, opts)
assertNoErrors(t, diags)
_, diags = ctx.Apply(plan, m)
_, diags = ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
}
@ -1635,7 +1635,7 @@ output "data" {
plan, diags := ctx.Plan(context.Background(), m, states.NewState(), opts)
assertNoErrors(t, diags)
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
// and destroy
@ -1643,7 +1643,7 @@ output "data" {
plan, diags = ctx.Plan(context.Background(), m, state, opts)
assertNoErrors(t, diags)
state, diags = ctx.Apply(plan, m)
state, diags = ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
// and destroy again with no state
@ -1655,7 +1655,7 @@ output "data" {
plan, diags = ctx.Plan(context.Background(), m, state, opts)
assertNoErrors(t, diags)
_, diags = ctx.Apply(plan, m)
_, diags = ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
}
@ -1710,7 +1710,7 @@ output "from_resource" {
plan, diags := ctx.Plan(context.Background(), m, state, opts)
assertNoErrors(t, diags)
_, diags = ctx.Apply(plan, m)
_, diags = ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
}
@ -1767,7 +1767,7 @@ output "from_resource" {
plan, diags := ctx.Plan(context.Background(), m, state, opts)
assertNoErrors(t, diags)
state, diags = ctx.Apply(plan, m)
state, diags = ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
resCheck := state.CheckResults.GetObjectResult(mustResourceInstanceAddr("test_object.x"))
@ -1855,7 +1855,7 @@ resource "test_object" "y" {
return resp
}
_, diags = ctx.Apply(plan, m)
_, diags = ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
}
@ -1903,7 +1903,7 @@ output "a" {
Mode: plans.NormalMode,
})
assertNoErrors(t, diags)
_, diags = ctx.Apply(plan, m)
_, diags = ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
}
@ -1950,7 +1950,7 @@ output "null_module_test" {
Mode: plans.NormalMode,
})
assertNoErrors(t, diags)
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
// now destroy
@ -1958,7 +1958,7 @@ output "null_module_test" {
Mode: plans.DestroyMode,
})
assertNoErrors(t, diags)
_, diags = ctx.Apply(plan, m)
_, diags = ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
}
@ -2025,7 +2025,7 @@ output "resources" {
Mode: plans.NormalMode,
})
assertNoErrors(t, diags)
_, diags = ctx.Apply(plan, m)
_, diags = ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
}
@ -2113,7 +2113,7 @@ resource "test_resource" "b" {
})
assertNoErrors(t, diags)
_, diags = ctx.Apply(plan, m)
_, diags = ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
}
@ -2156,7 +2156,7 @@ resource "unused_resource" "test" {
Mode: plans.DestroyMode,
})
assertNoErrors(t, diags)
_, diags = ctx.Apply(plan, m)
_, diags = ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
}
@ -2216,7 +2216,7 @@ import {
})
assertNoErrors(t, diags)
_, diags = ctx.Apply(plan, m)
_, diags = ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
if !hook.PreApplyImportCalled {
@ -2259,7 +2259,7 @@ locals {
t.Errorf("expected no errors, but got %s", diags)
}
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Errorf("expected no errors, but got %s", diags)
}
@ -2302,7 +2302,7 @@ locals {
t.Errorf("expected no errors, but got %s", diags)
}
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Errorf("expected no errors, but got %s", diags)
}
@ -2361,7 +2361,7 @@ func TestContext2Apply_forgetOrphanAndDeposed(t *testing.T) {
plan, diags := ctx.Plan(context.Background(), m, state, DefaultPlanOpts)
assertNoErrors(t, diags)
s, diags := ctx.Apply(plan, m)
s, diags := ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
@ -2555,7 +2555,7 @@ func TestContext2Apply_providerExpandWithTargetOrExclude(t *testing.T) {
plan, diags := ctx.Plan(context.Background(), m, state, normalPlanOpts)
assertNoErrors(t, diags)
newState, diags := ctx.Apply(plan, m)
newState, diags := ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
assertResourceInstanceProviderInstance(
@ -2623,7 +2623,7 @@ func TestContext2Apply_providerExpandWithTargetOrExclude(t *testing.T) {
plan, diags := ctx.Plan(context.Background(), m, state, makeStep2PlanOpts(plans.NormalMode))
assertNoErrors(t, diags)
newState, diags := ctx.Apply(plan, m)
newState, diags := ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
// Because makeStep2PlanOpts told us to retain at least one
@ -2696,7 +2696,7 @@ func TestContext2Apply_providerExpandWithTargetOrExclude(t *testing.T) {
plan, diags := ctx.Plan(context.Background(), m, state, normalPlanOpts)
assertNoErrors(t, diags)
newState, diags := ctx.Apply(plan, m)
newState, diags := ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
// The whole resource state for mock.first should've been removed now.
@ -2773,7 +2773,7 @@ func TestContext2Apply_moduleProviderAliasExcludes(t *testing.T) {
})
assertNoErrors(t, diags)
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
@ -2813,7 +2813,7 @@ func TestContext2Apply_moduleProviderAliasExcludesNonExistent(t *testing.T) {
})
assertNoErrors(t, diags)
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
@ -2846,7 +2846,7 @@ func TestContext2Apply_moduleExclude(t *testing.T) {
})
assertNoErrors(t, diags)
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
@ -2882,7 +2882,7 @@ func TestContext2Apply_moduleExcludeDependent(t *testing.T) {
})
assertNoErrors(t, diags)
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
@ -2913,7 +2913,7 @@ func TestContext2Apply_moduleExcludeNonExistent(t *testing.T) {
})
assertNoErrors(t, diags)
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
@ -2960,7 +2960,7 @@ func TestContext2Apply_destroyExcludedNonExistentWithModuleVariableAndCount(t *t
plan, diags := ctx.Plan(context.Background(), m, states.NewState(), DefaultPlanOpts)
assertNoErrors(t, diags)
state, diags = ctx.Apply(plan, m)
state, diags = ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("apply err: %s", diags.Err())
}
@ -2994,7 +2994,7 @@ func TestContext2Apply_destroyExcludedNonExistentWithModuleVariableAndCount(t *t
}
// Destroy, excluding the module explicitly
state, diags = ctx.Apply(plan, m)
state, diags = ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("destroy apply err: %s", diags)
}
@ -3049,7 +3049,7 @@ func TestContext2Apply_destroyExcludedWithModuleVariableAndCount(t *testing.T) {
plan, diags := ctx.Plan(context.Background(), m, states.NewState(), DefaultPlanOpts)
assertNoErrors(t, diags)
state, diags = ctx.Apply(plan, m)
state, diags = ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("apply err: %s", diags.Err())
}
@ -3083,7 +3083,7 @@ func TestContext2Apply_destroyExcludedWithModuleVariableAndCount(t *testing.T) {
}
// Destroy, excluding the module explicitly
state, diags = ctx.Apply(plan, m)
state, diags = ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("destroy apply err: %s", diags)
}
@ -3127,7 +3127,7 @@ func TestContext2Apply_excluded(t *testing.T) {
})
assertNoErrors(t, diags)
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
@ -3167,7 +3167,7 @@ func TestContext2Apply_excludedCount(t *testing.T) {
})
assertNoErrors(t, diags)
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
@ -3209,7 +3209,7 @@ func TestContext2Apply_excludedCountIndex(t *testing.T) {
})
assertNoErrors(t, diags)
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
@ -3259,7 +3259,7 @@ func TestContext2Apply_excludedDestroy(t *testing.T) {
plan, diags := ctx.Plan(context.Background(), m, states.NewState(), DefaultPlanOpts)
assertNoErrors(t, diags)
state, diags = ctx.Apply(plan, m)
state, diags = ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("apply err: %s", diags.Err())
}
@ -3282,7 +3282,7 @@ func TestContext2Apply_excludedDestroy(t *testing.T) {
})
assertNoErrors(t, diags)
state, diags = ctx.Apply(plan, m)
state, diags = ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
@ -3323,7 +3323,7 @@ func TestContext2Apply_excludedDestroyDependent(t *testing.T) {
plan, diags := ctx.Plan(context.Background(), m, states.NewState(), DefaultPlanOpts)
assertNoErrors(t, diags)
state, diags = ctx.Apply(plan, m)
state, diags = ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("apply err: %s", diags.Err())
}
@ -3344,7 +3344,7 @@ func TestContext2Apply_excludedDestroyDependent(t *testing.T) {
})
assertNoErrors(t, diags)
state, diags = ctx.Apply(plan, m)
state, diags = ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
@ -3434,7 +3434,7 @@ func TestContext2Apply_excludedDestroyCountDeps(t *testing.T) {
})
assertNoErrors(t, diags)
state, diags = ctx.Apply(plan, m)
state, diags = ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
@ -3512,7 +3512,7 @@ func TestContext2Apply_excludedDependentDestroyCountDeps(t *testing.T) {
})
assertNoErrors(t, diags)
state, diags = ctx.Apply(plan, m)
state, diags = ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
@ -3596,7 +3596,7 @@ func TestContext2Apply_excludedDestroyModule(t *testing.T) {
})
assertNoErrors(t, diags)
state, diags = ctx.Apply(plan, m)
state, diags = ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
@ -3681,7 +3681,7 @@ func TestContext2Apply_excludedDestroyCountIndex(t *testing.T) {
})
assertNoErrors(t, diags)
state, diags = ctx.Apply(plan, m)
state, diags = ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
@ -3715,7 +3715,7 @@ func TestContext2Apply_excludedModule(t *testing.T) {
})
assertNoErrors(t, diags)
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
@ -3764,7 +3764,7 @@ func TestContext2Apply_excludedModuleResourceDep(t *testing.T) {
t.Logf("Diff: %s", legacyDiffComparisonString(plan.Changes))
}
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
@ -3797,7 +3797,7 @@ func TestContext2Apply_excludedResourceDependentOnModule(t *testing.T) {
t.Logf("Diff: %s", legacyDiffComparisonString(plan.Changes))
}
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
@ -3835,7 +3835,7 @@ func TestContext2Apply_excludedModuleDep(t *testing.T) {
t.Logf("Diff: %s", legacyDiffComparisonString(plan.Changes))
}
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
@ -3868,7 +3868,7 @@ func TestContext2Apply_excludedModuleUnrelatedOutputs(t *testing.T) {
})
assertNoErrors(t, diags)
s, diags := ctx.Apply(plan, m)
s, diags := ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
@ -3916,7 +3916,7 @@ func TestContext2Apply_excludedModuleResource(t *testing.T) {
})
assertNoErrors(t, diags)
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
@ -3976,7 +3976,7 @@ func TestContext2Apply_excludedResourceOrphanModule(t *testing.T) {
})
assertNoErrors(t, diags)
state, diags = ctx.Apply(plan, m)
state, diags = ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("apply errors: %s", diags.Err())
}
@ -4027,7 +4027,7 @@ func TestContext2Apply_excludedOrphanModule(t *testing.T) {
})
assertNoErrors(t, diags)
state, diags = ctx.Apply(plan, m)
state, diags = ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("apply errors: %s", diags.Err())
}
@ -4097,7 +4097,7 @@ func TestContext2Apply_excludedWithTaintedInState(t *testing.T) {
t.Fatalf("err: %s", diags.Err())
}
s, diags := ctx.Apply(plan, m)
s, diags := ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("err: %s", diags.Err())
}
@ -4136,7 +4136,7 @@ func TestContext2Apply_excludedModuleRecursive(t *testing.T) {
})
assertNoErrors(t, diags)
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatalf("err: %s", diags.Err())
}
@ -4224,7 +4224,7 @@ resource "test_instance" "a" {
t.Fatal(diags.Err())
}
newState, diags := ctx.Apply(plan, m)
newState, diags := ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatal(diags.Err())
}
@ -4243,7 +4243,7 @@ resource "test_instance" "a" {
t.Fatal(diags.Err())
}
newState, diags := ctx.Apply(plan, m)
newState, diags := ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatal(diags.Err())
}
@ -4377,7 +4377,7 @@ resource "test_instance" "a" {
t.Fatal(diags.Err())
}
newState, diags := ctx.Apply(plan, m)
newState, diags := ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatal(diags.Err())
}
@ -4396,7 +4396,7 @@ resource "test_instance" "a" {
t.Fatal(diags.Err())
}
newState, diags := ctx.Apply(plan, m)
newState, diags := ctx.Apply(context.Background(), plan, m)
if diags.HasErrors() {
t.Fatal(diags.Err())
}

View File

@ -738,7 +738,7 @@ check "error" {
test.providerHook(test.provider)
}
state, diags := ctx.Apply(plan, configs)
state, diags := ctx.Apply(context.Background(), plan, configs)
if validateCheckDiagnostics(t, "apply", test.applyWarning, test.applyError, diags) {
return
}

File diff suppressed because it is too large Load Diff

View File

@ -79,7 +79,7 @@ func TestContext2Input_provider(t *testing.T) {
plan, diags := ctx.Plan(context.Background(), m, states.NewState(), DefaultPlanOpts)
assertNoErrors(t, diags)
if _, diags := ctx.Apply(plan, m); diags.HasErrors() {
if _, diags := ctx.Apply(context.Background(), plan, m); diags.HasErrors() {
t.Fatalf("apply errors: %s", diags.Err())
}
@ -162,7 +162,7 @@ func TestContext2Input_providerMulti(t *testing.T) {
return p, nil
}
if _, diags := ctx.Apply(plan, m); diags.HasErrors() {
if _, diags := ctx.Apply(context.Background(), plan, m); diags.HasErrors() {
t.Fatalf("apply errors: %s", diags.Err())
}
@ -238,7 +238,7 @@ func TestContext2Input_providerId(t *testing.T) {
plan, diags := ctx.Plan(context.Background(), m, states.NewState(), DefaultPlanOpts)
assertNoErrors(t, diags)
if _, diags := ctx.Apply(plan, m); diags.HasErrors() {
if _, diags := ctx.Apply(context.Background(), plan, m); diags.HasErrors() {
t.Fatalf("apply errors: %s", diags.Err())
}
@ -312,7 +312,7 @@ func TestContext2Input_providerOnly(t *testing.T) {
})
assertNoErrors(t, diags)
state, err := ctx.Apply(plan, m)
state, err := ctx.Apply(context.Background(), plan, m)
if err != nil {
t.Fatalf("err: %s", err)
}
@ -363,7 +363,7 @@ func TestContext2Input_providerVars(t *testing.T) {
})
assertNoErrors(t, diags)
if _, diags := ctx.Apply(plan, m); diags.HasErrors() {
if _, diags := ctx.Apply(context.Background(), plan, m); diags.HasErrors() {
t.Fatalf("apply errors: %s", diags.Err())
}

View File

@ -717,7 +717,7 @@ data "test_data_source" "a" {
// This is primarily a plan-time test, since the special handling of
// data resources is a plan-time concern, but we'll still try applying the
// plan here just to make sure it's valid.
newState, diags := ctx.Apply(plan, m)
newState, diags := ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
if rs := newState.ResourceInstance(dataAddr); rs != nil {
@ -4243,7 +4243,7 @@ resource "test_object" "b" {
opts := SimplePlanOpts(plans.NormalMode, testInputValuesUnset(m.Module.Variables))
plan, diags := ctx.Plan(context.Background(), m, states.NewState(), opts)
assertNoErrors(t, diags)
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
assertNoErrors(t, diags)
// Resource changes which have dependencies across providers which

View File

@ -242,7 +242,7 @@ func TestNodeModuleVariableConstraints(t *testing.T) {
}
}
state, diags := ctx.Apply(plan, m)
state, diags := ctx.Apply(context.Background(), plan, m)
assertNoDiagnostics(t, diags)
for _, addr := range checkableObjects {
result := state.CheckResults.GetObjectResult(addr)
@ -265,7 +265,7 @@ func TestNodeModuleVariableConstraints(t *testing.T) {
})
assertNoDiagnostics(t, diags)
state, diags = ctx.Apply(plan, m)
state, diags = ctx.Apply(context.Background(), plan, m)
assertNoDiagnostics(t, diags)
for _, addr := range checkableObjects {
result := state.CheckResults.GetObjectResult(addr)