@@ -5,14 +5,15 @@ import (
5
5
"strings"
6
6
7
7
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
8
+ "github.com/hashicorp/terraform-plugin-sdk/httpclient"
8
9
"github.com/hashicorp/terraform-plugin-sdk/terraform"
9
10
)
10
11
11
12
// Provider returns a terraform.ResourceProvider.
12
13
func Provider () terraform.ResourceProvider {
13
14
14
15
// The actual provider
15
- return & schema.Provider {
16
+ provider := & schema.Provider {
16
17
Schema : map [string ]* schema.Schema {
17
18
"token" : {
18
19
Type : schema .TypeString ,
@@ -93,9 +94,13 @@ func Provider() terraform.ResourceProvider {
93
94
"gitlab_project_mirror" : resourceGitlabProjectMirror (),
94
95
"gitlab_project_level_mr_approvals" : resourceGitlabProjectLevelMRApprovals (),
95
96
},
97
+ }
96
98
97
- ConfigureFunc : providerConfigure ,
99
+ provider .ConfigureFunc = func (d * schema.ResourceData ) (interface {}, error ) {
100
+ return providerConfigure (provider , d )
98
101
}
102
+
103
+ return provider
99
104
}
100
105
101
106
var descriptions map [string ]string
@@ -116,7 +121,7 @@ func init() {
116
121
}
117
122
}
118
123
119
- func providerConfigure (d * schema.ResourceData ) (interface {}, error ) {
124
+ func providerConfigure (p * schema. Provider , d * schema.ResourceData ) (interface {}, error ) {
120
125
config := Config {
121
126
Token : d .Get ("token" ).(string ),
122
127
BaseURL : d .Get ("base_url" ).(string ),
@@ -126,13 +131,22 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
126
131
ClientKey : d .Get ("client_key" ).(string ),
127
132
}
128
133
129
- return config .Client ()
134
+ client , err := config .Client ()
135
+ if err != nil {
136
+ return nil , err
137
+ }
138
+
139
+ // NOTE: httpclient.TerraformUserAgent is deprecated and removed in Terraform SDK v2
140
+ // After upgrading the SDK to v2 replace with p.UserAgent("terraform-provider-gitlab")
141
+ client .UserAgent = httpclient .TerraformUserAgent (p .TerraformVersion ) + " terraform-provider-gitlab"
142
+
143
+ return client , err
130
144
}
131
145
132
146
func validateApiURLVersion (value interface {}, key string ) (ws []string , es []error ) {
133
147
v := value .(string )
134
148
if strings .HasSuffix (v , "/api/v3" ) || strings .HasSuffix (v , "/api/v3/" ) {
135
- es = append (es , fmt .Errorf ("terraform-gitlab- provider does not support v3 api; please upgrade to /api/v4 in %s" , v ))
149
+ es = append (es , fmt .Errorf ("terraform-provider-gitlab does not support v3 api; please upgrade to /api/v4 in %s" , v ))
136
150
}
137
151
return
138
152
}
0 commit comments