From cac550ad94c22608b80c8bba21fbec77c80edcde Mon Sep 17 00:00:00 2001 From: Tanner Watson Date: Tue, 11 Aug 2020 18:49:28 -0400 Subject: [PATCH] Added some missing switches to apply, init, and plan settings --- .../TerraformApplyTests.cs | 28 +++++++++- .../TerraformInitTests.cs | 52 +++++++++++++++++++ .../TerraformPlanTests.cs | 26 ++++++++++ .../Apply/TerraformApplyRunner.cs | 5 ++ .../Apply/TerraformApplySettings.cs | 11 ++++ .../Init/TerraformInitRunner.cs | 10 ++++ .../Init/TerraformInitSettings.cs | 18 +++++++ .../Plan/TerraformPlanRunner.cs | 5 ++ .../Plan/TerraformPlanSettings.cs | 11 ++++ 9 files changed, 165 insertions(+), 1 deletion(-) diff --git a/src/Cake.Terraform.Tests/TerraformApplyTests.cs b/src/Cake.Terraform.Tests/TerraformApplyTests.cs index 3c24f7f..ee5eb49 100644 --- a/src/Cake.Terraform.Tests/TerraformApplyTests.cs +++ b/src/Cake.Terraform.Tests/TerraformApplyTests.cs @@ -157,7 +157,7 @@ public void Should_set_plan_path() Assert.Equal("apply \"plan.out\"", result.Args); } - [Fact] + [Fact] public void Should_set_parallelism() { var fixture = new Fixture @@ -171,6 +171,32 @@ public void Should_set_parallelism() Assert.Contains("-parallelism=42", result.Args); } + + [Fact] + public void Should_omit_input_flag_by_default() + { + var fixture = new Fixture(); + + var result = fixture.Run(); + + Assert.DoesNotContain("-input", result.Args); + } + + [Fact] + public void Should_include_input_flag_when_setting_is_false() + { + var fixture = new Fixture + { + Settings = new TerraformApplySettings + { + Input = false + } + }; + + var result = fixture.Run(); + + Assert.Contains("-input", result.Args); + } } } } diff --git a/src/Cake.Terraform.Tests/TerraformInitTests.cs b/src/Cake.Terraform.Tests/TerraformInitTests.cs index 0af54b4..ce48d6c 100644 --- a/src/Cake.Terraform.Tests/TerraformInitTests.cs +++ b/src/Cake.Terraform.Tests/TerraformInitTests.cs @@ -163,6 +163,58 @@ public void Should_include_force_copy_flag_when_setting_is_true() Assert.Contains("-force-copy", result.Args); } + + [Fact] + public void Should_omit_input_flag_by_default() + { + var fixture = new Fixture(); + + var result = fixture.Run(); + + Assert.DoesNotContain("-input", result.Args); + } + + [Fact] + public void Should_include_input_flag_when_setting_is_false() + { + var fixture = new Fixture + { + Settings = new TerraformInitSettings + { + Input = false + } + }; + + var result = fixture.Run(); + + Assert.Contains("-input", result.Args); + } + + [Fact] + public void Should_omit_backend_flag_by_default() + { + var fixture = new Fixture(); + + var result = fixture.Run(); + + Assert.DoesNotContain("-backend", result.Args); + } + + [Fact] + public void Should_include_backend_flag_when_setting_is_false() + { + var fixture = new Fixture + { + Settings = new TerraformInitSettings + { + Backend = false + } + }; + + var result = fixture.Run(); + + Assert.Contains("-backend", result.Args); + } } } } \ No newline at end of file diff --git a/src/Cake.Terraform.Tests/TerraformPlanTests.cs b/src/Cake.Terraform.Tests/TerraformPlanTests.cs index f5c079c..1e95eee 100644 --- a/src/Cake.Terraform.Tests/TerraformPlanTests.cs +++ b/src/Cake.Terraform.Tests/TerraformPlanTests.cs @@ -205,6 +205,32 @@ public void Should_not_set_destroy_flag_if_set_to_false() Assert.DoesNotContain("-destroy", result.Args); } + + [Fact] + public void Should_omit_input_flag_by_default() + { + var fixture = new Fixture(); + + var result = fixture.Run(); + + Assert.DoesNotContain("-input", result.Args); + } + + [Fact] + public void Should_include_input_flag_when_setting_is_false() + { + var fixture = new Fixture + { + Settings = new TerraformPlanSettings + { + Input = false + } + }; + + var result = fixture.Run(); + + Assert.Contains("-input", result.Args); + } } } } \ No newline at end of file diff --git a/src/Cake.Terraform/Apply/TerraformApplyRunner.cs b/src/Cake.Terraform/Apply/TerraformApplyRunner.cs index 9d9319a..813b51c 100644 --- a/src/Cake.Terraform/Apply/TerraformApplyRunner.cs +++ b/src/Cake.Terraform/Apply/TerraformApplyRunner.cs @@ -44,6 +44,11 @@ public void Run(TerraformApplySettings settings) builder.AppendSwitchQuoted("-var", $"{inputVariable.Key}={inputVariable.Value}"); } + if (!settings.Input) + { + builder.AppendSwitch("-input", "=", settings.Input.ToString()); + } + Run(settings, builder); } } diff --git a/src/Cake.Terraform/Apply/TerraformApplySettings.cs b/src/Cake.Terraform/Apply/TerraformApplySettings.cs index 3cf537f..9587975 100644 --- a/src/Cake.Terraform/Apply/TerraformApplySettings.cs +++ b/src/Cake.Terraform/Apply/TerraformApplySettings.cs @@ -5,6 +5,11 @@ namespace Cake.Terraform.Apply { public class TerraformApplySettings : TerraformSettings { + public TerraformApplySettings() + { + this.Input = true; + } + public int Parallelism { get; set; } public FilePath Plan { get; set; } @@ -25,5 +30,11 @@ public class TerraformApplySettings : TerraformSettings /// https://www.terraform.io/docs/commands/apply.html#auto-approve /// public bool AutoApprove { get; set; } + + /// + /// Ask for input for variables if not directly set. + /// https://www.terraform.io/docs/commands/apply.html#input-true + /// + public bool Input { get; set; } } } \ No newline at end of file diff --git a/src/Cake.Terraform/Init/TerraformInitRunner.cs b/src/Cake.Terraform/Init/TerraformInitRunner.cs index 1d653c5..0dc8d32 100644 --- a/src/Cake.Terraform/Init/TerraformInitRunner.cs +++ b/src/Cake.Terraform/Init/TerraformInitRunner.cs @@ -32,6 +32,16 @@ public void Run(TerraformInitSettings settings) builder.Append("-reconfigure"); } + if (!settings.Input) + { + builder.AppendSwitch("-input", "=", settings.Input.ToString()); + } + + if (!settings.Backend) + { + builder.AppendSwitch("-backend", "=", settings.Backend.ToString()); + } + Run(settings, builder); } } diff --git a/src/Cake.Terraform/Init/TerraformInitSettings.cs b/src/Cake.Terraform/Init/TerraformInitSettings.cs index bb4b3e8..9659be4 100644 --- a/src/Cake.Terraform/Init/TerraformInitSettings.cs +++ b/src/Cake.Terraform/Init/TerraformInitSettings.cs @@ -4,6 +4,12 @@ namespace Cake.Terraform.Init { public class TerraformInitSettings : TerraformSettings { + public TerraformInitSettings() + { + this.Input = true; + this.Backend = true; + } + /// /// A set of backend config key-value overrides to be passed to `terraform init` /// https://www.terraform.io/docs/commands/init.html#backend-config-value @@ -22,5 +28,17 @@ public class TerraformInitSettings : TerraformSettings /// https://www.terraform.io/docs/commands/init.html#force-copy /// public bool ForceCopy { get; set; } + + /// + /// Ask for input if necessary. If false, will error if input was required. + /// https://www.terraform.io/docs/commands/init.html#input-true + /// + public bool Input { get; set; } + + /// + /// Configure the backend for this configuration. + /// https://www.terraform.io/docs/commands/init.html#backend-initialization + /// + public bool Backend { get; set; } } } diff --git a/src/Cake.Terraform/Plan/TerraformPlanRunner.cs b/src/Cake.Terraform/Plan/TerraformPlanRunner.cs index c1be060..3bea879 100644 --- a/src/Cake.Terraform/Plan/TerraformPlanRunner.cs +++ b/src/Cake.Terraform/Plan/TerraformPlanRunner.cs @@ -43,6 +43,11 @@ public void Run(TerraformPlanSettings settings) } } + if (!settings.Input) + { + builder.AppendSwitch("-input", "=", settings.Input.ToString()); + } + Run(settings, builder); } diff --git a/src/Cake.Terraform/Plan/TerraformPlanSettings.cs b/src/Cake.Terraform/Plan/TerraformPlanSettings.cs index bf43fb8..096e9ab 100644 --- a/src/Cake.Terraform/Plan/TerraformPlanSettings.cs +++ b/src/Cake.Terraform/Plan/TerraformPlanSettings.cs @@ -5,6 +5,11 @@ namespace Cake.Terraform.Plan { public class TerraformPlanSettings : TerraformSettings { + public TerraformPlanSettings() + { + this.Input = true; + } + public FilePath OutFile { get; set; } public int Parallelism { get; set; } @@ -24,5 +29,11 @@ public class TerraformPlanSettings : TerraformSettings /// If set to true, generates a plan to destroy all the known resources /// public bool Destroy { get; set; } + + /// + /// Ask for input for variables if not directly set. + /// https://www.terraform.io/docs/commands/plan.html#input-true + /// + public bool Input { get; set; } } } \ No newline at end of file