Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): add ShowResult attribute to plan response #4777

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions runatlantis.io/docs/api-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ curl --request POST 'https://<ATLANTIS_HOST_NAME>/api/plan' \
"Failure": "",
"PlanSuccess": {
"TerraformOutput": "<redacted>",
"ShowResult": "<redacted>",
"LockURL": "<redacted>",
"RePlanCmd": "atlantis plan -d .",
"ApplyCmd": "atlantis apply -d .",
Expand Down
2 changes: 2 additions & 0 deletions server/events/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions server/events/project_command_runner.go
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some test per this change?

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down