mirror of
https://github.com/ysoftdevs/terraform-provider-bitbucketserver.git
synced 2026-07-02 02:51:48 +02:00
feat: Introduce muxing for new elements
This commit is contained in:
+52
-14
@@ -1,35 +1,43 @@
|
||||
package bitbucket
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/hashicorp/go-cty/cty"
|
||||
"github.com/xvlcwk-terraform/terraform-provider-bitbucketserver/bitbucket/util/client"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/xvlcwk-terraform/terraform-provider-bitbucketserver/bitbucket/marketplace"
|
||||
bitbucketTypes "github.com/xvlcwk-terraform/terraform-provider-bitbucketserver/bitbucket/util/types"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func Provider() terraform.ResourceProvider {
|
||||
func Provider() *schema.Provider {
|
||||
return &schema.Provider{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"server": {
|
||||
Required: true,
|
||||
Type: schema.TypeString,
|
||||
DefaultFunc: schema.EnvDefaultFunc("BITBUCKET_SERVER", nil),
|
||||
Description: "The url of your bitbucket instance. For the docker compose instance this is http://localhost:7990",
|
||||
},
|
||||
"username": {
|
||||
Required: true,
|
||||
Type: schema.TypeString,
|
||||
DefaultFunc: schema.EnvDefaultFunc("BITBUCKET_USERNAME", nil),
|
||||
Description: "The username for authentication. If you're using a personal access token use your normal username.",
|
||||
},
|
||||
"password": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Sensitive: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("BITBUCKET_PASSWORD", nil),
|
||||
Description: "the password for authentication. Personal access tokens are allowed, but http access token aren't yet",
|
||||
},
|
||||
},
|
||||
ConfigureFunc: providerConfigure,
|
||||
ConfigureContextFunc: providerConfigure,
|
||||
DataSourcesMap: map[string]*schema.Resource{
|
||||
"bitbucketserver_application_properties": dataSourceApplicationProperties(),
|
||||
"bitbucketserver_cluster": dataSourceCluster(),
|
||||
@@ -74,22 +82,52 @@ func Provider() terraform.ResourceProvider {
|
||||
}
|
||||
}
|
||||
|
||||
type BitbucketServerProvider struct {
|
||||
BitbucketClient *BitbucketClient
|
||||
MarketplaceClient *marketplace.Client
|
||||
}
|
||||
|
||||
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
||||
func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
|
||||
|
||||
serverSanitized := d.Get("server").(string)
|
||||
if strings.HasSuffix(serverSanitized, "/") {
|
||||
serverSanitized = serverSanitized[0 : len(serverSanitized)-1]
|
||||
}
|
||||
|
||||
b := &BitbucketClient{
|
||||
username := d.Get("username").(string)
|
||||
password := d.Get("password").(string)
|
||||
|
||||
configErrors := diag.Diagnostics{}
|
||||
|
||||
if serverSanitized == "" {
|
||||
configErrors = append(configErrors,
|
||||
diag.Diagnostic{
|
||||
Severity: diag.Error,
|
||||
AttributePath: cty.Path{}.GetAttr("server"),
|
||||
Detail: "server is required and must be provided in the provider config or the BITBUCKET_SERVER environment variable",
|
||||
})
|
||||
}
|
||||
if username == "" {
|
||||
configErrors = append(configErrors,
|
||||
diag.Diagnostic{
|
||||
|
||||
Severity: diag.Error,
|
||||
AttributePath: cty.Path{}.GetAttr("username"),
|
||||
Detail: "username is required and must be provided in the provider config or the BITBUCKET_USERNAME environment variable",
|
||||
})
|
||||
}
|
||||
if password == "" {
|
||||
configErrors = append(configErrors,
|
||||
diag.Diagnostic{
|
||||
Severity: diag.Error,
|
||||
AttributePath: cty.Path{}.GetAttr("password"),
|
||||
Detail: "password is required and must be provided in the provider config or the BITBUCKET_PASSWORD environment variable",
|
||||
})
|
||||
}
|
||||
|
||||
if configErrors.HasError() {
|
||||
return nil, configErrors
|
||||
}
|
||||
|
||||
b := &client.BitbucketClient{
|
||||
Server: serverSanitized,
|
||||
Username: d.Get("username").(string),
|
||||
Password: d.Get("password").(string),
|
||||
Username: username,
|
||||
Password: password,
|
||||
HTTPClient: &http.Client{},
|
||||
}
|
||||
|
||||
@@ -97,7 +135,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
||||
HTTPClient: &http.Client{},
|
||||
}
|
||||
|
||||
return &BitbucketServerProvider{
|
||||
return &bitbucketTypes.BitbucketServerProvider{
|
||||
BitbucketClient: b,
|
||||
MarketplaceClient: m,
|
||||
}, nil
|
||||
|
||||
Reference in New Issue
Block a user