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

Set custom User Agent for Terraform providers #729

Merged
merged 18 commits into from
Oct 29, 2024
Merged

Set custom User Agent for Terraform providers #729

merged 18 commits into from
Oct 29, 2024

Conversation

Cerebrovinny
Copy link
Collaborator

@Cerebrovinny Cerebrovinny commented Oct 19, 2024

What

  • The Atmos command now sets the TF_APPEND_USER_AGENT environment variable, which Terraform uses when interacting with the AWS provider.
  • Users can also append custom values to TF_APPEND_USER_AGENT, allowing further flexibility in monitoring or tracking specific operations.
  • The value has been omitted from atmos.yaml as it is already set by default within the code.
  • If no user-defined value is provided, the system will automatically set atmos {currentVersion} as the default.
  • A new package, version, has been created and migrated out of the cmd package. This change was necessary to avoid dependency cycles that would have blocked usage in other components.
  • No dependencies on the version package were identified in the following repository: terraform-provider-utils.

Why

  • The current implementation lacks a customer-specific user agent for Terraform operations. This enhancement ensures that Atmos-driven actions are identifiable and distinct from other operations.
  • Users will be able to differentiate and monitor Atmos-initiated actions within AWS, facilitating better tracking, logging, and troubleshooting.

Proof of working code

New tests created after the requested changes
CleanShot 2024-10-24 at 11 35 21

CleanShot 2024-10-24 at 12 01 49

references

#DEV-2337

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced --append-user-agent flag for customizing User-Agent strings in Terraform requests.
    • Added append_user_agent configuration option in atmos.yaml for user agent specification.
    • New commands for backend configuration and variable file generation added to the Atmos CLI.
    • Enhanced help documentation and installation instructions for improved user experience.
    • Support for --skip-init, --deploy-run-init, and --from-plan flags in Terraform commands.
  • Bug Fixes

    • Improved error handling for command-line arguments related to the new flag.
  • Documentation

    • Updated installation guide and command usage documentation for clarity and new features.

Copy link
Contributor

coderabbitai bot commented Oct 19, 2024

Warning

Rate limit exceeded

@aknysh has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 51 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Files that changed from the base of the PR and between 455f9d8 and 2bf45dc.

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request primarily focus on enhancing the handling of user agent strings within the Atmos CLI, specifically for Terraform commands. Modifications include the introduction of new fields and flags for user agent management, updates to configuration files, and documentation enhancements to clarify these new features. The changes also involve a shift in how version information is managed across various files, reflecting a restructuring of the codebase.

Changes

File Change Summary
internal/exec/terraform.go Modified ExecuteTerraform to manage TF_APPEND_USER_AGENT, updated handling for terraform deploy.
pkg/schema/schema.go Added AppendUserAgent field to Terraform and ArgsAndFlagsInfo structs.
pkg/config/config.go Added AppendUserAgent field to defaultCliConfig, updated InitCliConfig for user agent initialization.
pkg/config/utils.go Introduced handling for ATMOS_COMPONENTS_TERRAFORM_APPEND_USER_AGENT environment variable.
.goreleaser.yml Updated ldflags to change version flag import path.
Makefile Updated ldflags in the build target to change version variable path.
build.sh Modified go build command to update version variable path.
cmd/version.go Removed hardcoded version variable, replaced with dynamic import from version package.
internal/exec/utils.go Added cfg.AppendUserAgentFlag for command-line flag processing, updated info.AppendUserAgent.
pkg/config/const.go Added constant AppendUserAgentFlag for command-line usage.
pkg/version/version.go Introduced new version package with a dynamic Version variable.
website/docs/quick-start/install-atmos.mdx Updated installation instructions to reflect new version variable path.
internal/exec/help.go Added help message for the --append-user-agent flag.
website/src/components/Screengrabs/atmos-terraform--help.html Updated help documentation for atmos command with new flag details.
website/docs/cli/commands/terraform/usage.mdx Updated atmos terraform command documentation with new flags and features.
website/docs/core-concepts/projects/configuration/terraform.mdx Added append_user_agent configuration option to Terraform settings in YAML.

Possibly related PRs

  • Updates to Installation Instructions #549: The changes in this PR enhance the installation instructions, which may indirectly relate to the user experience improvements from the main PR's updates to the ExecuteTerraform function and environment variable handling.
  • Add the guide to install atmos using aqua #720: This PR adds a guide for installing Atmos using aqua, which is relevant as it provides users with additional methods to set up the environment that could utilize the new features introduced in the main PR.
  • Fix: condition to display help interactive menu #724: This PR modifies the help command behavior, which is directly related to the user experience improvements in the main PR, particularly regarding how commands are processed and displayed to users.

