mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-08 15:13:56 -06:00
631b0b865c
Here we add a basic provider with a single resource type. It's copied heavily from the `github` provider and `github_repository` resource, as there is some overlap in those types/apis. ~~~ resource "gitlab_project" "test1" { name = "test1" visibility_level = "public" } ~~~ We implement in terms of the [go-gitlab](https://github.com/xanzy/go-gitlab) library, which provides a wrapping of the [gitlab api](https://docs.gitlab.com/ee/api/) We have been a little selective in the properties we surface for the project resource, as not all properties are very instructive. Notable is the removal of the `public` bool as the `visibility_level` will take precedent if both are supplied which leads to confusing interactions if they disagree.
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package gitlab
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
gitlab "github.com/xanzy/go-gitlab"
|
|
)
|
|
|
|
// copied from ../github/util.go
|
|
func validateValueFunc(values []string) schema.SchemaValidateFunc {
|
|
return func(v interface{}, k string) (we []string, errors []error) {
|
|
value := v.(string)
|
|
valid := false
|
|
for _, role := range values {
|
|
if value == role {
|
|
valid = true
|
|
break
|
|
}
|
|
}
|
|
|
|
if !valid {
|
|
errors = append(errors, fmt.Errorf("%s is an invalid value for argument %s", value, k))
|
|
}
|
|
return
|
|
}
|
|
}
|
|
|
|
func stringToVisibilityLevel(s string) *gitlab.VisibilityLevelValue {
|
|
lookup := map[string]gitlab.VisibilityLevelValue{
|
|
"private": gitlab.PrivateVisibility,
|
|
"internal": gitlab.InternalVisibility,
|
|
"public": gitlab.PublicVisibility,
|
|
}
|
|
|
|
value, ok := lookup[s]
|
|
if !ok {
|
|
return nil
|
|
}
|
|
return &value
|
|
}
|
|
|
|
func visibilityLevelToString(v gitlab.VisibilityLevelValue) *string {
|
|
lookup := map[gitlab.VisibilityLevelValue]string{
|
|
gitlab.PrivateVisibility: "private",
|
|
gitlab.InternalVisibility: "internal",
|
|
gitlab.PublicVisibility: "public",
|
|
}
|
|
value, ok := lookup[v]
|
|
if !ok {
|
|
return nil
|
|
}
|
|
return &value
|
|
}
|