diff --git a/command/apply.go b/command/apply.go index 696fc00c72..ca9813eb52 100644 --- a/command/apply.go +++ b/command/apply.go @@ -48,6 +48,7 @@ func (c *ApplyCommand) Run(args []string) int { cmdFlags.StringVar(&c.Meta.stateOutPath, "state-out", "", "path") cmdFlags.StringVar(&c.Meta.backupPath, "backup", "", "path") cmdFlags.BoolVar(&c.Meta.stateLock, "lock", true, "lock state") + cmdFlags.DurationVar(&c.Meta.stateLockTimeout, "lock-timeout", 0, "lock timeout") cmdFlags.Usage = func() { c.Ui.Error(c.Help()) } if err := cmdFlags.Parse(args); err != nil { return 1 @@ -183,7 +184,6 @@ func (c *ApplyCommand) Run(args []string) int { opReq.Plan = plan opReq.PlanRefresh = refresh opReq.Type = backend.OperationTypeApply - opReq.LockState = c.Meta.stateLock // Perform the operation ctx, ctxCancel := context.WithCancel(context.Background()) @@ -276,6 +276,8 @@ Options: -lock=true Lock the state file when locking is supported. + -lock-timeout=0s Duration to retry a state lock. + -input=true Ask for input for variables if not directly set. -no-color If specified, output won't contain any color. @@ -325,6 +327,8 @@ Options: -lock=true Lock the state file when locking is supported. + -lock-timeout=0s Duration to retry a state lock. + -no-color If specified, output won't contain any color. -parallelism=n Limit the number of concurrent operations. diff --git a/command/import.go b/command/import.go index df8e420bda..1636ab9d98 100644 --- a/command/import.go +++ b/command/import.go @@ -35,6 +35,8 @@ func (c *ImportCommand) Run(args []string) int { cmdFlags.StringVar(&c.Meta.backupPath, "backup", "", "path") cmdFlags.StringVar(&configPath, "config", pwd, "path") cmdFlags.StringVar(&c.Meta.provider, "provider", "", "provider") + cmdFlags.BoolVar(&c.Meta.stateLock, "lock", true, "lock state") + cmdFlags.DurationVar(&c.Meta.stateLockTimeout, "lock-timeout", 0, "lock timeout") cmdFlags.Usage = func() { c.Ui.Error(c.Help()) } if err := cmdFlags.Parse(args); err != nil { return 1 @@ -162,6 +164,10 @@ Options: -input=true Ask for input for variables if not directly set. + -lock=true Lock the state file when locking is supported. + + -lock-timeout=0s Duration to retry a state lock. + -no-color If specified, output won't contain any color. -provider=provider Specific provider to use for import. This is used for diff --git a/command/init.go b/command/init.go index d2a9e835c8..6721b87a1d 100644 --- a/command/init.go +++ b/command/init.go @@ -28,6 +28,8 @@ func (c *InitCommand) Run(args []string) int { cmdFlags.Var((*variables.FlagAny)(&flagConfigExtra), "backend-config", "") cmdFlags.BoolVar(&flagGet, "get", true, "") cmdFlags.BoolVar(&c.forceInitCopy, "force-copy", false, "suppress prompts about copying state data") + cmdFlags.BoolVar(&c.Meta.stateLock, "lock", true, "lock state") + cmdFlags.DurationVar(&c.Meta.stateLockTimeout, "lock-timeout", 0, "lock timeout") cmdFlags.Usage = func() { c.Ui.Error(c.Help()) } if err := cmdFlags.Parse(args); err != nil { @@ -226,6 +228,10 @@ Options: -input=true Ask for input if necessary. If false, will error if input was required. + -lock=true Lock the state file when locking is supported. + + -lock-timeout=0s Duration to retry a state lock. + -no-color If specified, output won't contain any color. -force-copy Suppress prompts about copying state data. This is diff --git a/command/meta_backend.go b/command/meta_backend.go index c9a469f780..64f6a7861e 100644 --- a/command/meta_backend.go +++ b/command/meta_backend.go @@ -171,6 +171,7 @@ func (m *Meta) Operation() *backend.Operation { Targets: m.targets, UIIn: m.UIInput(), Environment: m.Env(), + LockState: m.stateLock, StateLockTimeout: m.stateLockTimeout, } } diff --git a/command/plan.go b/command/plan.go index 5b89634ed9..0b66fdffd6 100644 --- a/command/plan.go +++ b/command/plan.go @@ -32,6 +32,7 @@ func (c *PlanCommand) Run(args []string) int { cmdFlags.StringVar(&c.Meta.statePath, "state", "", "path") cmdFlags.BoolVar(&detailed, "detailed-exitcode", false, "detailed-exitcode") cmdFlags.BoolVar(&c.Meta.stateLock, "lock", true, "lock state") + cmdFlags.DurationVar(&c.Meta.stateLockTimeout, "lock-timeout", 0, "lock timeout") cmdFlags.Usage = func() { c.Ui.Error(c.Help()) } if err := cmdFlags.Parse(args); err != nil { return 1 @@ -85,7 +86,6 @@ func (c *PlanCommand) Run(args []string) int { opReq.PlanRefresh = refresh opReq.PlanOutPath = outPath opReq.Type = backend.OperationTypePlan - opReq.LockState = c.Meta.stateLock // Perform the operation op, err := b.Operation(context.Background(), opReq) @@ -145,6 +145,8 @@ Options: -lock=true Lock the state file when locking is supported. + -lock-timeout=0s Duration to retry a state lock. + -module-depth=n Specifies the depth of modules to show in the output. This does not affect the plan itself, only the output shown. By default, this is -1, which will expand all. diff --git a/command/refresh.go b/command/refresh.go index c9c5527b91..3f1b8bf286 100644 --- a/command/refresh.go +++ b/command/refresh.go @@ -24,6 +24,7 @@ func (c *RefreshCommand) Run(args []string) int { cmdFlags.StringVar(&c.Meta.stateOutPath, "state-out", "", "path") cmdFlags.StringVar(&c.Meta.backupPath, "backup", "", "path") cmdFlags.BoolVar(&c.Meta.stateLock, "lock", true, "lock state") + cmdFlags.DurationVar(&c.Meta.stateLockTimeout, "lock-timeout", 0, "lock timeout") cmdFlags.Usage = func() { c.Ui.Error(c.Help()) } if err := cmdFlags.Parse(args); err != nil { return 1 @@ -53,7 +54,6 @@ func (c *RefreshCommand) Run(args []string) int { opReq := c.Operation() opReq.Type = backend.OperationTypeRefresh opReq.Module = mod - opReq.LockState = c.Meta.stateLock // Perform the operation op, err := b.Operation(context.Background(), opReq) @@ -98,6 +98,8 @@ Options: -lock=true Lock the state file when locking is supported. + -lock-timeout=0s Duration to retry a state lock. + -no-color If specified, output won't contain any color. -state=path Path to read and save state (unless state-out diff --git a/command/taint.go b/command/taint.go index 4836404191..e4e4436207 100644 --- a/command/taint.go +++ b/command/taint.go @@ -29,6 +29,7 @@ func (c *TaintCommand) Run(args []string) int { cmdFlags.StringVar(&c.Meta.stateOutPath, "state-out", "", "path") cmdFlags.StringVar(&c.Meta.backupPath, "backup", "", "path") cmdFlags.BoolVar(&c.Meta.stateLock, "lock", true, "lock state") + cmdFlags.DurationVar(&c.Meta.stateLockTimeout, "lock-timeout", 0, "lock timeout") cmdFlags.Usage = func() { c.Ui.Error(c.Help()) } if err := cmdFlags.Parse(args); err != nil { return 1 @@ -192,6 +193,8 @@ Options: -lock=true Lock the state file when locking is supported. + -lock-timeout=0s Duration to retry a state lock. + -module=path The module path where the resource lives. By default this will be root. Child modules can be specified by names. Ex. "consul" or "consul.vpc" (nested modules). diff --git a/command/untaint.go b/command/untaint.go index cc4a99aa5d..adce511f7c 100644 --- a/command/untaint.go +++ b/command/untaint.go @@ -28,6 +28,7 @@ func (c *UntaintCommand) Run(args []string) int { cmdFlags.StringVar(&c.Meta.stateOutPath, "state-out", "", "path") cmdFlags.StringVar(&c.Meta.backupPath, "backup", "", "path") cmdFlags.BoolVar(&c.Meta.stateLock, "lock", true, "lock state") + cmdFlags.DurationVar(&c.Meta.stateLockTimeout, "lock-timeout", 0, "lock timeout") cmdFlags.Usage = func() { c.Ui.Error(c.Help()) } if err := cmdFlags.Parse(args); err != nil { return 1 @@ -180,6 +181,8 @@ Options: -lock=true Lock the state file when locking is supported. + -lock-timeout=0s Duration to retry a state lock. + -module=path The module path where the resource lives. By default this will be root. Child modules can be specified by names. Ex. "consul" or "consul.vpc" (nested modules).