10 "github.com/hashicorp/terraform/version"
13 const userAgentFormat = "Terraform/%s"
14 const uaEnvVar = "TF_APPEND_USER_AGENT"
16 func UserAgentString() string {
17 ua := fmt.Sprintf(userAgentFormat, version.Version)
19 if add := os.Getenv(uaEnvVar); add != "" {
20 add = strings.TrimSpace(add)
23 log.Printf("[DEBUG] Using modified User-Agent: %s", ua)
30 type userAgentRoundTripper struct {
31 inner http.RoundTripper
35 func (rt *userAgentRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
36 if _, ok := req.Header["User-Agent"]; !ok {
37 req.Header.Set("User-Agent", rt.userAgent)
39 return rt.inner.RoundTrip(req)