From d8809da29c3f83369512514e6ab772c50e29a502 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Sat, 19 Oct 2024 14:00:39 +0100 Subject: [PATCH 01/16] feat: extend terraform schema for append user agent --- pkg/schema/schema.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/schema/schema.go b/pkg/schema/schema.go index d77dd9213..8c4a6dcbf 100644 --- a/pkg/schema/schema.go +++ b/pkg/schema/schema.go @@ -62,6 +62,7 @@ type TemplatesSettingsGomplate struct { type Terraform struct { BasePath string `yaml:"base_path" json:"base_path" mapstructure:"base_path"` ApplyAutoApprove bool `yaml:"apply_auto_approve" json:"apply_auto_approve" mapstructure:"apply_auto_approve"` + AppendUserAgent string `yaml:"append_user_agent" json:"append_user_agent" mapstructure:"append_user_agent"` DeployRunInit bool `yaml:"deploy_run_init" json:"deploy_run_init" mapstructure:"deploy_run_init"` InitRunReconfigure bool `yaml:"init_run_reconfigure" json:"init_run_reconfigure" mapstructure:"init_run_reconfigure"` AutoGenerateBackendFile bool `yaml:"auto_generate_backend_file" json:"auto_generate_backend_file" mapstructure:"auto_generate_backend_file"` From fef015e7da412a7d8099c72db46fda6c84e843de Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Sat, 19 Oct 2024 14:43:34 +0100 Subject: [PATCH 02/16] Set custom user agent for terraform #2335 --- internal/exec/terraform.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/exec/terraform.go b/internal/exec/terraform.go index 1d2314100..333b256bd 100644 --- a/internal/exec/terraform.go +++ b/internal/exec/terraform.go @@ -255,6 +255,13 @@ func ExecuteTerraform(info schema.ConfigAndStacksInfo) error { // https://developer.hashicorp.com/terraform/cli/config/environment-variables#tf_in_automation info.ComponentEnvList = append(info.ComponentEnvList, "TF_IN_AUTOMATION=true") + if strings.TrimSpace(cliConfig.Components.Terraform.AppendUserAgent) != "" { + info.ComponentEnvList = append( + info.ComponentEnvList, + fmt.Sprintf("TF_APPEND_USER_AGENT=%s", strings.TrimSpace(cliConfig.Components.Terraform.AppendUserAgent)), + ) + } + // Print ENV vars if they are found in the component's stack config if len(info.ComponentEnvList) > 0 { u.LogDebug(cliConfig, "\nUsing ENV vars:") From 79374be43d7bc09958ee76950217ce9a1b3872b6 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Sat, 19 Oct 2024 18:29:48 +0100 Subject: [PATCH 03/16] fix: trim user aggent in append user --- internal/exec/terraform.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/exec/terraform.go b/internal/exec/terraform.go index 333b256bd..4aab23937 100644 --- a/internal/exec/terraform.go +++ b/internal/exec/terraform.go @@ -255,10 +255,11 @@ func ExecuteTerraform(info schema.ConfigAndStacksInfo) error { // https://developer.hashicorp.com/terraform/cli/config/environment-variables#tf_in_automation info.ComponentEnvList = append(info.ComponentEnvList, "TF_IN_AUTOMATION=true") - if strings.TrimSpace(cliConfig.Components.Terraform.AppendUserAgent) != "" { + trimmedUserAgent := strings.TrimSpace(cliConfig.Components.Terraform.AppendUserAgent) + if len(trimmedUserAgent) > 0 { info.ComponentEnvList = append( info.ComponentEnvList, - fmt.Sprintf("TF_APPEND_USER_AGENT=%s", strings.TrimSpace(cliConfig.Components.Terraform.AppendUserAgent)), + fmt.Sprintf("TF_APPEND_USER_AGENT=%s", trimmedUserAgent), ) } From 9c8d604b2efac7105c4a14936ee09c7f588cd218 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Sun, 20 Oct 2024 18:33:17 +0100 Subject: [PATCH 04/16] feat: adding user aggent for terraform second step --- internal/exec/terraform.go | 14 ++++++++------ pkg/config/config.go | 1 + pkg/config/utils.go | 6 ++++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/internal/exec/terraform.go b/internal/exec/terraform.go index 4aab23937..93b272e1a 100644 --- a/internal/exec/terraform.go +++ b/internal/exec/terraform.go @@ -255,12 +255,14 @@ func ExecuteTerraform(info schema.ConfigAndStacksInfo) error { // https://developer.hashicorp.com/terraform/cli/config/environment-variables#tf_in_automation info.ComponentEnvList = append(info.ComponentEnvList, "TF_IN_AUTOMATION=true") - trimmedUserAgent := strings.TrimSpace(cliConfig.Components.Terraform.AppendUserAgent) - if len(trimmedUserAgent) > 0 { - info.ComponentEnvList = append( - info.ComponentEnvList, - fmt.Sprintf("TF_APPEND_USER_AGENT=%s", trimmedUserAgent), - ) + // Set 'TF_APPEND_USER_AGENT' ENV var based on precedence + // Precedence: Environment Variable > atmos.yaml > Default + appendUserAgent := cliConfig.Components.Terraform.AppendUserAgent + if envUA, exists := os.LookupEnv("TF_APPEND_USER_AGENT"); exists && envUA != "" { + appendUserAgent = envUA + } + if appendUserAgent != "" { + info.ComponentEnvList = append(info.ComponentEnvList, fmt.Sprintf("TF_APPEND_USER_AGENT=%s", appendUserAgent)) } // Print ENV vars if they are found in the component's stack config diff --git a/pkg/config/config.go b/pkg/config/config.go index 63014bf4d..814061159 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -43,6 +43,7 @@ var ( DeployRunInit: true, InitRunReconfigure: true, AutoGenerateBackendFile: true, + AppendUserAgent: "Cloud Posse Atmos v1.181 (https://atmos.tools)", }, Helmfile: schema.Helmfile{ BasePath: "components/helmfile", diff --git a/pkg/config/utils.go b/pkg/config/utils.go index bd916b2bb..7cc2653d4 100644 --- a/pkg/config/utils.go +++ b/pkg/config/utils.go @@ -327,6 +327,12 @@ func processEnvVars(cliConfig *schema.CliConfiguration) error { cliConfig.Logs.Level = logsLevel } + tfAppendUserAgent := os.Getenv("TF_APPEND_USER_AGENT") + if len(tfAppendUserAgent) > 0 { + u.LogTrace(*cliConfig, fmt.Sprintf("Found ENV var TF_APPEND_USER_AGENT=%s", tfAppendUserAgent)) + cliConfig.Components.Terraform.AppendUserAgent = tfAppendUserAgent + } + listMergeStrategy := os.Getenv("ATMOS_SETTINGS_LIST_MERGE_STRATEGY") if len(listMergeStrategy) > 0 { u.LogTrace(*cliConfig, fmt.Sprintf("Found ENV var ATMOS_SETTINGS_LIST_MERGE_STRATEGY=%s", listMergeStrategy)) From 2424c96388ffa889686fb05ad7a38d2340cdc74c Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Thu, 24 Oct 2024 21:46:23 +0100 Subject: [PATCH 05/16] added new pkg version for more modular packages --- .goreleaser.yml | 2 +- Makefile | 2 +- build.sh | 2 +- cmd/version.go | 7 +++---- pkg/config/config.go | 9 ++++++++- pkg/version/version.go | 5 +++++ website/docs/quick-start/install-atmos.mdx | 2 +- 7 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 pkg/version/version.go diff --git a/.goreleaser.yml b/.goreleaser.yml index da036881b..4e4903ce5 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -23,7 +23,7 @@ builds: binary: atmos ldflags: # Set `atmos` version to the GitHub release tag using Go `ldflags` - - '-s -w -X "github.com/cloudposse/atmos/cmd.Version={{.Version}}"' + - '-s -w -X "github.com/cloudposse/atmos/pkg/version.Version={{.Version}}"' archives: - format: binary diff --git a/Makefile b/Makefile index bc12271ec..f90a5e578 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ get: go get build: get - env $(if $(GOOS),GOOS=$(GOOS)) $(if $(GOARCH),GOARCH=$(GOARCH)) go build -o build/atmos -v -ldflags "-X 'github.com/cloudposse/atmos/cmd.Version=${VERSION}'" + env $(if $(GOOS),GOOS=$(GOOS)) $(if $(GOARCH),GOARCH=$(GOARCH)) go build -o build/atmos -v -ldflags "-X 'github.com/cloudposse/atmos/pkg/version.Version=${VERSION}'" version: build chmod +x ./build/atmos diff --git a/build.sh b/build.sh index 309ee4de9..cf740b48a 100755 --- a/build.sh +++ b/build.sh @@ -2,7 +2,7 @@ version="0.0.1" -go build -o build/atmos -v -ldflags "-X 'github.com/cloudposse/atmos/cmd.Version=$version'" +go build -o build/atmos -v -ldflags "-X 'github.com/cloudposse/atmos/version.Version=$version'" # https://www.digitalocean.com/community/tutorials/using-ldflags-to-set-version-information-for-go-applications # https://blog.kowalczyk.info/article/vEja/embedding-build-number-in-go-executable.html diff --git a/cmd/version.go b/cmd/version.go index f2005dd91..ba70483ea 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -10,10 +10,9 @@ import ( tuiUtils "github.com/cloudposse/atmos/internal/tui/utils" "github.com/cloudposse/atmos/pkg/schema" u "github.com/cloudposse/atmos/pkg/utils" + "github.com/cloudposse/atmos/pkg/version" ) -var Version = "0.0.1" - var versionCmd = &cobra.Command{ Use: "version", Short: "Print the CLI version", @@ -27,14 +26,14 @@ var versionCmd = &cobra.Command{ u.LogErrorAndExit(schema.CliConfiguration{}, err) } - u.PrintMessage(fmt.Sprintf("\U0001F47D Atmos %s on %s/%s", Version, runtime.GOOS, runtime.GOARCH)) + u.PrintMessage(fmt.Sprintf("\U0001F47D Atmos %s on %s/%s", version.Version, runtime.GOOS, runtime.GOARCH)) fmt.Println() // Check for the latest Atmos release on GitHub latestReleaseTag, err := u.GetLatestGitHubRepoRelease("cloudposse", "atmos") if err == nil && latestReleaseTag != "" { latestRelease := strings.TrimPrefix(latestReleaseTag, "v") - currentRelease := strings.TrimPrefix(Version, "v") + currentRelease := strings.TrimPrefix(version.Version, "v") if latestRelease != currentRelease { printMessageToUpgradeToAtmosLatestRelease(latestRelease) } diff --git a/pkg/config/config.go b/pkg/config/config.go index 814061159..937efb639 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -16,6 +16,7 @@ import ( "github.com/cloudposse/atmos/pkg/schema" u "github.com/cloudposse/atmos/pkg/utils" + "github.com/cloudposse/atmos/pkg/version" ) var ( @@ -43,7 +44,7 @@ var ( DeployRunInit: true, InitRunReconfigure: true, AutoGenerateBackendFile: true, - AppendUserAgent: "Cloud Posse Atmos v1.181 (https://atmos.tools)", + AppendUserAgent: fmt.Sprintf("Atmos/%s (Cloud Posse; +https://atmos.tools)", version.Version), }, Helmfile: schema.Helmfile{ BasePath: "components/helmfile", @@ -106,6 +107,7 @@ func InitCliConfig(configAndStacksInfo schema.ConfigAndStacksInfo, processStacks // Default configuration values v.SetDefault("components.helmfile.use_eks", true) + v.SetDefault("components.terraform.append_user_agent", fmt.Sprintf("Atmos/%s (Cloud Posse; +https://atmos.tools)", version.Version)) // Process config in system folder configFilePath1 := "" @@ -244,6 +246,11 @@ func InitCliConfig(configAndStacksInfo schema.ConfigAndStacksInfo, processStacks cliConfig.BasePath = configAndStacksInfo.AtmosBasePath } + // After unmarshalling, ensure AppendUserAgent is set if still empty + if cliConfig.Components.Terraform.AppendUserAgent == "" { + cliConfig.Components.Terraform.AppendUserAgent = fmt.Sprintf("Atmos/%s (Cloud Posse; +https://atmos.tools)", version.Version) + } + // Check config err = checkConfig(cliConfig) if err != nil { diff --git a/pkg/version/version.go b/pkg/version/version.go new file mode 100644 index 000000000..7db05562c --- /dev/null +++ b/pkg/version/version.go @@ -0,0 +1,5 @@ +package version + +// 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 diff --git a/website/docs/quick-start/install-atmos.mdx b/website/docs/quick-start/install-atmos.mdx index 6ef0e0948..d436588ec 100644 --- a/website/docs/quick-start/install-atmos.mdx +++ b/website/docs/quick-start/install-atmos.mdx @@ -242,7 +242,7 @@ Atmos has native packages for macOS and every major Linux distribution. We also or run this and replace `$version` with the version that should be returned with `atmos version`. ```shell - go build -o build/atmos -v -ldflags "-X 'github.com/cloudposse/atmos/cmd.Version=$version'" + go build -o build/atmos -v -ldflags "-X 'github.com/cloudposse/atmos/pkg/version.Version=$version'" ``` From 60457664bb9940d662a2f9bb505647aaf8e08e07 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Thu, 24 Oct 2024 22:21:32 +0100 Subject: [PATCH 06/16] flag for user append agent --- internal/exec/utils.go | 16 ++++++++++++++++ pkg/config/const.go | 1 + pkg/schema/schema.go | 1 + 3 files changed, 18 insertions(+) diff --git a/internal/exec/utils.go b/internal/exec/utils.go index 0a4b662c2..c6200682b 100644 --- a/internal/exec/utils.go +++ b/internal/exec/utils.go @@ -35,6 +35,7 @@ var ( cfg.DeployRunInitFlag, cfg.InitRunReconfigure, cfg.AutoGenerateBackendFileFlag, + cfg.AppendUserAgentFlag, cfg.FromPlanFlag, cfg.PlanFileFlag, cfg.HelpFlag1, @@ -668,6 +669,21 @@ func processArgsAndFlags(componentType string, inputArgsAndFlags []string) (sche info.TerraformDir = terraformDirFlagParts[1] } + if arg == cfg.AppendUserAgentFlag { + if len(inputArgsAndFlags) <= (i + 1) { + return info, fmt.Errorf("invalid flag: %s requires a value", arg) + } + info.AppendUserAgent = inputArgsAndFlags[i+1] + indexesToRemove = append(indexesToRemove, i, i+1) + } else if strings.HasPrefix(arg+"=", cfg.AppendUserAgentFlag) { + parts := strings.SplitN(arg, "=", 2) + if len(parts) != 2 { + return info, fmt.Errorf("invalid flag: %s", arg) + } + info.AppendUserAgent = parts[1] + indexesToRemove = append(indexesToRemove, i) + } + if arg == cfg.HelmfileCommandFlag { if len(inputArgsAndFlags) <= (i + 1) { return info, fmt.Errorf("invalid flag: %s", arg) diff --git a/pkg/config/const.go b/pkg/config/const.go index 720f53507..924d97249 100644 --- a/pkg/config/const.go +++ b/pkg/config/const.go @@ -27,6 +27,7 @@ const ( DeployRunInitFlag = "--deploy-run-init" AutoGenerateBackendFileFlag = "--auto-generate-backend-file" + AppendUserAgentFlag = "--append-user-agent" InitRunReconfigure = "--init-run-reconfigure" FromPlanFlag = "--from-plan" diff --git a/pkg/schema/schema.go b/pkg/schema/schema.go index 8c4a6dcbf..89e90b061 100644 --- a/pkg/schema/schema.go +++ b/pkg/schema/schema.go @@ -133,6 +133,7 @@ type ArgsAndFlagsInfo struct { DeployRunInit string InitRunReconfigure string AutoGenerateBackendFile string + AppendUserAgent string UseTerraformPlan bool PlanFile string DryRun bool From 927cd75fb420ad87171e3b358ef4f40e1e11dadc Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Thu, 24 Oct 2024 22:42:12 +0100 Subject: [PATCH 07/16] improve error msg for append user flag --- internal/exec/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/exec/utils.go b/internal/exec/utils.go index c6200682b..54fae380c 100644 --- a/internal/exec/utils.go +++ b/internal/exec/utils.go @@ -671,7 +671,7 @@ func processArgsAndFlags(componentType string, inputArgsAndFlags []string) (sche if arg == cfg.AppendUserAgentFlag { if len(inputArgsAndFlags) <= (i + 1) { - return info, fmt.Errorf("invalid flag: %s requires a value", arg) + return info, fmt.Errorf("invalid flag: %s requires a value (e.g. %s 'Atmos/1.0' or %s='Atmos/1.0')", arg, arg, arg) } info.AppendUserAgent = inputArgsAndFlags[i+1] indexesToRemove = append(indexesToRemove, i, i+1) From 0a283afa31a935625799650a0fc98fbe3d97cf60 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Fri, 25 Oct 2024 14:50:39 +0100 Subject: [PATCH 08/16] added append user agent flag in docs --- internal/exec/help.go | 2 ++ website/src/components/Screengrabs/atmos-terraform--help.html | 1 + 2 files changed, 3 insertions(+) diff --git a/internal/exec/help.go b/internal/exec/help.go index bd168c6fa..84662f25a 100644 --- a/internal/exec/help.go +++ b/internal/exec/help.go @@ -45,6 +45,8 @@ func processHelp(componentType string, command string) error { u.PrintMessage(" - double-dash '--' can be used to signify the end of the options for Atmos and the start of the additional " + "native arguments and flags for the 'terraform' commands. " + "For example: atmos terraform plan -s -- -refresh=false -lock=false") + + u.PrintMessage(" - '--append-user-agent' flag allows you to customize the User-Agent string appended to Terraform requests for enhanced observability and traceability.\n") } if componentType == "helmfile" { diff --git a/website/src/components/Screengrabs/atmos-terraform--help.html b/website/src/components/Screengrabs/atmos-terraform--help.html index b5e69a3f6..84c3512f0 100644 --- a/website/src/components/Screengrabs/atmos-terraform--help.html +++ b/website/src/components/Screengrabs/atmos-terraform--help.html @@ -28,6 +28,7 @@ - 'atmos terraform generate varfile' command generates a varfile for an 'atmos' component in a stack - 'atmos terraform generate varfiles' command generates varfiles for all 'atmos' components in all stacks - 'atmos terraform shell' command configures an environment for an 'atmos' component in a stack and starts a new shell allowing executing all native terraform commands inside the shell without using atmos-specific arguments and flags + - `--append-user-agent` flag allows you to customize the User-Agent string appended to Terraform requests for enhanced observability and traceability. - double-dash '--' can be used to signify the end of the options for Atmos and the start of the additional native arguments and flags for the 'terraform' commands. For example: atmos terraform plan <component> -s <stack> -- -refresh=false -lock=false Usage: terraform [global options] <subcommand> [args] From 8baed95d98f07844ecfbbd9e314a43824dde8342 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Fri, 25 Oct 2024 20:53:01 +0100 Subject: [PATCH 09/16] update print append user aggent message --- internal/exec/help.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/exec/help.go b/internal/exec/help.go index 84662f25a..c088856ef 100644 --- a/internal/exec/help.go +++ b/internal/exec/help.go @@ -46,7 +46,9 @@ func processHelp(componentType string, command string) error { "native arguments and flags for the 'terraform' commands. " + "For example: atmos terraform plan -s -- -refresh=false -lock=false") - u.PrintMessage(" - '--append-user-agent' flag allows you to customize the User-Agent string appended to Terraform requests for enhanced observability and traceability.\n") + u.PrintMessage(" - '--append-user-agent' flag sets TF_APPEND_USER_AGENT environment variable to customize the User-Agent string in Terraform provider requests. " + + "The recommended format is 'Atmos/ (Cloud Posse; +https://atmos.tools)' for enhanced observability and traceability.\n") + } if componentType == "helmfile" { From 8370d5c84f50f92da70a7b2f0b7bec03557f73f2 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Fri, 25 Oct 2024 21:08:51 +0100 Subject: [PATCH 10/16] add append user agent to atmos yaml and rename it --- atmos.yaml | 2 ++ internal/exec/help.go | 2 +- pkg/config/utils.go | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/atmos.yaml b/atmos.yaml index 5fa3fb3c0..a1e7d0c77 100644 --- a/atmos.yaml +++ b/atmos.yaml @@ -40,6 +40,8 @@ components: init_run_reconfigure: true # Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_AUTO_GENERATE_BACKEND_FILE' ENV var, or '--auto-generate-backend-file' command-line argument auto_generate_backend_file: false + # Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_APPEND_USER_AGENT' ENV var, or '--append-user-agent' command-line argument + append_user_agent: "Atmos/ (Cloud Posse; +https://atmos.tools)" helmfile: # Can also be set using 'ATMOS_COMPONENTS_HELMFILE_BASE_PATH' ENV var, or '--helmfile-dir' command-line argument # Supports both absolute and relative paths diff --git a/internal/exec/help.go b/internal/exec/help.go index c088856ef..6308daae0 100644 --- a/internal/exec/help.go +++ b/internal/exec/help.go @@ -46,7 +46,7 @@ func processHelp(componentType string, command string) error { "native arguments and flags for the 'terraform' commands. " + "For example: atmos terraform plan -s -- -refresh=false -lock=false") - u.PrintMessage(" - '--append-user-agent' flag sets TF_APPEND_USER_AGENT environment variable to customize the User-Agent string in Terraform provider requests. " + + u.PrintMessage(" - '--append-user-agent' flag sets ATMOS_COMPONENTS_TERRAFORM_APPEND_USER_AGENT environment variable to customize the User-Agent string in Terraform provider requests. " + "The recommended format is 'Atmos/ (Cloud Posse; +https://atmos.tools)' for enhanced observability and traceability.\n") } diff --git a/pkg/config/utils.go b/pkg/config/utils.go index 7cc2653d4..d6a20036e 100644 --- a/pkg/config/utils.go +++ b/pkg/config/utils.go @@ -327,9 +327,9 @@ func processEnvVars(cliConfig *schema.CliConfiguration) error { cliConfig.Logs.Level = logsLevel } - tfAppendUserAgent := os.Getenv("TF_APPEND_USER_AGENT") + tfAppendUserAgent := os.Getenv("ATMOS_COMPONENTS_TERRAFORM_APPEND_USER_AGENT") if len(tfAppendUserAgent) > 0 { - u.LogTrace(*cliConfig, fmt.Sprintf("Found ENV var TF_APPEND_USER_AGENT=%s", tfAppendUserAgent)) + u.LogTrace(*cliConfig, fmt.Sprintf("Found ENV var ATMOS_COMPONENTS_TERRAFORM_APPEND_USER_AGENT=%s", tfAppendUserAgent)) cliConfig.Components.Terraform.AppendUserAgent = tfAppendUserAgent } From 40674a449998701430ab1c922a6195f7866c9efc Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Fri, 25 Oct 2024 21:34:30 +0100 Subject: [PATCH 11/16] updated usage terraform docs --- website/docs/cli/commands/terraform/usage.mdx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/website/docs/cli/commands/terraform/usage.mdx b/website/docs/cli/commands/terraform/usage.mdx index 096909fee..66cb70c4a 100644 --- a/website/docs/cli/commands/terraform/usage.mdx +++ b/website/docs/cli/commands/terraform/usage.mdx @@ -114,6 +114,8 @@ atmos terraform workspace test/test-component-override-3 -s tenant1-ue2-dev --re atmos terraform workspace test/test-component-override-3 -s tenant1-ue2-dev --redirect-stderr ./errors.txt atmos terraform plan test/test-component -s tenant1-ue2-dev -- -refresh=false -lock=false + +atmos terraform plan test/test-component -s tenant1-ue2-dev --append-user-agent "Atmos/1.0.0 (Cloud Posse; +https://atmos.tools)" ``` ## Arguments @@ -124,12 +126,12 @@ atmos terraform plan test/test-component -s tenant1-ue2-dev -- -refresh=false -l ## Flags -| Flag | Description | Alias | Required | -| :------------------ | :-------------------------------------------------------------------------------------------------------------------------------------------- | :---- | :------- | -| `--stack` | Atmos stack | `-s` | yes | -| `--dry-run` | Dry run | | no | -| `--redirect-stderr` | File descriptor to redirect `stderr` to.
Errors can be redirected to any file or any standard file descriptor
(including `/dev/null`) | | no | - +| Flag | Description | Alias | Required | +| :------------------ | :-------------------------------------------------------------------------------------------------------------------------------------------- | :---- | :------- | +| `--stack` | Atmos stack | `-s` | yes | +| `--dry-run` | Dry run | | no | +| `--redirect-stderr` | File descriptor to redirect `stderr` to.
Errors can be redirected to any file or any standard file descriptor
(including `/dev/null`) | | no | +| `--append-user-agent` | Append a custom User-Agent to Terraform requests. Can also be set using the ATMOS_COMPONENTS_TERRAFORM_APPEND_USER_AGENT environment variable.| | no |
:::note From 9b697faf574a7d72009f91cbe76fc90f6253cc59 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Fri, 25 Oct 2024 21:38:26 +0100 Subject: [PATCH 12/16] utils flag standard for append user agent --- internal/exec/utils.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/internal/exec/utils.go b/internal/exec/utils.go index 54fae380c..bf82b2ea4 100644 --- a/internal/exec/utils.go +++ b/internal/exec/utils.go @@ -671,17 +671,15 @@ func processArgsAndFlags(componentType string, inputArgsAndFlags []string) (sche if arg == cfg.AppendUserAgentFlag { if len(inputArgsAndFlags) <= (i + 1) { - return info, fmt.Errorf("invalid flag: %s requires a value (e.g. %s 'Atmos/1.0' or %s='Atmos/1.0')", arg, arg, arg) + return info, fmt.Errorf("invalid flag: %s", arg) } info.AppendUserAgent = inputArgsAndFlags[i+1] - indexesToRemove = append(indexesToRemove, i, i+1) } else if strings.HasPrefix(arg+"=", cfg.AppendUserAgentFlag) { - parts := strings.SplitN(arg, "=", 2) - if len(parts) != 2 { + var appendUserAgentFlagParts = strings.Split(arg, "=") + if len(appendUserAgentFlagParts) != 2 { return info, fmt.Errorf("invalid flag: %s", arg) } - info.AppendUserAgent = parts[1] - indexesToRemove = append(indexesToRemove, i) + info.AppendUserAgent = appendUserAgentFlagParts[1] } if arg == cfg.HelmfileCommandFlag { From 265e768cea741e239e87dca65e22c1580584e49e Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Fri, 25 Oct 2024 22:32:12 +0100 Subject: [PATCH 13/16] added generic data for append user agent command docs --- website/docs/cli/commands/terraform/usage.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/cli/commands/terraform/usage.mdx b/website/docs/cli/commands/terraform/usage.mdx index 66cb70c4a..94709912b 100644 --- a/website/docs/cli/commands/terraform/usage.mdx +++ b/website/docs/cli/commands/terraform/usage.mdx @@ -115,7 +115,7 @@ atmos terraform workspace test/test-component-override-3 -s tenant1-ue2-dev --re atmos terraform plan test/test-component -s tenant1-ue2-dev -- -refresh=false -lock=false -atmos terraform plan test/test-component -s tenant1-ue2-dev --append-user-agent "Atmos/1.0.0 (Cloud Posse; +https://atmos.tools)" +atmos terraform plan test/test-component -s tenant1-ue2-dev --append-user-agent "Acme/1.0 (Build 1234; arm64)" ``` ## Arguments From e07c435bf1a57f4f847d3be923ca09aefc2cb084 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Fri, 25 Oct 2024 22:42:55 +0100 Subject: [PATCH 14/16] user append flag docs added --- atmos.yaml | 2 -- website/docs/core-concepts/projects/configuration/terraform.mdx | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/atmos.yaml b/atmos.yaml index a1e7d0c77..5fa3fb3c0 100644 --- a/atmos.yaml +++ b/atmos.yaml @@ -40,8 +40,6 @@ components: init_run_reconfigure: true # Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_AUTO_GENERATE_BACKEND_FILE' ENV var, or '--auto-generate-backend-file' command-line argument auto_generate_backend_file: false - # Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_APPEND_USER_AGENT' ENV var, or '--append-user-agent' command-line argument - append_user_agent: "Atmos/ (Cloud Posse; +https://atmos.tools)" helmfile: # Can also be set using 'ATMOS_COMPONENTS_HELMFILE_BASE_PATH' ENV var, or '--helmfile-dir' command-line argument # Supports both absolute and relative paths diff --git a/website/docs/core-concepts/projects/configuration/terraform.mdx b/website/docs/core-concepts/projects/configuration/terraform.mdx index 4a01b45fc..4ddd0a849 100644 --- a/website/docs/core-concepts/projects/configuration/terraform.mdx +++ b/website/docs/core-concepts/projects/configuration/terraform.mdx @@ -38,6 +38,8 @@ components: init_run_reconfigure: true # Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_AUTO_GENERATE_BACKEND_FILE' ENV var, or '--auto-generate-backend-file' command-line argument auto_generate_backend_file: false + # Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_APPEND_USER_AGENT' ENV var, or '--append-user-agent' command-line argument + append_user_agent: "Acme/1.0 (Build 1234; arm64)" ```
From 2e1de82473bb86e27a06ab452815fbf130785f48 Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Sun, 27 Oct 2024 09:58:44 +0000 Subject: [PATCH 15/16] feat: update help print message --- internal/exec/help.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/exec/help.go b/internal/exec/help.go index 6308daae0..86fcf9003 100644 --- a/internal/exec/help.go +++ b/internal/exec/help.go @@ -46,8 +46,8 @@ func processHelp(componentType string, command string) error { "native arguments and flags for the 'terraform' commands. " + "For example: atmos terraform plan -s -- -refresh=false -lock=false") - u.PrintMessage(" - '--append-user-agent' flag sets ATMOS_COMPONENTS_TERRAFORM_APPEND_USER_AGENT environment variable to customize the User-Agent string in Terraform provider requests. " + - "The recommended format is 'Atmos/ (Cloud Posse; +https://atmos.tools)' for enhanced observability and traceability.\n") + u.PrintMessage(" - '--append-user-agent' flag sets the TF_APPEND_USER_AGENT environment variable to customize the User-Agent string in Terraform provider requests. " + + "Example: 'Atmos/ (Cloud Posse; +https://atmos.tools)'\n") } From 455f9d8d08a8bb3ef0b16a8921ea3a1b1ed3a9de Mon Sep 17 00:00:00 2001 From: Cerebrovinny Date: Sun, 27 Oct 2024 17:11:37 +0000 Subject: [PATCH 16/16] feat: update help print message --- internal/exec/help.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/exec/help.go b/internal/exec/help.go index 86fcf9003..91b2b4e74 100644 --- a/internal/exec/help.go +++ b/internal/exec/help.go @@ -5,6 +5,7 @@ import ( "github.com/cloudposse/atmos/pkg/schema" u "github.com/cloudposse/atmos/pkg/utils" + "github.com/cloudposse/atmos/pkg/version" ) // processHelp processes help commands @@ -46,8 +47,9 @@ func processHelp(componentType string, command string) error { "native arguments and flags for the 'terraform' commands. " + "For example: atmos terraform plan -s -- -refresh=false -lock=false") - u.PrintMessage(" - '--append-user-agent' flag sets the TF_APPEND_USER_AGENT environment variable to customize the User-Agent string in Terraform provider requests. " + - "Example: 'Atmos/ (Cloud Posse; +https://atmos.tools)'\n") + u.PrintMessage(fmt.Sprintf(" - '--append-user-agent' flag sets the TF_APPEND_USER_AGENT environment variable to customize the User-Agent string in Terraform provider requests. "+ + "Example: 'Atmos/%s (Cloud Posse; +https://atmos.tools)'. "+ + "If not specified, defaults to 'atmos %s'\n", version.Version, version.Version)) }