Ejemplo n.º 1
0
 protected override void Execute(RunningDeployment deployment, Dictionary <string, string> environmentVariables)
 {
     using (var cli = new TerraformCliExecutor(log, fileSystem, commandLineRunner, deployment, environmentVariables))
     {
         cli.ExecuteCommand("destroy", "-force", "-no-color", cli.TerraformVariableFiles, cli.ActionParams)
         .VerifySuccess();
     }
 }
Ejemplo n.º 2
0
        protected override void Execute(RunningDeployment deployment, Dictionary <string, string> environmentVariables)
        {
            string results;

            using (var cli = new TerraformCliExecutor(log, fileSystem, commandLineRunner, 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);
        }
Ejemplo n.º 3
0
        protected override void Execute(RunningDeployment deployment, Dictionary <string, string> environmentVariables)
        {
            using (var cli = new TerraformCliExecutor(log, fileSystem, commandLineRunner, 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, false, "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}'");
                    }
                }
            }
        }