feat: set TF_APPEND_USER_AGENT env var for terraform steps#6305
feat: set TF_APPEND_USER_AGENT env var for terraform steps#6305aidansteele wants to merge 2 commits into
Conversation
b453156 to
4c24f9a
Compare
There was a problem hiding this comment.
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_AGENTinDefaultProjectCommandRunner.runSteps()for all workflow steps, using--vcs-status-name(oratlantis) and the Atlantis version plus PR context. - Wire
AtlantisVersionandVCSStatusNameintoDefaultProjectCommandRunnerfrom 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. |
| // 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" | ||
| } | ||
|
|
There was a problem hiding this comment.
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.
8f09263 to
5db103d
Compare
|
@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. |
5db103d to
9bb6b30
Compare
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>
9bb6b30 to
048640a
Compare
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_AGENTbefore 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