watch for cancellation in plan and refresh
Cancellation in the local backend was only implemented for apply.
This commit is contained in:
parent
90e986348a
commit
85295e5c23
|
@ -151,14 +151,6 @@ func (b *Local) opApply(
|
|||
_, applyErr = tfCtx.Apply()
|
||||
// we always want the state, even if apply failed
|
||||
applyState = tfCtx.State()
|
||||
|
||||
/*
|
||||
// Record any shadow errors for later
|
||||
if err := ctx.ShadowError(); err != nil {
|
||||
shadowErr = multierror.Append(shadowErr, multierror.Prefix(
|
||||
err, "apply operation:"))
|
||||
}
|
||||
*/
|
||||
}()
|
||||
|
||||
// Wait for the apply to finish or for us to be interrupted so
|
||||
|
|
|
@ -101,14 +101,34 @@ func (b *Local) opPlan(
|
|||
}
|
||||
}
|
||||
|
||||
// Perform the plan
|
||||
// Perform the plan in a goroutine so we can be interrupted
|
||||
var plan *terraform.Plan
|
||||
var planErr error
|
||||
doneCh := make(chan struct{})
|
||||
go func() {
|
||||
defer close(doneCh)
|
||||
log.Printf("[INFO] backend/local: plan calling Plan")
|
||||
plan, err := tfCtx.Plan()
|
||||
if err != nil {
|
||||
runningOp.Err = errwrap.Wrapf("Error running plan: {{err}}", err)
|
||||
return
|
||||
plan, planErr = tfCtx.Plan()
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
if b.CLI != nil {
|
||||
b.CLI.Output("stopping plan operation...")
|
||||
}
|
||||
|
||||
// Stop execution
|
||||
go tfCtx.Stop()
|
||||
|
||||
// Wait for completion still
|
||||
<-doneCh
|
||||
case <-doneCh:
|
||||
}
|
||||
|
||||
if planErr != nil {
|
||||
runningOp.Err = errwrap.Wrapf("Error running plan: {{err}}", planErr)
|
||||
return
|
||||
}
|
||||
// Record state
|
||||
runningOp.PlanEmpty = plan.Diff.Empty()
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package local
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
|
@ -12,6 +13,7 @@ import (
|
|||
"github.com/hashicorp/terraform/command/clistate"
|
||||
"github.com/hashicorp/terraform/config/module"
|
||||
"github.com/hashicorp/terraform/state"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
func (b *Local) opRefresh(
|
||||
|
@ -78,11 +80,34 @@ func (b *Local) opRefresh(
|
|||
}
|
||||
}
|
||||
|
||||
// Perform operation and write the resulting state to the running op
|
||||
newState, err := tfCtx.Refresh()
|
||||
// Perform the refresh in a goroutine so we can be interrupted
|
||||
var newState *terraform.State
|
||||
var refreshErr error
|
||||
doneCh := make(chan struct{})
|
||||
go func() {
|
||||
defer close(doneCh)
|
||||
newState, err = tfCtx.Refresh()
|
||||
log.Printf("[INFO] backend/local: plan calling Plan")
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
if b.CLI != nil {
|
||||
b.CLI.Output("stopping refresh operation...")
|
||||
}
|
||||
|
||||
// Stop execution
|
||||
go tfCtx.Stop()
|
||||
|
||||
// Wait for completion still
|
||||
<-doneCh
|
||||
case <-doneCh:
|
||||
}
|
||||
|
||||
// write the resulting state to the running op
|
||||
runningOp.State = newState
|
||||
if err != nil {
|
||||
runningOp.Err = errwrap.Wrapf("Error refreshing state: {{err}}", err)
|
||||
if refreshErr != nil {
|
||||
runningOp.Err = errwrap.Wrapf("Error refreshing state: {{err}}", refreshErr)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue