1.2.0
This commit is contained in:
@@ -8,36 +8,76 @@ import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
|
||||
)
|
||||
|
||||
func DataSource(ctx context.Context, req *datasource.ConfigureRequest, resp *datasource.ConfigureResponse) *decort.DecortClient {
|
||||
if req.ProviderData == nil {
|
||||
tflog.Error(ctx, "Provider Configure is nill")
|
||||
return nil
|
||||
}
|
||||
client, ok := req.ProviderData.(*decort.DecortClient)
|
||||
if !ok {
|
||||
resp.Diagnostics.AddError(
|
||||
"Unexpected Data Source Configure Type",
|
||||
fmt.Sprintf("Expected *decort.DecortClient, got: %T. Please report this issue to the provider developers.", req.ProviderData),
|
||||
)
|
||||
return nil
|
||||
}
|
||||
return client
|
||||
type Client struct {
|
||||
Provider any
|
||||
}
|
||||
|
||||
func Resource(ctx context.Context, req *resource.ConfigureRequest, resp *resource.ConfigureResponse) *decort.DecortClient {
|
||||
func DataSource(ctx context.Context, req *datasource.ConfigureRequest, resp *datasource.ConfigureResponse) *Client {
|
||||
if req.ProviderData == nil {
|
||||
tflog.Error(ctx, "Provider Configure is nill")
|
||||
return nil
|
||||
}
|
||||
client, ok := req.ProviderData.(*decort.DecortClient)
|
||||
if !ok {
|
||||
resp.Diagnostics.AddError(
|
||||
"Unexpected Data Source Configure Type",
|
||||
fmt.Sprintf("Expected *decort.DecortClient, got: %T. Please report this issue to the provider developers.", req.ProviderData),
|
||||
)
|
||||
|
||||
res := Client{}
|
||||
if decort, ok := req.ProviderData.(*decort.DecortClient); ok {
|
||||
res.Provider = decort
|
||||
return &res
|
||||
}
|
||||
if bvs, ok := req.ProviderData.(*decort.BVSDecortClient); ok {
|
||||
res.Provider = bvs
|
||||
return &res
|
||||
}
|
||||
|
||||
resp.Diagnostics.AddError(
|
||||
"Unexpected Data Source Configure Type",
|
||||
fmt.Sprintf("Expected *decort.DecortClient or *decort.BVSDecortClient, got: %T. Please report this issue to the provider developers.", req.ProviderData),
|
||||
)
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func Resource(ctx context.Context, req *resource.ConfigureRequest, resp *resource.ConfigureResponse) *Client {
|
||||
if req.ProviderData == nil {
|
||||
tflog.Error(ctx, "Provider Configure is nill")
|
||||
return nil
|
||||
}
|
||||
return client
|
||||
res := Client{}
|
||||
if decort, ok := req.ProviderData.(*decort.DecortClient); ok {
|
||||
res.Provider = decort
|
||||
return &res
|
||||
}
|
||||
if bvs, ok := req.ProviderData.(*decort.BVSDecortClient); ok {
|
||||
res.Provider = bvs
|
||||
return &res
|
||||
}
|
||||
|
||||
resp.Diagnostics.AddError(
|
||||
"Unexpected Data Source Configure Type",
|
||||
fmt.Sprintf("Expected *decort.DecortClient or *decort.BVSDecortClient, got: %T. Please report this issue to the provider developers.", req.ProviderData),
|
||||
)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) CloudAPI() *cloudapi.CloudAPI {
|
||||
if decort, ok := c.Provider.(*decort.DecortClient); ok {
|
||||
return decort.CloudAPI()
|
||||
}
|
||||
if bvs, ok := c.Provider.(*decort.BVSDecortClient); ok {
|
||||
return bvs.CloudAPI()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) CloudBroker() *cloudbroker.CloudBroker {
|
||||
if decort, ok := c.Provider.(*decort.DecortClient); ok {
|
||||
return decort.CloudBroker()
|
||||
}
|
||||
if bvs, ok := c.Provider.(*decort.BVSDecortClient); ok {
|
||||
return bvs.CloudBroker()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user