mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-08-02 00:38:40 +00:00
* Adding policy_check support into yaml config * Added policy check model and runtime structs * Adding BuildPolicyCheckCommand to ProjectCommandBuilder * Return incorrectly deleted code * Remove BuildAutoPolicyPlanCommand from ProjectCommandBuilder * Split runAutoCommand into two functions runAutoPlanCommand - does what originally RunAutoplancommand was doing except now it returns CommandResult and []models.ProjectCommandContext runAutoPolicyCheckCommand - accepts CommandContext, CommandResult, and []models.ProjectCommandContext as arguments and runs PolicyCheckStep runner * Refactor RunCommentCommand * Remove BuildPolicyCheckCommand and rename StepCmdExec back to TerraformExec * Add policy step runner logic and conftest interfaces. * Add show step runner to policy check stage. * Adding models.PolicyCheckCommand to buildCtx This also means buildPlanAllCommands call buildCtx twice once with models.PlanCommand and once with models.PolicyCheckCommand * Adding new project_command_builder that supports policy_check * Refactoring PolicyCheck specific logic into a PolicyCheckProjectCommandBuilder * Moving events.CommandContext to models.CommandContext this will allow me to remove buildCtx method and move ProjectCommandContext creation into models package * Policy Owners might be different types, for that reason we are refactoring Owners into its own struct with specific keys defining different owner types Co-authored-by: Nish Krishnan <nishk@lyft.com> Co-authored-by: Nish Krishnan <nishkrishnan@users.noreply.github.com>
61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
package runtime
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/hashicorp/go-version"
|
|
"github.com/pkg/errors"
|
|
"github.com/runatlantis/atlantis/server/events/models"
|
|
)
|
|
|
|
const minimumShowTfVersion string = "0.12.0"
|
|
|
|
func NewShowStepRunner(executor TerraformExec, defaultTFVersion *version.Version) (Runner, error) {
|
|
runner := &PlanTypeStepRunnerDelegate{
|
|
defaultRunner: &ShowStepRunner{
|
|
TerraformExecutor: executor,
|
|
DefaultTFVersion: defaultTFVersion,
|
|
},
|
|
remotePlanRunner: NullRunner{},
|
|
}
|
|
|
|
return NewMinimumVersionStepRunnerDelegate(minimumShowTfVersion, defaultTFVersion, runner)
|
|
}
|
|
|
|
// ShowStepRunner runs terraform show on an existing plan file and outputs it to a json file
|
|
type ShowStepRunner struct {
|
|
TerraformExecutor TerraformExec
|
|
DefaultTFVersion *version.Version
|
|
}
|
|
|
|
func (p *ShowStepRunner) Run(ctx models.ProjectCommandContext, extraArgs []string, path string, envs map[string]string) (string, error) {
|
|
tfVersion := p.DefaultTFVersion
|
|
if ctx.TerraformVersion != nil {
|
|
tfVersion = ctx.TerraformVersion
|
|
}
|
|
|
|
planFile := filepath.Join(path, GetPlanFilename(ctx.Workspace, ctx.ProjectName))
|
|
showResultFile := filepath.Join(path, ctx.GetShowResultFileName())
|
|
|
|
output, err := p.TerraformExecutor.RunCommandWithVersion(
|
|
ctx.Log,
|
|
path,
|
|
[]string{"show", "-no-color", "-json", filepath.Clean(planFile)},
|
|
envs,
|
|
tfVersion,
|
|
ctx.Workspace,
|
|
)
|
|
|
|
if err != nil {
|
|
return "", errors.Wrap(err, "running terraform show")
|
|
}
|
|
|
|
if err := ioutil.WriteFile(showResultFile, []byte(output), os.ModePerm); err != nil {
|
|
return "", errors.Wrap(err, "writing terraform show result")
|
|
}
|
|
|
|
return output, nil
|
|
}
|