From bd9b9abb023bfbbb810a18bccb7b5455419a7c80 Mon Sep 17 00:00:00 2001 From: Justin Ryan Date: Wed, 4 Oct 2017 14:07:05 -0400 Subject: [PATCH 1/2] include lock args on plan/apply/destroy --- plugin.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/plugin.go b/plugin.go index ff9f47c..afafd5a 100644 --- a/plugin.go +++ b/plugin.go @@ -210,6 +210,12 @@ func planCommand(config Config) *exec.Cmd { if config.Parallelism > 0 { args = append(args, fmt.Sprintf("-parallelism=%d", config.Parallelism)) } + if config.InitOptions.Lock != nil { + args = append(args, fmt.Sprintf("-lock=%t", *config.InitOptions.Lock)) + } + if config.InitOptions.LockTimeout != "" { + args = append(args, fmt.Sprintf("-lock-timeout=%s", config.InitOptions.LockTimeout)) + } return exec.Command( "terraform", args..., @@ -234,6 +240,12 @@ func applyCommand(config Config) *exec.Cmd { if config.Parallelism > 0 { args = append(args, fmt.Sprintf("-parallelism=%d", config.Parallelism)) } + if config.InitOptions.Lock != nil { + args = append(args, fmt.Sprintf("-lock=%t", *config.InitOptions.Lock)) + } + if config.InitOptions.LockTimeout != "" { + args = append(args, fmt.Sprintf("-lock-timeout=%s", config.InitOptions.LockTimeout)) + } args = append(args, "plan.tfout") return exec.Command( "terraform", @@ -251,6 +263,12 @@ func destroyCommand(config Config) *exec.Cmd { if config.Parallelism > 0 { args = append(args, fmt.Sprintf("-parallelism=%d", config.Parallelism)) } + if config.InitOptions.Lock != nil { + args = append(args, fmt.Sprintf("-lock=%t", *config.InitOptions.Lock)) + } + if config.InitOptions.LockTimeout != "" { + args = append(args, fmt.Sprintf("-lock-timeout=%s", config.InitOptions.LockTimeout)) + } args = append(args, "-force") return exec.Command( "terraform", From 0b0be126e1e0311d740c222d7165fad52f2d4f34 Mon Sep 17 00:00:00 2001 From: Justin Ryan Date: Wed, 4 Oct 2017 14:12:49 -0400 Subject: [PATCH 2/2] add defaults to lock options in doc --- DOCS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DOCS.md b/DOCS.md index 8e6d476..3c18709 100644 --- a/DOCS.md +++ b/DOCS.md @@ -196,10 +196,10 @@ specified multiple times. Flags specified later in the line override those specified earlier if they conflict. init_options.lock -: Lock the state file when locking is supported. +: Lock the state file when locking is supported. Default `true`. init_options.lock-timeout -: Duration to retry a state lock. +: Duration to wait for a state lock. Default `0s`. vars : a map of variables to pass to the Terraform `plan` and `apply` commands.