diff --git a/internal/terraform/eval_context.go b/internal/terraform/eval_context.go index b78fec4c0e..e88e24f2c0 100644 --- a/internal/terraform/eval_context.go +++ b/internal/terraform/eval_context.go @@ -4,6 +4,8 @@ package terraform import ( + "context" + "github.com/hashicorp/hcl/v2" "github.com/zclconf/go-cty/cty" @@ -28,9 +30,9 @@ import ( // EvalContext is the interface that is given to eval nodes to execute. type EvalContext interface { - // Stopped returns a channel that is closed when evaluation is stopped - // via Terraform.Context.Stop() - Stopped() <-chan struct{} + // Stopped returns a context that is canceled when evaluation is stopped via + // Terraform.Context.Stop() + StopCtx() context.Context // Path is the current module path. Path() addrs.ModuleInstance diff --git a/internal/terraform/eval_context_builtin.go b/internal/terraform/eval_context_builtin.go index bad4a5c7df..2376d32961 100644 --- a/internal/terraform/eval_context_builtin.go +++ b/internal/terraform/eval_context_builtin.go @@ -102,13 +102,13 @@ func (ctx *BuiltinEvalContext) withScope(scope evalContextScope) EvalContext { return &newCtx } -func (ctx *BuiltinEvalContext) Stopped() <-chan struct{} { +func (ctx *BuiltinEvalContext) StopCtx() context.Context { // This can happen during tests. During tests, we just block forever. if ctx.StopContext == nil { - return nil + return context.TODO() } - return ctx.StopContext.Done() + return ctx.StopContext } func (ctx *BuiltinEvalContext) Hook(fn func(Hook) (HookAction, error)) error { diff --git a/internal/terraform/eval_context_mock.go b/internal/terraform/eval_context_mock.go index 48015b729d..236d7260cc 100644 --- a/internal/terraform/eval_context_mock.go +++ b/internal/terraform/eval_context_mock.go @@ -4,6 +4,8 @@ package terraform import ( + "context" + "github.com/hashicorp/hcl/v2" "github.com/hashicorp/hcl/v2/hcldec" "github.com/zclconf/go-cty/cty" @@ -31,8 +33,8 @@ import ( // MockEvalContext is a mock version of EvalContext that can be used // for tests. type MockEvalContext struct { - StoppedCalled bool - StoppedValue <-chan struct{} + StopCtxCalled bool + StopCtxValue context.Context HookCalled bool HookHook Hook @@ -164,9 +166,9 @@ type MockEvalContext struct { // MockEvalContext implements EvalContext var _ EvalContext = (*MockEvalContext)(nil) -func (c *MockEvalContext) Stopped() <-chan struct{} { - c.StoppedCalled = true - return c.StoppedValue +func (c *MockEvalContext) StopCtx() context.Context { + c.StopCtxCalled = true + return c.StopCtxValue } func (c *MockEvalContext) Hook(fn func(Hook) (HookAction, error)) error {