Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions source/Calamari.Terraform/Behaviours/ApplyBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,17 @@ protected override Task Execute(RunningDeployment deployment, Dictionary<string,
commandLineRunner,
deployment,
environmentVariables);
cli.ExecuteCommand("apply",
"-no-color",
"-auto-approve",
cli.TerraformVariableFiles,
cli.ActionParams);
var applyArgs = GetApplyArgs(deployment, cli);

cli.ExecuteCommand(applyArgs.ToArray());

var outputArg = GetOutputArgs(deployment);

var args = new List<string>();
args.Add("output");
if (!OctopusFeatureToggles.AnsiColorsInTaskLogFeatureToggle.IsEnabled(deployment.Variables))
args.Add("-no-color");
args.Add("-json");

// Attempt to get the outputs. This will fail if none are defined in versions prior to v0.11.15
// Please note that we really don't want to log the following command output as it can contain sensitive variables etc. hence the IgnoreCommandOutput()
if (cli.ExecuteCommand(out var result,
false,
args.ToArray())
outputArg.ToArray())
.ExitCode
!= 0)
return Task.CompletedTask;
Expand All @@ -73,6 +67,24 @@ protected override Task Execute(RunningDeployment deployment, Dictionary<string,
return Task.CompletedTask;
}

static IEnumerable<string> GetOutputArgs(RunningDeployment deployment)
{
yield return "output";
if (!OctopusFeatureToggles.AnsiColorsInTaskLogFeatureToggle.IsEnabled(deployment.Variables))
yield return "-no-color";
yield return "-json";
}

static IEnumerable<string> GetApplyArgs(RunningDeployment deployment, TerraformCliExecutor cli)
{
yield return "apply";
if (!OctopusFeatureToggles.AnsiColorsInTaskLogFeatureToggle.IsEnabled(deployment.Variables))
yield return "-no-color";
yield return "-auto-approve";
yield return cli.TerraformVariableFiles;
yield return cli.ActionParams;
}

IEnumerable<(string, JToken)> OutputVariables(string result)
{
var jObj = JObject.Parse(result);
Expand Down