コード例 #1
0
 protected override void Execute(RunningDeployment deployment, Dictionary <string, string> environmentVariables)
 {
     using (var cli = new TerraformCLIExecutor(fileSystem, deployment, environmentVariables))
     {
         cli.ExecuteCommand("destroy", "-force", "-no-color", cli.TerraformVariableFiles,
                            cli.ActionParams);
     }
 }
コード例 #2
0
        protected override void Execute(RunningDeployment deployment, Dictionary <string, string> environmentVariables)
        {
            string results;

            using (var cli = new TerraformCLIExecutor(fileSystem, deployment, environmentVariables))
            {
                var commandResult = cli.ExecuteCommand(out results, "plan", "-no-color", "-detailed-exitcode", extraParameter, cli.TerraformVariableFiles, cli.ActionParams);
                var resultCode    = commandResult.ExitCode;

                if (resultCode == 1)
                {
                    commandResult.VerifySuccess();
                }

                Log.Info(
                    $"Saving variable 'Octopus.Action[\"{deployment.Variables["Octopus.Action.StepName"]}\"].Output.{TerraformSpecialVariables.Action.Terraform.PlanDetailedExitCode}' with the detailed exit code of the plan, with value '{resultCode}'.");
                Log.SetOutputVariable(TerraformSpecialVariables.Action.Terraform.PlanDetailedExitCode, resultCode.ToString(), deployment.Variables);
            }

            Log.Info(
                $"Saving variable 'Octopus.Action[\"{deployment.Variables["Octopus.Action.StepName"]}\"].Output.{TerraformSpecialVariables.Action.Terraform.PlanOutput}' with the details of the plan");
            Log.SetOutputVariable(TerraformSpecialVariables.Action.Terraform.PlanOutput, results, deployment.Variables);
        }
コード例 #3
0
        protected override void Execute(RunningDeployment deployment, Dictionary <string, string> environmentVariables)
        {
            using (var cli = new TerraformCLIExecutor(fileSystem, deployment, environmentVariables))
            {
                cli.ExecuteCommand("apply", "-no-color", "-auto-approve",
                                   cli.TerraformVariableFiles, cli.ActionParams);

                // Attempt to get the outputs. This will fail if none are defined in versions prior to v0.11.8
                // 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, new IgnoreCommandOutput(), "output", "-no-color", "-json").ExitCode != 0)
                {
                    return;
                }

                foreach (var(name, token) in OutputVariables(result))
                {
                    Boolean.TryParse(token.SelectToken("sensitive")?.ToString(), out var isSensitive);

                    var json  = token.ToString();
                    var value = token.SelectToken("value")?.ToString();

                    Log.SetOutputVariable($"TerraformJsonOutputs[{name}]", json, deployment.Variables, isSensitive);
                    if (value != null)
                    {
                        Log.SetOutputVariable($"TerraformValueOutputs[{name}]", value, deployment.Variables, isSensitive);
                    }

                    Log.Info(
                        $"Saving {(isSensitive ? "sensitive" : String.Empty)}variable 'Octopus.Action[\"{deployment.Variables["Octopus.Action.StepName"]}\"].Output.TerraformJsonOutputs[\"{name}\"]' with the JSON value only of '{json}'");
                    if (value != null)
                    {
                        Log.Info(
                            $"Saving {(isSensitive ? "sensitive" : String.Empty)}variable 'Octopus.Action[\"{deployment.Variables["Octopus.Action.StepName"]}\"].Output.TerraformValueOutputs[\"{name}\"]' with the value only of '{value}'");
                    }
                }
            }
        }