From dc848c262f34bfd182c0486c4f1c4a18a6c90df7 Mon Sep 17 00:00:00 2001 From: Raul Salamanca Date: Tue, 23 Jul 2024 08:48:42 -0400 Subject: [PATCH] feat(api): add ShowResult attribute to plan response --- runatlantis.io/docs/api-endpoints.md | 1 + server/events/models/models.go | 2 ++ server/events/project_command_runner.go | 11 +++++++++++ 3 files changed, 14 insertions(+) diff --git a/runatlantis.io/docs/api-endpoints.md b/runatlantis.io/docs/api-endpoints.md index ce622979da..b1aa998c14 100644 --- a/runatlantis.io/docs/api-endpoints.md +++ b/runatlantis.io/docs/api-endpoints.md @@ -73,6 +73,7 @@ curl --request POST 'https:///api/plan' \ "Failure": "", "PlanSuccess": { "TerraformOutput": "", + "ShowResult": "", "LockURL": "", "RePlanCmd": "atlantis plan -d .", "ApplyCmd": "atlantis apply -d .", diff --git a/server/events/models/models.go b/server/events/models/models.go index a23410a69b..8638485520 100644 --- a/server/events/models/models.go +++ b/server/events/models/models.go @@ -364,6 +364,8 @@ func SplitRepoFullName(repoFullName string) (owner string, repo string) { type PlanSuccess struct { // TerraformOutput is the output from Terraform of running plan. TerraformOutput string + // ShowResult is the output from Terraform of running show. + ShowResult string // LockURL is the full URL to the lock held by this plan. LockURL string // RePlanCmd is the command that users should run to re-plan this project. diff --git a/server/events/project_command_runner.go b/server/events/project_command_runner.go index e97d919820..b32a17a5ab 100644 --- a/server/events/project_command_runner.go +++ b/server/events/project_command_runner.go @@ -582,9 +582,20 @@ func (p *DefaultProjectCommandRunner) doPlan(ctx command.ProjectContext) (*model return nil, "", fmt.Errorf("%s\n%s", err, strings.Join(outputs, "\n")) } + showfile := filepath.Join(projAbsPath, ctx.GetShowResultFileName()) + + var showResult []byte + if _, err := os.Stat(showfile); err == nil { + showResult, err = os.ReadFile(showfile) + if err != nil { + return nil, "", errors.Wrap(err, "reading showfile") + } + } + return &models.PlanSuccess{ LockURL: p.LockURLGenerator.GenerateLockURL(lockAttempt.LockKey), TerraformOutput: strings.Join(outputs, "\n"), + ShowResult: string(showResult), RePlanCmd: ctx.RePlanCmd, ApplyCmd: ctx.ApplyCmd, MergedAgain: mergedAgain,