Skip to content

Commit

Permalink
Merge pull request #56 from tannerwatson/feature/add_missing_switches
Browse files Browse the repository at this point in the history
Added some missing switches to apply, init, and plan settings
  • Loading branch information
nils-a authored May 23, 2024
2 parents 073fbd3 + cac550a commit 3959942
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/Cake.Terraform.Tests/TerraformApplyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
}
}
52 changes: 52 additions & 0 deletions src/Cake.Terraform.Tests/TerraformInitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
26 changes: 26 additions & 0 deletions src/Cake.Terraform.Tests/TerraformPlanTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
5 changes: 5 additions & 0 deletions src/Cake.Terraform/Apply/TerraformApplyRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/Cake.Terraform/Apply/TerraformApplySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -25,5 +30,11 @@ public class TerraformApplySettings : TerraformSettings
/// https://www.terraform.io/docs/commands/apply.html#auto-approve
/// </summary>
public bool AutoApprove { get; set; }

/// <summary>
/// Ask for input for variables if not directly set.
/// <see>https://www.terraform.io/docs/commands/apply.html#input-true</see>
/// </summary>
public bool Input { get; set; }
}
}
10 changes: 10 additions & 0 deletions src/Cake.Terraform/Init/TerraformInitRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/Cake.Terraform/Init/TerraformInitSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ namespace Cake.Terraform.Init
{
public class TerraformInitSettings : TerraformSettings
{
public TerraformInitSettings()
{
this.Input = true;
this.Backend = true;
}

/// <summary>
/// A set of backend config key-value overrides to be passed to `terraform init`
/// <see>https://www.terraform.io/docs/commands/init.html#backend-config-value</see>
Expand All @@ -22,5 +28,17 @@ public class TerraformInitSettings : TerraformSettings
/// <see>https://www.terraform.io/docs/commands/init.html#force-copy</see>
/// </summary>
public bool ForceCopy { get; set; }

/// <summary>
/// Ask for input if necessary. If false, will error if input was required.
/// <see>https://www.terraform.io/docs/commands/init.html#input-true</see>
/// </summary>
public bool Input { get; set; }

/// <summary>
/// Configure the backend for this configuration.
/// <see>https://www.terraform.io/docs/commands/init.html#backend-initialization</see>
/// </summary>
public bool Backend { get; set; }
}
}
5 changes: 5 additions & 0 deletions src/Cake.Terraform/Plan/TerraformPlanRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public void Run(TerraformPlanSettings settings)
}
}

if (!settings.Input)
{
builder.AppendSwitch("-input", "=", settings.Input.ToString());
}

Run(settings, builder);
}

Expand Down
11 changes: 11 additions & 0 deletions src/Cake.Terraform/Plan/TerraformPlanSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -24,5 +29,11 @@ public class TerraformPlanSettings : TerraformSettings
/// If set to true, generates a plan to destroy all the known resources
/// </summary>
public bool Destroy { get; set; }

/// <summary>
/// Ask for input for variables if not directly set.
/// <see>https://www.terraform.io/docs/commands/plan.html#input-true</see>
/// </summary>
public bool Input { get; set; }
}
}

0 comments on commit 3959942

Please sign in to comment.