Skip to content

Commit 11e8bb8

Browse files
author
Julien Pivotto
committed
Validate that API URL version is not v3
This will help our users to figure out that we moved to the v4 api. Signed-off-by: Julien Pivotto <[email protected]>
1 parent 4742657 commit 11e8bb8

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

gitlab/provider.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package gitlab
22

33
import (
4+
"fmt"
5+
"strings"
6+
47
"github.com/hashicorp/terraform/helper/schema"
58
"github.com/hashicorp/terraform/terraform"
69
)
@@ -18,10 +21,11 @@ func Provider() terraform.ResourceProvider {
1821
Description: descriptions["token"],
1922
},
2023
"base_url": {
21-
Type: schema.TypeString,
22-
Optional: true,
23-
DefaultFunc: schema.EnvDefaultFunc("GITLAB_BASE_URL", ""),
24-
Description: descriptions["base_url"],
24+
Type: schema.TypeString,
25+
Optional: true,
26+
DefaultFunc: schema.EnvDefaultFunc("GITLAB_BASE_URL", ""),
27+
Description: descriptions["base_url"],
28+
ValidateFunc: validateApiURLVersion,
2529
},
2630
"cacert_file": {
2731
Type: schema.TypeString,
@@ -71,3 +75,11 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
7175

7276
return config.Client()
7377
}
78+
79+
func validateApiURLVersion(value interface{}, key string) (ws []string, es []error) {
80+
v := value.(string)
81+
if strings.HasSuffix(v, "/api/v3") || strings.HasSuffix(v, "/api/v3/") {
82+
es = append(es, fmt.Errorf("terraform-gitlab-provider does not support v3 api; please upgrade to /api/v4 in %s", v))
83+
}
84+
return
85+
}

0 commit comments

Comments
 (0)