Skip to content

Commit 40c85a4

Browse files
committed
Use Terraform SDK UserAgent function
1 parent 9fcf005 commit 40c85a4

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

gitlab/config.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package gitlab
33
import (
44
"crypto/tls"
55
"crypto/x509"
6-
"fmt"
76
"io/ioutil"
87
"net/http"
98

@@ -13,13 +12,13 @@ import (
1312

1413
// Config is per-provider, specifies where to connect to gitlab
1514
type Config struct {
16-
Token string
17-
BaseURL string
18-
Insecure bool
19-
CACertFile string
20-
ClientCert string
21-
ClientKey string
22-
TerraformVersion string
15+
Token string
16+
BaseURL string
17+
Insecure bool
18+
CACertFile string
19+
ClientCert string
20+
ClientKey string
21+
TerraformUserAgent string
2322
}
2423

2524
// Client returns a *gitlab.Client to interact with the configured gitlab instance
@@ -64,7 +63,7 @@ func (c *Config) Client() (interface{}, error) {
6463
},
6564
),
6665
func(client *gitlab.Client) error {
67-
client.UserAgent = fmt.Sprintf("terraform-provider-gitlab/%s", c.TerraformVersion)
66+
client.UserAgent = c.TerraformUserAgent
6867
return nil
6968
},
7069
}

gitlab/provider.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"strings"
66

77
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
8+
"github.com/hashicorp/terraform-plugin-sdk/httpclient"
89
"github.com/hashicorp/terraform-plugin-sdk/terraform"
910
)
1011

@@ -122,13 +123,16 @@ func init() {
122123

123124
func providerConfigure(p *schema.Provider, d *schema.ResourceData) (interface{}, error) {
124125
config := Config{
125-
Token: d.Get("token").(string),
126-
BaseURL: d.Get("base_url").(string),
127-
CACertFile: d.Get("cacert_file").(string),
128-
Insecure: d.Get("insecure").(bool),
129-
ClientCert: d.Get("client_cert").(string),
130-
ClientKey: d.Get("client_key").(string),
131-
TerraformVersion: p.TerraformVersion,
126+
Token: d.Get("token").(string),
127+
BaseURL: d.Get("base_url").(string),
128+
CACertFile: d.Get("cacert_file").(string),
129+
Insecure: d.Get("insecure").(bool),
130+
ClientCert: d.Get("client_cert").(string),
131+
ClientKey: d.Get("client_key").(string),
132+
133+
// NOTE: httpclient.TerraformUserAgent is deprecated and removed in Terraform SDK v2
134+
// After upgrading the SDK to v2 replace with p.UserAgent()
135+
TerraformUserAgent: httpclient.TerraformUserAgent(p.TerraformVersion),
132136
}
133137

134138
return config.Client()

0 commit comments

Comments
 (0)