Suggested labels

minor

Suggested reviewers

  • osterman
  • aknysh
  • hans-d
  • joe-niland

Poem

In the garden of code, a new flag does bloom,
--append-user-agent, dispelling the gloom.
With user agents now set, our requests take flight,
In the world of Terraform, everything feels right.
So hop along, friends, let’s build and deploy,
With Atmos in hand, we’ll code with great joy! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range comments (1)
internal/exec/terraform.go (1)

Line range hint 258-271: Integration looks good. Consider adding a debug log for the new environment variable.

The placement of the new code block for setting TF_APPEND_USER_AGENT is appropriate and integrates well with the existing function flow. The debug logging that follows will include the new environment variable if set.

To improve debugging, consider adding a specific debug log for the new TF_APPEND_USER_AGENT setting:

 if strings.TrimSpace(cliConfig.Components.Terraform.AppendUserAgent) != "" {
+	u.LogDebug(cliConfig, fmt.Sprintf("Setting custom user agent: %s", strings.TrimSpace(cliConfig.Components.Terraform.AppendUserAgent)))
 	info.ComponentEnvList = append(
 		info.ComponentEnvList,
 		fmt.Sprintf("TF_APPEND_USER_AGENT=%s", strings.TrimSpace(cliConfig.Components.Terraform.AppendUserAgent)),
 	)
 }

This addition will make it easier to confirm when the custom user agent is being set.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between c866ab5 and d351e23.

