Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable habitat supervisor service before start #17225

Closed
wants to merge 57 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
19d8f53
`enable` habitat supervisor service before `start`
Jan 29, 2018
06365ef
deps: Bump AWS provider to support cn-northwest-1 state
bflad Jan 27, 2018
34905ca
always evaluate locals, even during destroy
jbardin Jan 29, 2018
23116dc
add destroy provisioner test with locals, outputs
jbardin Jan 29, 2018
3e578ed
always evaluate outputs too
jbardin Jan 29, 2018
78db5b9
website: even more community providers
cgriggs01 Jan 29, 2018
6767fc4
delete outputs during destroy
jbardin Jan 30, 2018
b24c28e
add a more complex locals test
jbardin Jan 30, 2018
add6f36
add PruneUnusedValuesTransformer
jbardin Jan 30, 2018
70a8bed
Workspaces are supported locally.
Jan 30, 2018
7ad5036
catch missing id attribute during interpolation
jbardin Jan 30, 2018
a4968a7
gofmt bug will be fixed in 1.10
jbardin Jan 30, 2018
9088739
deps: Remove unnecessary Joyent dependencies
jen20 Jan 31, 2018
901cd89
Website: Provider link (#17246)
cgriggs01 Jan 31, 2018
67dc5b7
Make sure outputs are removed when targeting
jbardin Jan 31, 2018
0b4f4ee
website: fix ordering of interpolation functions
blakestoddard Jan 31, 2018
f955ced
website: improve the Module Sources documentation
afeld Jan 31, 2018
abc7e04
v0.11.3
jbardin Jan 31, 2018
4ab0bbe
release: clean up after v0.11.3
jbardin Jan 31, 2018
498252d
slow down the plan shutdown tests for slow hosts
jbardin Jan 31, 2018
15c5b93
helper/schema: Prevent crash on removal of computed field in Customiz…
radeksimko Feb 1, 2018
788896d
Update CHANGELOG.md
radeksimko Feb 1, 2018
9182b51
Website Update provider name (#17270)
cgriggs01 Feb 2, 2018
ae308c3
deps: Bump terraform-provider-aws@v1.8.0 and aws-sdk-go@v1.12.70
bflad Feb 6, 2018
c803044
Website: Restructure Community providers list (#17286)
cgriggs01 Feb 6, 2018
a6e2387
website: private module registry documentation
nfagerlund Feb 7, 2018
8202c38
website: Clarify Registry examples behavior
justincampbell Feb 9, 2018
9febf73
terraform: use hashicorp/go-uuid for lineage generation
ryanuber Feb 9, 2018
01f5cce
Update cloud-index.html.markdown
kikitux Feb 12, 2018
bb8772a
always wait for a RunningOperation to return
jbardin Feb 9, 2018
4a3840f
move backend operation cancellation into meta
jbardin Feb 9, 2018
0653c72
ignore error in plan shutdown test
jbardin Feb 10, 2018
7767f36
coalesce the backened interrupt code
jbardin Feb 12, 2018
233dac3
website: document the naming conventions for outputs
Feb 13, 2018
ef693fe
website: fix incorrect anchor links for registry API pagination
outsideris Feb 13, 2018
bf6d4da
deps: Bump terraform-provider-aws@v1.9.0 and aws-sdk-go@v1.12.73
bflad Feb 13, 2018
068f50e
Update CHANGELOG for #17216
bflad Feb 13, 2018
f6a661b
Document aws_route53_record importable (#17306)
jmcarp Feb 13, 2018
9a421c5
[provisioner-habitat] Allow custom service name (#17196)
nsdavidson Feb 13, 2018
02a054b
[provisioner-habitat] Detect if hab user exists (#17195)
nsdavidson Feb 13, 2018
edaaba5
Update CHANGELOG.md
catsby Feb 13, 2018
3444ccf
docs/import: Remove out of date listing of importable resources and n…
bflad Feb 14, 2018
e67cf9e
add support for ssh host key checking
jbardin Feb 14, 2018
9bb5b53
update x/crypt/ssh and add knownhosts package
jbardin Feb 14, 2018
9a5650b
add test for host key validation
jbardin Feb 14, 2018
c4e5fb6
add tests for signed host certs
jbardin Feb 14, 2018
a1f472a
add host_key and bastion_host_key to the docs
jbardin Feb 14, 2018
12014e6
add the remote-exec retry function to communicator
jbardin Feb 14, 2018
d984abc
remove retryFunc
jbardin Feb 14, 2018
5a8adab
remove retryFunc
jbardin Feb 14, 2018
6d15887
remove retryFunc
jbardin Feb 14, 2018
5b15c4b
remove retryFunc
jbardin Feb 14, 2018
b476f08
Fix type assertion when loading stored error
jbardin Feb 15, 2018
d0e0528
have the ssh communicator return fatal errors
jbardin Feb 15, 2018
5726efe
simplify remote-exec runScripts
jbardin Feb 15, 2018
ae0d343
update etcd documentation links
jbardin Feb 15, 2018
588396d
`enable` habitat supervisor service before `start`
Jan 29, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
## 0.11.3 (Unreleased)
## 0.11.4 (Unreleased)

IMPROVEMENTS:

* backend/s3: add support for the eu-west-3 region [GH-17193]
* backend/s3: add support for the cn-northwest-1 region [GH-17216]
* provisioner/habitat: Detect if hab user exists and only create if necessary [GH-17195]
* provisioner/habitat: Allow custom service name [GH-17196]

BUG FIXES:

* helper/schema: Prevent crash on removal of computed field in CustomizeDiff [GH-17261]

## 0.11.3 (January 31, 2018)

IMPROVEMENTS:

* backend/s3: add support for the eu-west-3 region ([#17193](https://github.com/hashicorp/terraform/issues/17193))


BUG FIXES:

* core: fix crash when an error is encountered during refresh [GH-17076]
* config: fixed crash when module source is invalid [GH-17134]
* config: allow the count pseudo-attribute of a resource to be interpolated into `provisioner` and `connection` blocks without errors [GH-17133]
* backend/s3: allow the workspace name to be a prefix of workspace_key_prefix [GH-17086]
* provisioner/chef: fix crash when validating `use_policyfile` [GH-17147]
* core: fix crash when an error is encountered during refresh ([#17076](https://github.com/hashicorp/terraform/issues/17076))
* config: fixed crash when module source is invalid ([#17134](https://github.com/hashicorp/terraform/issues/17134))
* config: allow the count pseudo-attribute of a resource to be interpolated into `provisioner` and `connection` blocks without errors ([#17133](https://github.com/hashicorp/terraform/issues/17133))
* backend/s3: allow the workspace name to be a prefix of workspace_key_prefix ([#17086](https://github.com/hashicorp/terraform/issues/17086))
* provisioner/chef: fix crash when validating `use_policyfile` ([#17147](https://github.com/hashicorp/terraform/issues/17147))

## 0.11.2 (January 9, 2018)

Expand Down
12 changes: 10 additions & 2 deletions backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,23 @@ type Operation struct {

// RunningOperation is the result of starting an operation.
type RunningOperation struct {
// Context should be used to track Done and Err for errors.
//
// For implementers of a backend, this context should not wrap the
// passed in context. Otherwise, canceling the parent context will
// immediately mark this context as "done" but those aren't the semantics
// we want: we want this context to be done only when the operation itself
// is fully done.
context.Context

// Stop requests the operation to complete early, by calling Stop on all
// the plugins. If the process needs to terminate immediately, call Cancel.
Stop context.CancelFunc

// Cancel is the context.CancelFunc associated with the embedded context,
// and can be called to terminate the operation early.
// Once Cancel is called, the operation should return as soon as possible
// to avoid running operations during process exit.
Cancel context.CancelFunc

// Err is the error of the operation. This is populated after
// the operation has completed.
Err error
Expand Down
73 changes: 68 additions & 5 deletions backend/local/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -224,7 +225,7 @@ func (b *Local) State(name string) (state.State, error) {
// name conflicts, assume that the field is overwritten if set.
func (b *Local) Operation(ctx context.Context, op *backend.Operation) (*backend.RunningOperation, error) {
// Determine the function to call for our operation
var f func(context.Context, *backend.Operation, *backend.RunningOperation)
var f func(context.Context, context.Context, *backend.Operation, *backend.RunningOperation)
switch op.Type {
case backend.OperationTypeRefresh:
f = b.opRefresh
Expand All @@ -244,20 +245,82 @@ func (b *Local) Operation(ctx context.Context, op *backend.Operation) (*backend.
b.opLock.Lock()

// Build our running operation
runningCtx, runningCtxCancel := context.WithCancel(context.Background())
runningOp := &backend.RunningOperation{Context: runningCtx}
// the runninCtx is only used to block until the operation returns.
runningCtx, done := context.WithCancel(context.Background())
runningOp := &backend.RunningOperation{
Context: runningCtx,
}

// stopCtx wraps the context passed in, and is used to signal a graceful Stop.
stopCtx, stop := context.WithCancel(ctx)
runningOp.Stop = stop

// cancelCtx is used to cancel the operation immediately, usually
// indicating that the process is exiting.
cancelCtx, cancel := context.WithCancel(context.Background())
runningOp.Cancel = cancel

// Do it
go func() {
defer done()
defer stop()
defer cancel()

defer b.opLock.Unlock()
defer runningCtxCancel()
f(ctx, op, runningOp)
f(stopCtx, cancelCtx, op, runningOp)
}()

// Return
return runningOp, nil
}

// opWait wats for the operation to complete, and a stop signal or a
// cancelation signal.
func (b *Local) opWait(
doneCh <-chan struct{},
stopCtx context.Context,
cancelCtx context.Context,
tfCtx *terraform.Context,
opState state.State) (canceled bool) {
// Wait for the operation to finish or for us to be interrupted so
// we can handle it properly.
select {
case <-stopCtx.Done():
if b.CLI != nil {
b.CLI.Output("stopping operation...")
}

// try to force a PersistState just in case the process is terminated
// before we can complete.
if err := opState.PersistState(); err != nil {
// We can't error out from here, but warn the user if there was an error.
// If this isn't transient, we will catch it again below, and
// attempt to save the state another way.
if b.CLI != nil {
b.CLI.Error(fmt.Sprintf(earlyStateWriteErrorFmt, err))
}
}

// Stop execution
go tfCtx.Stop()

select {
case <-cancelCtx.Done():
log.Println("[WARN] running operation canceled")
// if the operation was canceled, we need to return immediately
canceled = true
case <-doneCh:
}
case <-cancelCtx.Done():
// this should not be called without first attempting to stop the
// operation
log.Println("[ERROR] running operation canceled without Stop")
canceled = true
case <-doneCh:
}
return
}

// Colorize returns the Colorize structure that can be used for colorizing
// output. This is gauranteed to always return a non-nil value and so is useful
// as a helper to wrap any potentially colored strings.
Expand Down
33 changes: 5 additions & 28 deletions backend/local/backend_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import (
)

func (b *Local) opApply(
ctx context.Context,
stopCtx context.Context,
cancelCtx context.Context,
op *backend.Operation,
runningOp *backend.RunningOperation) {
log.Printf("[INFO] backend/local: starting Apply operation")
Expand Down Expand Up @@ -55,7 +56,7 @@ func (b *Local) opApply(
}

if op.LockState {
lockCtx, cancel := context.WithTimeout(ctx, op.StateLockTimeout)
lockCtx, cancel := context.WithTimeout(stopCtx, op.StateLockTimeout)
defer cancel()

lockInfo := state.NewLockInfo()
Expand Down Expand Up @@ -153,32 +154,8 @@ func (b *Local) opApply(
applyState = tfCtx.State()
}()

// Wait for the apply to finish or for us to be interrupted so
// we can handle it properly.
err = nil
select {
case <-ctx.Done():
if b.CLI != nil {
b.CLI.Output("stopping apply operation...")
}

// try to force a PersistState just in case the process is terminated
// before we can complete.
if err := opState.PersistState(); err != nil {
// We can't error out from here, but warn the user if there was an error.
// If this isn't transient, we will catch it again below, and
// attempt to save the state another way.
if b.CLI != nil {
b.CLI.Error(fmt.Sprintf(earlyStateWriteErrorFmt, err))
}
}

// Stop execution
go tfCtx.Stop()

// Wait for completion still
<-doneCh
case <-doneCh:
if b.opWait(doneCh, stopCtx, cancelCtx, tfCtx, opState) {
return
}

// Store the final state
Expand Down
19 changes: 5 additions & 14 deletions backend/local/backend_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import (
)

func (b *Local) opPlan(
ctx context.Context,
stopCtx context.Context,
cancelCtx context.Context,
op *backend.Operation,
runningOp *backend.RunningOperation) {
log.Printf("[INFO] backend/local: starting Plan operation")
Expand Down Expand Up @@ -62,7 +63,7 @@ func (b *Local) opPlan(
}

if op.LockState {
lockCtx, cancel := context.WithTimeout(ctx, op.StateLockTimeout)
lockCtx, cancel := context.WithTimeout(stopCtx, op.StateLockTimeout)
defer cancel()

lockInfo := state.NewLockInfo()
Expand Down Expand Up @@ -111,18 +112,8 @@ func (b *Local) opPlan(
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 b.opWait(doneCh, stopCtx, cancelCtx, tfCtx, opState) {
return
}

if planErr != nil {
Expand Down
19 changes: 5 additions & 14 deletions backend/local/backend_refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import (
)

func (b *Local) opRefresh(
ctx context.Context,
stopCtx context.Context,
cancelCtx context.Context,
op *backend.Operation,
runningOp *backend.RunningOperation) {
// Check if our state exists if we're performing a refresh operation. We
Expand Down Expand Up @@ -53,7 +54,7 @@ func (b *Local) opRefresh(
}

if op.LockState {
lockCtx, cancel := context.WithTimeout(ctx, op.StateLockTimeout)
lockCtx, cancel := context.WithTimeout(stopCtx, op.StateLockTimeout)
defer cancel()

lockInfo := state.NewLockInfo()
Expand Down Expand Up @@ -90,18 +91,8 @@ func (b *Local) opRefresh(
log.Printf("[INFO] backend/local: refresh calling Refresh")
}()

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:
if b.opWait(doneCh, stopCtx, cancelCtx, tfCtx, opState) {
return
}

// write the resulting state to the running op
Expand Down
24 changes: 4 additions & 20 deletions builtin/provisioners/chef/resource_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"strings"
"sync"
"text/template"
"time"

"github.com/hashicorp/terraform/communicator"
"github.com/hashicorp/terraform/communicator/remote"
Expand Down Expand Up @@ -307,8 +306,11 @@ func applyFn(ctx context.Context) error {
return err
}

ctx, cancel := context.WithTimeout(ctx, comm.Timeout())
defer cancel()

// Wait and retry until we establish the connection
err = retryFunc(comm.Timeout(), func() error {
err = communicator.Retry(ctx, func() error {
return comm.Connect(o)
})
if err != nil {
Expand Down Expand Up @@ -717,24 +719,6 @@ func (p *provisioner) copyOutput(o terraform.UIOutput, r io.Reader, doneCh chan<
}
}

// retryFunc is used to retry a function for a given duration
func retryFunc(timeout time.Duration, f func() error) error {
finish := time.After(timeout)
for {
err := f()
if err == nil {
return nil
}
log.Printf("Retryable error: %v", err)

select {
case <-finish:
return err
case <-time.After(3 * time.Second):
}
}
}

func decodeConfig(d *schema.ResourceData) (*provisioner, error) {
p := &provisioner{
ClientOptions: getStringList(d.Get("client_options")),
Expand Down
Loading