Skip to content

feat: set TF_APPEND_USER_AGENT env var for terraform steps#6305

Open
aidansteele wants to merge 2 commits into
runatlantis:mainfrom
aidansteele:patch-1-clean
Open

feat: set TF_APPEND_USER_AGENT env var for terraform steps#6305
aidansteele wants to merge 2 commits into
runatlantis:mainfrom
aidansteele:patch-1-clean

Conversation

@aidansteele

@aidansteele aidansteele commented Mar 12, 2026

Copy link
Copy Markdown

Note: this was originally implemented in #5588. I tried to implement this with a merge commit, plus my standalone fixes, plus addressing the feedback from @nitrocode (on the original PR), but I couldn't get it to apply cleanly. So this PR implements the same functionality squashed into a single commit, with the original PR's author added as a co-author.

what

Set TF_APPEND_USER_AGENT before all terraform step executions so that providers include Atlantis context in their User-Agent headers. This makes it easier to correlate actions in provider audit logs (e.g. AWS CloudTrail) with the PR/commit that triggered them.

The value uses the --vcs-status-name (defaults to 'atlantis') as the product token, allowing operators running multiple Atlantis instances to differentiate between them.

Format: <vcs-status-name>/<version> (<user>; <command>; <dir>; <workspace>; <commit>; +<pr-url>)

why

It's useful to have this information in logs (ex: CloudTrail) to identify exactly which PR modified a resource.

tests

Updated tests to pass with these changes

references

Copilot AI review requested due to automatic review settings March 12, 2026 00:53
@dosubot dosubot Bot added feature New functionality/enhancement go Pull requests that update Go code labels Mar 12, 2026
@github-actions github-actions Bot added the docs Documentation label Mar 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a default TF_APPEND_USER_AGENT environment variable to Atlantis’ Terraform-related step executions so downstream Terraform providers can include PR/commit context in their HTTP User-Agent, improving audit-log correlation across runs (e.g., CloudTrail).

Changes:

  • Populate TF_APPEND_USER_AGENT in DefaultProjectCommandRunner.runSteps() for all workflow steps, using --vcs-status-name (or atlantis) and the Atlantis version plus PR context.
  • Wire AtlantisVersion and VCSStatusName into DefaultProjectCommandRunner from server initialization.
  • Update unit tests and docs to account for the new environment variable behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
server/server.go Passes Atlantis version and VCS status name into the project command runner so it can compose the user agent.
server/events/project_command_runner.go Builds and injects TF_APPEND_USER_AGENT into the env map before executing workflow steps.
server/events/project_command_runner_test.go Updates expected env maps for step runner calls to include TF_APPEND_USER_AGENT.
server/core/runtime/run_step_runner_test.go Ensures custom run steps receive and can reference TF_APPEND_USER_AGENT.
runatlantis.io/docs/custom-workflows.md Documents TF_APPEND_USER_AGENT as a native environment variable and provides an example format.

Comment thread runatlantis.io/docs/custom-workflows.md
Comment on lines +834 to +841
// Truncate the verbose atlantis version (ex: 'dev (commit: none) (build date: unknown)' -> 'dev').
atlantisVersion, _, _ := strings.Cut(p.AtlantisVersion, " ")

vcsStatusName := p.VCSStatusName
if vcsStatusName == "" {
vcsStatusName = "atlantis"
}

Copilot AI Mar 12, 2026

Copy link

Choose a reason for hiding this comment

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

The new TF_APPEND_USER_AGENT composition logic (version truncation + VCS status name fallback) isn’t directly covered by unit tests with non-empty values. Current expectations in project_command_runner_test mostly exercise the zero-value defaults, so a regression in how AtlantisVersion/VCSStatusName are used (or truncated) could slip through. Consider adding/adjusting a test case that sets runner.AtlantisVersion (including a verbose value with spaces) and runner.VCSStatusName, and asserts the resulting TF_APPEND_USER_AGENT matches the documented format.

Copilot generated this review using guidance from repository custom instructions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lukemassa
lukemassa previously approved these changes May 7, 2026
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label May 7, 2026
Comment thread runatlantis.io/docs/custom-workflows.md
@aidansteele

Copy link
Copy Markdown
Author

@nitrocode I realised the PR was no longer merging cleanly, and the DCO check was failing - I've fixed both. Let me know if there's anything else I can do.

aidansteele and others added 2 commits July 8, 2026 08:45
Set TF_APPEND_USER_AGENT before all terraform step executions so that
providers include Atlantis context in their User-Agent headers. This
makes it easier to correlate actions in provider audit logs (e.g. AWS
CloudTrail) with the PR/commit that triggered them.

The value uses the --vcs-status-name (defaults to 'atlantis') as the
product token, allowing operators running multiple Atlantis instances
to differentiate between them.

Format: <vcs-status-name>/<version> (<user>; <command>; <dir>; <workspace>; <commit>; +<pr-url>)

Co-authored-by: Luke Young <lyoung@confluent.io>
Signed-off-by: Aidan Steele <aidans@squareup.com>
Signed-off-by: Aidan Steele <aidans@squareup.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation feature New functionality/enhancement go Pull requests that update Go code lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs on appending the user agent with relevant atlantis information

4 participants