chore(provisioner/terraform): preserve existing AWS_SDK_UA_APP_ID (#24606) by DevelopmentCats · Pull Request #26474 · coder/coder · GitHub
Skip to content
Merged
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
2 changes: 1 addition & 1 deletion provisioner/terraform/provision.go
36 changes: 36 additions & 0 deletions provisioner/terraform/safeenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,39 @@ func safeEnviron() []string {
}
return strippedEnv
}

// safeEnvironValue returns the value of the named variable in the given
// `KEY=VALUE` environment slice, or an empty string if it is not present.
func safeEnvironValue(env []string, name string) string {
prefix := name + "="
for _, e := range env {
if strings.HasPrefix(e, prefix) {
return strings.TrimPrefix(e, prefix)
}
}
return ""
}
Comment on lines +59 to +67

const (
awsSDKUserAgentEnvKey = "AWS_SDK_UA_APP_ID"
// awsSDKUserAgentCoder is Coder's AWS Partner Revenue Measurement
// User-Agent string. The `APN_1.1/pc_<product-code>$` format and the
// space-delimited append behavior below follow AWS's guidance:
// https://docs.aws.amazon.com/PRM/latest/aws-prm-onboarding-guide/automated-user-agent.html
awsSDKUserAgentCoder = "APN_1.1/pc_cdfmjwn8i6u8l9fwz8h82e4w3$"
)

// awsSDKUserAgentEnv returns the AWS_SDK_UA_APP_ID value to pass to the
// Terraform subprocess. If the caller's environment already configures an
// Application ID (e.g. an operator who is also an AWS Partner and wants
// their own revenue attribution), Coder's value is appended with a space
// delimiter so both attributions are preserved. Otherwise Coder's value is
// used on its own.
//
// See: https://docs.aws.amazon.com/PRM/latest/aws-prm-onboarding-guide/automated-user-agent.html
func awsSDKUserAgentEnv(existing string) string {
if existing == "" {
return awsSDKUserAgentEnvKey + "=" + awsSDKUserAgentCoder
}
return awsSDKUserAgentEnvKey + "=" + existing + " " + awsSDKUserAgentCoder
}
44 changes: 44 additions & 0 deletions provisioner/terraform/safeenv_internal_test.go
Loading