📒 Files selected for processing (2)
  • internal/exec/terraform.go (1 hunks)
  • pkg/schema/schema.go (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
pkg/schema/schema.go (1)

65-65: LGTM: New field added to support custom user agent.

The addition of the AppendUserAgent field to the Terraform struct aligns with the PR objective of setting a custom user agent for the Terraform AWS provider. This change allows for the configuration of a custom user agent string, which can be used to identify and track Atmos-initiated operations.

To ensure this change is properly utilized, let's verify if it's being used in the relevant parts of the codebase:

✅ Verification successful

Verified: AppendUserAgent is properly utilized in the codebase.

  • internal/exec/terraform.go handles the custom user agent logic using the AppendUserAgent field.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usage of the new AppendUserAgent field
rg --type go "AppendUserAgent" -C 3

Length of output: 1623

internal/exec/terraform.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between d351e23 and bdd86a5.

📒 Files selected for processing (1)
  • internal/exec/terraform.go (1 hunks)
🧰 Additional context used

internal/exec/terraform.go Outdated Show resolved Hide resolved
pkg/schema/schema.go Show resolved Hide resolved
@Cerebrovinny Cerebrovinny marked this pull request as draft October 19, 2024 20:31
@Cerebrovinny Cerebrovinny marked this pull request as ready for review October 20, 2024 17:34
@Cerebrovinny
Copy link
Collaborator Author

I guess we should move the static version to dynamic using AppendUserAgent: fmt.Sprintf("Cloud Posse Atmos %s (https://atmos.tools)", AtmosVersion),

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between bdd86a5 and 0a84332.

📒 Files selected for processing (3)
  • internal/exec/terraform.go (1 hunks)
  • pkg/config/config.go (1 hunks)
  • pkg/config/utils.go (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
internal/exec/terraform.go (1)

258-266: LGTM! The environment variable TF_APPEND_USER_AGENT is correctly set with proper precedence

The implementation properly sets the TF_APPEND_USER_AGENT environment variable, respecting the precedence of the environment variable over the configuration file as intended. This aligns well with the PR objective to distinguish Atmos-initiated actions.

pkg/config/config.go Outdated Show resolved Hide resolved
pkg/config/utils.go Outdated Show resolved Hide resolved
@osterman osterman changed the title Set custom user agent for Terraform AWS provider #DEV-2337 Set custom user agent for Terraform providers Oct 21, 2024
@osterman
Copy link
Member

osterman commented Oct 21, 2024

@Cerebrovinny thanks for the screenshot. Looks like we're not following the general UA convention.

Let's change to: Atmos/1.181 (Cloud Posse; +https://atmos.tools)

For reference, see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent

pkg/config/config.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 0a84332 and a98ee34.

📒 Files selected for processing (12)
  • .goreleaser.yml (1 hunks)
  • Makefile (1 hunks)
  • build.sh (1 hunks)
  • cmd/version.go (2 hunks)
  • internal/exec/terraform.go (1 hunks)
  • internal/exec/utils.go (2 hunks)
  • pkg/config/config.go (4 hunks)
  • pkg/config/const.go (1 hunks)
  • pkg/config/utils.go (1 hunks)
  • pkg/schema/schema.go (2 hunks)
  • pkg/version/version.go (1 hunks)
  • website/docs/quick-start/install-atmos.mdx (1 hunks)
🔇 Additional comments (14)
pkg/version/version.go (1)

3-5: 🛠️ Refactor suggestion

Enhance version documentation and consider semantic versioning for default.

The current implementation has a few potential improvements:

  1. The documentation should mention that this version is used in the Terraform user agent
  2. The default version "0.0.1" might not be the best choice for a fallback version

Consider these improvements:

-// Version holds the current version of the Atmos CLI.
-// It can be set dynamically during build time using ldflags.
-var Version = "0.0.1" // Default version; will be overridden during build
+// Version holds the current version of the Atmos CLI.
+// It can be set dynamically during build time using ldflags.
+// This version is used in various places including the Terraform user agent string
+// to identify requests made by Atmos.
+//
+// Example build command:
+// go build -ldflags "-X github.com/cloudposse/atmos/pkg/version.Version=1.2.3"
+var Version = "dev" // Default version for development; will be overridden during build

Using "dev" as the default version is a common practice that:

  1. Clearly indicates when the version wasn't properly set during build
  2. Follows the convention used by many Go projects
  3. Makes it obvious in logs and user agents when a development build is being used

Let's verify if the version is being properly set during build:

✅ Verification successful

Let me verify if the version is used in the Terraform user agent by searching for its usage.


Enhance version documentation and update default version

The version is indeed used in the Terraform user agent string (pkg/config/config.go) and is properly set during builds via ldflags in multiple places (Makefile, build.sh, and .goreleaser.yml). The suggested improvements are valid and beneficial:

-// Version holds the current version of the Atmos CLI.
-// It can be set dynamically during build time using ldflags.
-var Version = "0.0.1" // Default version; will be overridden during build
+// Version holds the current version of the Atmos CLI.
+// It can be set dynamically during build time using ldflags.
+// This version is used in various places including the Terraform user agent string
+// to identify requests made by Atmos.
+//
+// Example build command:
+// go build -ldflags "-X github.com/cloudposse/atmos/pkg/version.Version=1.2.3"
+var Version = "dev" // Default version for development; will be overridden during build
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if version is being set in build configuration

# Test 1: Check Makefile for version setting
echo "Checking Makefile for version setting:"
rg -A 2 "ldflags.*version.Version" 

# Test 2: Check .goreleaser.yml for version setting
echo "Checking .goreleaser.yml for version configuration:"
rg -A 2 "ldflags" .goreleaser.yml

Length of output: 1145


Script:

#!/bin/bash
# Search for Version usage in terraform-related code
rg -B 2 -A 2 "Version" --type go | grep -v "^version.go"

# Search specifically for user agent configuration
rg -B 2 -A 2 "UserAgent|User-Agent" --type go

Length of output: 14350

build.sh (1)

5-5: LGTM! Good package organization.

The change to move version information from cmd to a dedicated version package follows good separation of concerns and aligns with Go best practices. This restructuring will make version management more maintainable, especially for the new Terraform user agent feature.

Let's verify the version package structure:

✅ Verification successful

The version package restructuring is correctly implemented

The verification confirms that:

  • The version information has been properly moved to a dedicated package at pkg/version/version.go
  • All necessary imports and references have been updated across the codebase
  • The build flags in build.sh, Makefile, and .goreleaser.yml correctly reference the new version package path
  • The version variable is properly used in user agent strings and CLI version display
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the version package structure and usage

# Test 1: Check if version package exists
echo "Checking version package structure..."
fd --type f "^.*\.go$" version/

# Test 2: Check version usage across codebase
echo "Checking version usage..."
rg "version\.Version" --type go

Length of output: 942


Script:

#!/bin/bash
# Let's check the actual structure and content of version-related files

# Check for any Go files containing "Version" declaration
echo "Checking Version variable declarations..."
ast-grep --pattern 'var Version string'

# Check imports of the version package
echo "Checking version package imports..."
rg '^import.*".*version"' --type go

# Check if version might be in a different directory
echo "Searching for version-related Go files..."
fd -e go -x grep -l "Version.*string" {}

Length of output: 508


Script:

#!/bin/bash
# Let's examine the actual version-related code structure

# Check the content of files that might contain version information
echo "Checking content of potential version files..."
rg "var Version" --type go -C 3

# Check the git history to see if version package was recently moved or added
echo "Checking recent version-related changes..."
git log -p --grep="version" -n 1

# Check if version might be defined in a different way
echo "Checking other version declarations..."
ast-grep --pattern 'Version = $_'

Length of output: 6269

Makefile (1)

21-21: LGTM! Good architectural improvement.

Moving the version information to a dedicated pkg/version package improves the separation of concerns and makes it more accessible for features like the custom user agent.

Let's verify the version package exists:

✅ Verification successful

Let me check the content of the version package to verify the Version variable declaration, as the previous ast-grep pattern might have been too strict.


✅ Version package and variable verified successfully

The pkg/version package exists with the correct Version variable that will be populated during build time via ldflags, confirming this is a valid architectural improvement.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the version package and its Version variable

# Test 1: Check if the version package exists
fd --type f "^.*\.go$" "pkg/version"

# Test 2: Verify the Version variable declaration
ast-grep --pattern 'var Version string'

Length of output: 101


Script:

#!/bin/bash
# Check the content of version.go and look for Version variable with more flexible patterns
cat pkg/version/version.go

# Alternative pattern matching for Version variable
ast-grep --pattern 'var Version = $_'
ast-grep --pattern 'var Version $_'

Length of output: 413

cmd/version.go (2)

13-13: LGTM! Clean version package import.

The addition of the version package import follows Go conventions and supports centralized version management.


29-29: LGTM! Version usage properly refactored.

The changes effectively utilize the centralized version from the version package while maintaining all existing functionality. This refactoring supports the broader goal of implementing consistent version reporting across the application, including the new Terraform user agent feature.

Also applies to: 36-36

.goreleaser.yml (1)

26-26: LGTM! Verify version import path consistency.

The move to a dedicated version package is a good practice for better code organization.

Let's verify that all version references have been updated consistently:

✅ Verification successful

Let me gather more information to ensure all version-related code has been properly migrated.


Let me check the content of these version-related files to ensure proper migration.


Version package migration is complete and consistent

The verification confirms that:

  • The version declaration has been properly moved to pkg/version/version.go
  • The old cmd.Version is no longer used anywhere in the codebase
  • The new pkg/version.Version is consistently referenced in build files (Makefile, goreleaser.yml)
  • The cmd/version.go command properly imports and uses the new version package
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining references to the old version import path
# and confirm the new version package is properly referenced.

# Test 1: Check for any remaining references to the old version path
echo "Checking for old version path references..."
rg "github.com/cloudposse/atmos/cmd\.Version"

# Test 2: Verify the new version path is used consistently
echo "Verifying new version path usage..."
rg "github.com/cloudposse/atmos/pkg/version\.Version"

Length of output: 604


Script:

#!/bin/bash
# Let's check for any version-related code in both old and new locations
# and verify the complete migration

# Check for version-related files in cmd directory
echo "Checking version files in cmd directory..."
fd "version" "cmd"

# Check for version-related files in pkg directory
echo "Checking version files in pkg directory..."
fd "version" "pkg"

# Look for any version-related imports or references
echo "Checking version-related imports..."
rg -l "\"version\"" --type go

# Check for any Version variable declarations
echo "Checking Version variable declarations..."
ast-grep --pattern 'var Version string'

Length of output: 556


Script:

#!/bin/bash
# Check the content of version-related files

echo "Content of cmd/version.go:"
cat cmd/version.go

echo -e "\nContent of pkg/version/version.go:"
cat pkg/version/version.go

echo -e "\nChecking for version imports in cmd/version.go:"
rg "import.*version" cmd/version.go -A 5

Length of output: 1811

pkg/config/const.go (1)

30-30: LGTM! Verify constant usage.

The new constant follows the established naming and value patterns for CLI flags.

Let's verify how this constant is being used:

✅ Verification successful

Constant is properly integrated and used

The AppendUserAgentFlag constant is correctly integrated into the codebase:

  • Added to the list of common flags
  • Properly handled in argument parsing with both formats (--append-user-agent value and --append-user-agent=value)
  • Value is stored in info.AppendUserAgent for further processing
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of AppendUserAgentFlag constant
# Expected: Should be used in command-line processing and Terraform execution

# Test 1: Find direct references to the constant
rg -l "AppendUserAgentFlag"

# Test 2: Find any hardcoded instances of the flag that should use the constant instead
rg -l -- "--append-user-agent"

Length of output: 121


Script:

#!/bin/bash
# Let's check how the constant is used in internal/exec/utils.go
rg -A 5 -B 5 "AppendUserAgentFlag" internal/exec/utils.go

Length of output: 906

pkg/config/config.go (2)

19-19: LGTM! Good use of version package.

The addition of the version package import enables dynamic version number usage, which is the right approach.


47-47: LGTM! Follows recommended user agent format.

The user agent format follows the recommended pattern and correctly uses dynamic versioning.

internal/exec/terraform.go (1)

258-266: 🧹 Nitpick (assertive)

LGTM! Consider adding string trimming and format validation.

The implementation correctly handles the precedence chain for the user agent (ENV var > atmos.yaml > default). However, consider these improvements:

  1. Add string trimming to handle potential whitespace:
-	appendUserAgent := cliConfig.Components.Terraform.AppendUserAgent
+	appendUserAgent := strings.TrimSpace(cliConfig.Components.Terraform.AppendUserAgent)
-	if envUA, exists := os.LookupEnv("TF_APPEND_USER_AGENT"); exists && envUA != "" {
+	if envUA, exists := os.LookupEnv("TF_APPEND_USER_AGENT"); exists && strings.TrimSpace(envUA) != "" {
-		appendUserAgent = envUA
+		appendUserAgent = strings.TrimSpace(envUA)
  1. Add validation for the user agent format:
 	if appendUserAgent != "" {
+		// Validate format: "Atmos/1.181 (Cloud Posse; +https://atmos.tools)"
+		if !strings.HasPrefix(appendUserAgent, "Atmos/") {
+			return fmt.Errorf("invalid user agent format: %s. Expected format: Atmos/VERSION (Cloud Posse; +https://atmos.tools)", appendUserAgent)
+		}
 		info.ComponentEnvList = append(info.ComponentEnvList, fmt.Sprintf("TF_APPEND_USER_AGENT=%s", appendUserAgent))
 	}

Let's verify the user agent format in the codebase:

pkg/config/utils.go (1)

330-334: LGTM! Implementation aligns with PR objectives.

The environment variable handling follows the established pattern in the codebase and correctly implements the custom user agent functionality for Terraform providers.

pkg/schema/schema.go (2)

65-65: LGTM! Field addition for user agent configuration.

The AppendUserAgent field in the Terraform struct is well-placed and properly tagged for YAML/JSON/mapstructure serialization, allowing users to configure the Terraform user agent through configuration files.


136-136: LGTM! Field addition for CLI-based user agent override.

The AppendUserAgent field in the ArgsAndFlagsInfo struct enables CLI-based override of the Terraform user agent, providing flexibility in how the user agent is specified.

internal/exec/utils.go (1)

38-38: LGTM: AppendUserAgentFlag added to commonFlags.

The flag is correctly added to the list of common flags that Atmos processes internally.

pkg/version/version.go Show resolved Hide resolved
build.sh Show resolved Hide resolved
website/docs/quick-start/install-atmos.mdx Show resolved Hide resolved
pkg/config/config.go Show resolved Hide resolved
pkg/config/config.go Show resolved Hide resolved
internal/exec/utils.go Outdated Show resolved Hide resolved
Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

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

@Cerebrovinny thanks, looks good.

Please update the docs:

Please update the help:

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 5bc2111 and 9a7886d.

📒 Files selected for processing (2)
  • internal/exec/help.go (1 hunks)
  • website/src/components/Screengrabs/atmos-terraform--help.html (1 hunks)

internal/exec/help.go Outdated Show resolved Hide resolved
@aknysh aknysh added the minor New features that do not break anything label Oct 27, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 265e768 and e07c435.

📒 Files selected for processing (1)
  • website/docs/core-concepts/projects/configuration/terraform.mdx (1 hunks)

internal/exec/help.go Outdated Show resolved Hide resolved
internal/exec/help.go Outdated Show resolved Hide resolved
Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

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

@Cerebrovinny LGTM, a few nitpicks

@aknysh aknysh added no-release Do not create a new release (wait for additional code changes) and removed minor New features that do not break anything labels Oct 27, 2024
@aknysh aknysh changed the title Set custom user agent for Terraform providers Set custom User Agent for Terraform providers Oct 27, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between e07c435 and 2e1de82.

📒 Files selected for processing (1)
  • internal/exec/help.go (1 hunks)

internal/exec/help.go Outdated Show resolved Hide resolved
Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

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

thanks @Cerebrovinny

@aknysh aknysh added minor New features that do not break anything and removed no-release Do not create a new release (wait for additional code changes) labels Oct 29, 2024
@aknysh aknysh merged commit a48ed22 into main Oct 29, 2024
25 of 26 checks passed
@aknysh aknysh deleted the feat/dev-2337 branch October 29, 2024 05:28
Copy link

These changes were released in v1.96.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor New features that do not break anything
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants