From 18ca1c8fdf5ec86c89792442c3b0218934bd9852 Mon Sep 17 00:00:00 2001 From: Sergio Jozee Date: Thu, 12 Jan 2023 11:24:20 +0100 Subject: [PATCH 1/2] Adding destroy attribute to the apply --- src/Cake.Terraform/Apply/TerraformApplyRunner.cs | 5 +++++ src/Cake.Terraform/Apply/TerraformApplySettings.cs | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/src/Cake.Terraform/Apply/TerraformApplyRunner.cs b/src/Cake.Terraform/Apply/TerraformApplyRunner.cs index 813b51c..d90d077 100644 --- a/src/Cake.Terraform/Apply/TerraformApplyRunner.cs +++ b/src/Cake.Terraform/Apply/TerraformApplyRunner.cs @@ -17,6 +17,11 @@ public void Run(TerraformApplySettings settings) var builder = new ProcessArgumentBuilder() .Append("apply"); + if (settings.Destroy) + { + builder.Append("-destroy"); + } + // Order of AutoApprove and Plan are important. if (settings.AutoApprove) { diff --git a/src/Cake.Terraform/Apply/TerraformApplySettings.cs b/src/Cake.Terraform/Apply/TerraformApplySettings.cs index 9587975..0e29f9f 100644 --- a/src/Cake.Terraform/Apply/TerraformApplySettings.cs +++ b/src/Cake.Terraform/Apply/TerraformApplySettings.cs @@ -36,5 +36,11 @@ public TerraformApplySettings() /// https://www.terraform.io/docs/commands/apply.html#input-true /// public bool Input { get; set; } + + /// + /// Does destory + /// https://www.terraform.io/docs/commands/destroy.html + /// + public bool Destroy { get; set; } } } \ No newline at end of file From bac5e0f05d94f37150e6b0887528fcc40c9a357b Mon Sep 17 00:00:00 2001 From: Sergio Jozee Date: Thu, 12 Jan 2023 12:59:29 +0100 Subject: [PATCH 2/2] Updating summary and adding a test --- src/Cake.Terraform.Tests/TerraformApplyTests.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Cake.Terraform.Tests/TerraformApplyTests.cs b/src/Cake.Terraform.Tests/TerraformApplyTests.cs index ee5eb49..2107459 100644 --- a/src/Cake.Terraform.Tests/TerraformApplyTests.cs +++ b/src/Cake.Terraform.Tests/TerraformApplyTests.cs @@ -142,6 +142,22 @@ public void Should_Append_Auto_Approve_When_AutoApprove_Is_True() Assert.Contains("-auto-approve", result.Args); } + [Fact] + public void Should_Append_Destroy_When_AutoApprove_Is_True() + { + var fixture = new Fixture + { + Settings = new TerraformApplySettings + { + Destroy = true + } + }; + + var result = fixture.Run(); + + Assert.Contains("-destroy", result.Args); + } + [Fact] public void Should_set_plan_path() {