mirror of
https://github.com/ysoftdevs/terraform-provider-bitbucketserver.git
synced 2026-03-18 07:23:47 +01:00
This is very much a WIP. It will be extended quite a bit to support automatic recreation and similar stuff. For now it will only be pushed to be used internally.
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package util
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/hashicorp/terraform-plugin-framework/resource"
|
|
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
|
|
client2 "github.com/xvlcwk-terraform/terraform-provider-bitbucketserver/bitbucket/util/client"
|
|
bitbucketTypes "github.com/xvlcwk-terraform/terraform-provider-bitbucketserver/bitbucket/util/types"
|
|
)
|
|
|
|
type (
|
|
// ResourceHelper provides assistive snippets of logic to help reduce duplication in
|
|
// each resource definition.
|
|
ResourceHelper struct {
|
|
client *client2.BitbucketClient
|
|
}
|
|
)
|
|
|
|
func NewResourceHelper() *ResourceHelper {
|
|
return &ResourceHelper{}
|
|
}
|
|
|
|
// Configure should register the client for the resource.
|
|
func (r *ResourceHelper) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
|
|
// Prevent panic if the provider has not been configured.
|
|
if req.ProviderData == nil {
|
|
return
|
|
}
|
|
|
|
provider, ok := req.ProviderData.(*bitbucketTypes.BitbucketServerProvider)
|
|
if !ok {
|
|
resp.Diagnostics.AddError(
|
|
"Unexpected Resource Configure Type",
|
|
fmt.Sprintf("Expected *bitbucket.BitbucketServerProvider, got: %T. Please report this issue to the provider developers.", req.ProviderData),
|
|
)
|
|
return
|
|
}
|
|
|
|
r.client = provider.BitbucketClient
|
|
}
|
|
|
|
func (r *ResourceHelper) Schema(s map[string]schema.Attribute) map[string]schema.Attribute {
|
|
return s
|
|
}
|