1.0.0
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
package cbAccount
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/schemas"
|
||||
)
|
||||
|
||||
// Ensure the implementation satisfies the expected interfaces.
|
||||
var (
|
||||
_ datasource.DataSource = &dataSourceAccount{}
|
||||
)
|
||||
|
||||
func NewDataSourceAccount() datasource.DataSource {
|
||||
return &dataSourceAccount{}
|
||||
}
|
||||
|
||||
// dataSourceAccount is the data source implementation.
|
||||
type dataSourceAccount struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (d *dataSourceAccount) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
// Read Terraform configuration data into the model
|
||||
var state models.DataSourceAccountModel
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read DataSourceCbAccountModel: Error get state")
|
||||
return
|
||||
}
|
||||
accountId := uint64(state.AccountID.ValueInt64())
|
||||
tflog.Info(ctx, "Read DataSourceCbAccountModel: got state successfully", map[string]any{"account_id": accountId})
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout30s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read DataSourceCbAccountModel: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read DataSourceCbAccountModel: set timeouts successfully", map[string]any{
|
||||
"account_id": accountId,
|
||||
"readTimeout": readTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Map response body to schema
|
||||
resp.Diagnostics.Append(flattens.AccountDataSource(ctx, &state, d.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read DataSourceCbAccountModel: Error flatten data source account")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read DataSourceCbAccountModel: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read DataSourceCbAccountModel", map[string]any{"account_id": accountId})
|
||||
}
|
||||
|
||||
func (d *dataSourceAccount) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaDataSourceAccount(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dataSourceAccount) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_cb_account"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *dataSourceAccount) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure DataSourceCbAccountModel")
|
||||
d.client = client.DataSource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure DataSourceCbAccountModel successfully")
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package cbAccount
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/schemas"
|
||||
)
|
||||
|
||||
// Ensure the implementation satisfies the expected interfaces.
|
||||
var (
|
||||
_ datasource.DataSource = &dataSourceAccountList{}
|
||||
)
|
||||
|
||||
func NewDataSourceAccountList() datasource.DataSource {
|
||||
return &dataSourceAccountList{}
|
||||
}
|
||||
|
||||
// NewDataSourceAccountList is the data source implementation.
|
||||
type dataSourceAccountList struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
// Read Terraform configuration data into the model
|
||||
var state models.DataSourceAccountListModel
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountList: Error get state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceAccountList: got state successfully")
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout30s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountList: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceAccountList: set timeouts successfully", map[string]any{"readTimeout": readTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Map response body to schema
|
||||
resp.Diagnostics.Append(flattens.AccountListDataSource(ctx, &state, d.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountList: Error flatten data source")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountList: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read dataSourceAccountList")
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaDataSourceAccountList(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_cb_account_list"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *dataSourceAccountList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure dataSourceAccountList")
|
||||
d.client = client.DataSource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure dataSourceAccountList successfully")
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package cbAccount
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/schemas"
|
||||
)
|
||||
|
||||
// Ensure the implementation satisfies the expected interfaces.
|
||||
var (
|
||||
_ datasource.DataSource = &dataSourceAccountVinsList{}
|
||||
)
|
||||
|
||||
func NewDataSourceAccountVinsList() datasource.DataSource {
|
||||
return &dataSourceAccountVinsList{}
|
||||
}
|
||||
|
||||
// dataSourceAccountVinsList is the data source implementation.
|
||||
type dataSourceAccountVinsList struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountVinsList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
// Read Terraform configuration data into the model
|
||||
var state models.DataSourceAccountVinsListModel
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountVinsList: Error get state")
|
||||
return
|
||||
}
|
||||
accountId := uint64(state.AccountID.ValueInt64())
|
||||
tflog.Info(ctx, "Read dataSourceAccountVinsList: got state successfully", map[string]any{"account_id": accountId})
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout30s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountVinsList: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceAccountVinsList: set timeouts successfully", map[string]any{
|
||||
"account_id": accountId,
|
||||
"readTimeout": readTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Map response body to schema
|
||||
resp.Diagnostics.Append(flattens.AccountVinsListDataSource(ctx, &state, d.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountVinsList: Error flatten data source account")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAccountVinsList: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read dataSourceAccountVinsList", map[string]any{"account_id": accountId})
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountVinsList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaDataSourceAccountVinsList(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dataSourceAccountVinsList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_cb_account_vins_list"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *dataSourceAccountVinsList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure dataSourceAccountVinsList")
|
||||
d.client = client.DataSource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure dataSourceAccountVinsList successfully")
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/utilities"
|
||||
)
|
||||
|
||||
// AccountDataSource flattens data source for account.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountDataSource(ctx context.Context, state *models.DataSourceAccountModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.CbAccountDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
ID := uint64(state.AccountID.ValueInt64())
|
||||
|
||||
recordAccount, err := utilities.AccountDataSourceCheckPresence(ctx, ID, c)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about account with ID %v", ID), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountDataSource: before flatten", map[string]any{"account_id": ID, "recordAccount": recordAccount})
|
||||
|
||||
*state = models.DataSourceAccountModel{
|
||||
AccountID: state.AccountID,
|
||||
Timeouts: state.Timeouts,
|
||||
DCLocation: types.StringValue(recordAccount.DCLocation),
|
||||
CKey: types.StringValue(recordAccount.CKey),
|
||||
ACL: flattenACLInAccount(ctx, recordAccount.ACL),
|
||||
Company: types.StringValue(recordAccount.Company),
|
||||
CompanyURL: types.StringValue(recordAccount.CompanyURL),
|
||||
CPUAllocationParameter: types.StringValue(recordAccount.CPUAllocationParameter),
|
||||
CPUAllocationRatio: types.Float64Value(recordAccount.CPUAllocationRatio),
|
||||
CreatedBy: types.StringValue(recordAccount.CreatedBy),
|
||||
CreatedTime: types.Int64Value(int64(recordAccount.CreatedTime)),
|
||||
DeactivationTime: types.Float64Value(recordAccount.DeactivationTime),
|
||||
DeletedBy: types.StringValue(recordAccount.DeletedBy),
|
||||
DeletedTime: types.Int64Value(int64(recordAccount.DeletedTime)),
|
||||
DisplayName: types.StringValue(recordAccount.DisplayName),
|
||||
GUID: types.Int64Value(int64(recordAccount.GUID)),
|
||||
Name: types.StringValue(recordAccount.Name),
|
||||
ResourceLimits: flattenResourceLimits(ctx, recordAccount.ResourceLimits),
|
||||
ResTypes: flattens.FlattenSimpleTypeToList(ctx, types.StringType, recordAccount.ResTypes),
|
||||
SendAccessEmails: types.BoolValue(recordAccount.SendAccessEmails),
|
||||
Status: types.StringValue(recordAccount.Status),
|
||||
UniqPools: flattens.FlattenSimpleTypeToList(ctx, types.StringType, recordAccount.UniqPools),
|
||||
UpdatedTime: types.Int64Value(int64(recordAccount.UpdatedTime)),
|
||||
Version: types.Int64Value(int64(recordAccount.Version)),
|
||||
VINS: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, recordAccount.VINS),
|
||||
}
|
||||
|
||||
state.ComputeFeatures, diags = types.ListValueFrom(ctx, types.StringType, recordAccount.ComputeFeatures)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.AccountListDeletedDataSource: cannot flatten recordAccount.ComputeFeatures to state.ComputeFeatures", diags))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountDataSource: after flatten", map[string]any{"account_id": state.AccountID.ValueInt64()})
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountDataSource", map[string]any{"account_id": state.AccountID.ValueInt64()})
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenResourceLimits(ctx context.Context, limits account.ResourceLimits) *models.ResourceLimitsModel {
|
||||
tflog.Info(ctx, "Start flattenResourceLimits")
|
||||
res := models.ResourceLimitsModel{
|
||||
CuC: types.Float64Value(limits.CuC),
|
||||
CuD: types.Float64Value(limits.CuD),
|
||||
CuI: types.Float64Value(limits.CuI),
|
||||
CuM: types.Float64Value(limits.CuM),
|
||||
CuDM: types.Float64Value(limits.CuDM),
|
||||
CuNP: types.Float64Value(limits.CuNP),
|
||||
GPUUnits: types.Float64Value(limits.GPUUnits),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenResourceLimits")
|
||||
return &res
|
||||
}
|
||||
|
||||
func flattenACLInAccount(ctx context.Context, aclList []account.ACL) []models.ACLModel {
|
||||
tflog.Info(ctx, "Start flattenACLInAccount")
|
||||
res := make([]models.ACLModel, 0, len(aclList))
|
||||
for _, item := range aclList {
|
||||
temp := models.ACLModel{
|
||||
Explicit: types.BoolValue(item.Explicit),
|
||||
GUID: types.StringValue(item.GUID),
|
||||
Right: types.StringValue(item.Right),
|
||||
Status: types.StringValue(item.Status),
|
||||
Type: types.StringValue(item.Type),
|
||||
UserGroupID: types.StringValue(item.UserGroupID),
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/utilities"
|
||||
)
|
||||
|
||||
// AccountListDataSource flattens data source for account.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountListDataSource(ctx context.Context, state *models.DataSourceAccountListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
accList, err := utilities.AccountListDataSourceCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about account list", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountListDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceAccountListModel{
|
||||
ByID: state.ByID,
|
||||
Name: state.Name,
|
||||
ACL: state.ACL,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
SortBy: state.SortBy,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
EntryCount: types.Int64Value(int64(accList.EntryCount)),
|
||||
}
|
||||
|
||||
items := make([]models.AccountListElementModel, 0, len(accList.Data))
|
||||
for _, item := range accList.Data {
|
||||
i := models.AccountListElementModel{
|
||||
DCLocation: types.StringValue(item.DCLocation),
|
||||
CKey: types.StringValue(item.CKey),
|
||||
ACL: flattenACLInAccountList(ctx, item.ACL),
|
||||
Company: types.StringValue(item.Company),
|
||||
CompanyURL: types.StringValue(item.CompanyURL),
|
||||
CPUAllocationParameter: types.StringValue(item.CPUAllocationParameter),
|
||||
CPUAllocationRatio: types.Float64Value(item.CPUAllocationRatio),
|
||||
CreatedBy: types.StringValue(item.CreatedBy),
|
||||
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
|
||||
DeactivationTime: types.Float64Value(item.DeactivationTime),
|
||||
DeletedBy: types.StringValue(item.DeletedBy),
|
||||
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
|
||||
DisplayName: types.StringValue(item.DisplayName),
|
||||
GUID: types.Int64Value(int64(item.GUID)),
|
||||
Name: types.StringValue(item.Name),
|
||||
ResourceLimits: flattenAccountListResourceLimits(ctx, item.ResourceLimits),
|
||||
ResTypes: flattenAccListSimpleType(ctx, types.StringType, item.ResTypes),
|
||||
SendAccessEmails: types.BoolValue(item.SendAccessEmails),
|
||||
Status: types.StringValue(item.Status),
|
||||
UniqPools: flattenAccListSimpleType(ctx, types.StringType, item.UniqPools),
|
||||
UpdatedTime: types.Int64Value(int64(item.UpdatedTime)),
|
||||
Version: types.Int64Value(int64(item.Version)),
|
||||
VINS: flattenAccListSimpleType(ctx, types.Int64Type, item.VINS),
|
||||
}
|
||||
i.ComputeFeatures, diags = types.ListValueFrom(ctx, types.StringType, item.ComputeFeatures)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.AccountListDataSource: cannot flatten item.ComputeFeatures to i.ComputeFeatures", diags))
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
state.Items = items
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountListDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountListDataSource")
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenAccountListResourceLimits(ctx context.Context, limits account.ResourceLimits) *models.AccountListResourceLimitsModel {
|
||||
tflog.Info(ctx, "Start flattenAccountListResourceLimits")
|
||||
res := models.AccountListResourceLimitsModel{
|
||||
CuC: types.Float64Value(limits.CuC),
|
||||
CuD: types.Float64Value(limits.CuD),
|
||||
CuI: types.Float64Value(limits.CuI),
|
||||
CuM: types.Float64Value(limits.CuM),
|
||||
CuDM: types.Float64Value(limits.CuDM),
|
||||
CuNP: types.Float64Value(limits.CuNP),
|
||||
GPUUnits: types.Float64Value(limits.GPUUnits),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenAccountListResourceLimits")
|
||||
return &res
|
||||
}
|
||||
|
||||
func flattenACLInAccountList(ctx context.Context, aclList []account.ACL) []models.AccountListACLModel {
|
||||
tflog.Info(ctx, "Start flattenACLInAccountList")
|
||||
res := make([]models.AccountListACLModel, 0, len(aclList))
|
||||
for _, item := range aclList {
|
||||
temp := models.AccountListACLModel{
|
||||
Explicit: types.BoolValue(item.Explicit),
|
||||
GUID: types.StringValue(item.GUID),
|
||||
Right: types.StringValue(item.Right),
|
||||
Status: types.StringValue(item.Status),
|
||||
Type: types.StringValue(item.Type),
|
||||
UserGroupID: types.StringValue(item.UserGroupID),
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenAccListSimpleType(ctx context.Context, elementType attr.Type, elements any) types.List {
|
||||
res, diags := types.ListValueFrom(ctx, elementType, elements)
|
||||
if diags != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenAccListSimpleType", diags))
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/utilities"
|
||||
)
|
||||
|
||||
// AccountVinsListDataSource flattens data source for account list.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountVinsListDataSource(ctx context.Context, state *models.DataSourceAccountVinsListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountVinsListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
accountVinsList, err := utilities.AccountVinsListCheck(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about account list", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountVinsListDataSource: before flatten")
|
||||
|
||||
*state = models.DataSourceAccountVinsListModel{
|
||||
AccountID: state.AccountID,
|
||||
VinsID: state.VinsID,
|
||||
Name: state.Name,
|
||||
RGID: state.RGID,
|
||||
ExtIp: state.ExtIp,
|
||||
SortBy: state.SortBy,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
EntryCount: types.Int64Value(int64(accountVinsList.EntryCount)),
|
||||
}
|
||||
items := make([]models.ItemVINSModel, 0, len(accountVinsList.Data))
|
||||
for _, item := range accountVinsList.Data {
|
||||
i := models.ItemVINSModel{
|
||||
AccountID: types.Int64Value(int64(item.ID)),
|
||||
AccountName: types.StringValue(item.Name),
|
||||
Computes: types.Int64Value(int64(item.Computes)),
|
||||
CreatedBy: types.StringValue(item.CreatedBy),
|
||||
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
|
||||
DeletedBy: types.StringValue(item.DeletedBy),
|
||||
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
|
||||
ExternalIP: types.StringValue(item.ExternalIP),
|
||||
ExtnetId: types.Int64Value(int64(item.ExtnetId)),
|
||||
FreeIPs: types.Int64Value(int64(item.FreeIPs)),
|
||||
ID: types.Int64Value(int64(item.ID)),
|
||||
Name: types.StringValue(item.Name),
|
||||
Network: types.StringValue(item.Network),
|
||||
PriVNFDevID: types.Int64Value(int64(item.PriVNFDevID)),
|
||||
RGID: types.Int64Value(int64(item.RGID)),
|
||||
RGName: types.StringValue(item.RGName),
|
||||
Status: types.StringValue(item.Status),
|
||||
UpdatedBy: types.StringValue(item.UpdatedBy),
|
||||
UpdatedTime: types.Int64Value(int64(item.UpdatedTime)),
|
||||
}
|
||||
|
||||
items = append(items, i)
|
||||
}
|
||||
|
||||
state.Data = items
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountVinsListDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountVinsListDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type DataSourceAccountModel struct {
|
||||
// optional fields
|
||||
AccountID types.Int64 `tfsdk:"account_id"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
|
||||
// response fields
|
||||
DCLocation types.String `tfsdk:"dc_location"`
|
||||
CKey types.String `tfsdk:"ckey"`
|
||||
ACL []ACLModel `tfsdk:"acl"`
|
||||
Company types.String `tfsdk:"company"`
|
||||
CompanyURL types.String `tfsdk:"companyurl"`
|
||||
ComputeFeatures types.List `tfsdk:"compute_features"`
|
||||
CPUAllocationParameter types.String `tfsdk:"cpu_allocation_parameter"`
|
||||
CPUAllocationRatio types.Float64 `tfsdk:"cpu_allocation_ratio"`
|
||||
CreatedBy types.String `tfsdk:"created_by"`
|
||||
CreatedTime types.Int64 `tfsdk:"created_time"`
|
||||
DeactivationTime types.Float64 `tfsdk:"deactivation_time"`
|
||||
DeletedBy types.String `tfsdk:"deleted_by"`
|
||||
DeletedTime types.Int64 `tfsdk:"deleted_time"`
|
||||
DisplayName types.String `tfsdk:"displayname"`
|
||||
GUID types.Int64 `tfsdk:"guid"`
|
||||
ID types.Int64 `tfsdk:"id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
ResourceLimits *ResourceLimitsModel `tfsdk:"resource_limits"`
|
||||
ResTypes types.List `tfsdk:"resource_types"`
|
||||
SendAccessEmails types.Bool `tfsdk:"send_access_emails"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
UniqPools types.List `tfsdk:"uniq_pools"`
|
||||
UpdatedTime types.Int64 `tfsdk:"updated_time"`
|
||||
Version types.Int64 `tfsdk:"version"`
|
||||
VINS types.List `tfsdk:"vins"`
|
||||
}
|
||||
|
||||
type ACLModel struct {
|
||||
Explicit types.Bool `tfsdk:"explicit"`
|
||||
GUID types.String `tfsdk:"guid"`
|
||||
Right types.String `tfsdk:"right"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
Type types.String `tfsdk:"type"`
|
||||
UserGroupID types.String `tfsdk:"user_group_id"`
|
||||
}
|
||||
|
||||
type ResourceLimitsModel struct {
|
||||
CuC types.Float64 `tfsdk:"cu_c"`
|
||||
CuD types.Float64 `tfsdk:"cu_d"`
|
||||
CuDM types.Float64 `tfsdk:"cu_dm"`
|
||||
CuI types.Float64 `tfsdk:"cu_i"`
|
||||
CuM types.Float64 `tfsdk:"cu_m"`
|
||||
CuNP types.Float64 `tfsdk:"cu_np"`
|
||||
GPUUnits types.Float64 `tfsdk:"gpu_units"`
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type DataSourceAccountListModel struct {
|
||||
// optional fields
|
||||
ByID types.Int64 `tfsdk:"by_id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
ACL types.String `tfsdk:"acl"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
SortBy types.String `tfsdk:"sort_by"`
|
||||
Page types.Int64 `tfsdk:"page"`
|
||||
Size types.Int64 `tfsdk:"size"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
|
||||
// response fields
|
||||
Id types.String `tfsdk:"id"`
|
||||
Items []AccountListElementModel `tfsdk:"items"`
|
||||
EntryCount types.Int64 `tfsdk:"entry_count"`
|
||||
}
|
||||
|
||||
type AccountListElementModel struct {
|
||||
DCLocation types.String `tfsdk:"dc_location"`
|
||||
CKey types.String `tfsdk:"ckey"`
|
||||
ACL []AccountListACLModel `tfsdk:"acl"`
|
||||
Company types.String `tfsdk:"company"`
|
||||
CompanyURL types.String `tfsdk:"companyurl"`
|
||||
ComputeFeatures types.List `tfsdk:"compute_features"`
|
||||
CPUAllocationParameter types.String `tfsdk:"cpu_allocation_parameter"`
|
||||
CPUAllocationRatio types.Float64 `tfsdk:"cpu_allocation_ratio"`
|
||||
CreatedBy types.String `tfsdk:"created_by"`
|
||||
CreatedTime types.Int64 `tfsdk:"created_time"`
|
||||
DeactivationTime types.Float64 `tfsdk:"deactivation_time"`
|
||||
DeletedBy types.String `tfsdk:"deleted_by"`
|
||||
DeletedTime types.Int64 `tfsdk:"deleted_time"`
|
||||
DisplayName types.String `tfsdk:"displayname"`
|
||||
GUID types.Int64 `tfsdk:"guid"`
|
||||
ID types.Int64 `tfsdk:"id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
ResourceLimits *AccountListResourceLimitsModel `tfsdk:"resource_limits"`
|
||||
ResTypes types.List `tfsdk:"resource_types"`
|
||||
SendAccessEmails types.Bool `tfsdk:"send_access_emails"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
UniqPools types.List `tfsdk:"uniq_pools"`
|
||||
UpdatedTime types.Int64 `tfsdk:"updated_time"`
|
||||
Version types.Int64 `tfsdk:"version"`
|
||||
VINS types.List `tfsdk:"vins"`
|
||||
}
|
||||
|
||||
type AccountListACLModel struct {
|
||||
Explicit types.Bool `tfsdk:"explicit"`
|
||||
GUID types.String `tfsdk:"guid"`
|
||||
Right types.String `tfsdk:"right"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
Type types.String `tfsdk:"type"`
|
||||
UserGroupID types.String `tfsdk:"user_group_id"`
|
||||
}
|
||||
|
||||
type AccountListResourceLimitsModel struct {
|
||||
CuC types.Float64 `tfsdk:"cu_c"`
|
||||
CuD types.Float64 `tfsdk:"cu_d"`
|
||||
CuDM types.Float64 `tfsdk:"cu_dm"`
|
||||
CuI types.Float64 `tfsdk:"cu_i"`
|
||||
CuM types.Float64 `tfsdk:"cu_m"`
|
||||
CuNP types.Float64 `tfsdk:"cu_np"`
|
||||
GPUUnits types.Float64 `tfsdk:"gpu_units"`
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type DataSourceAccountVinsListModel struct {
|
||||
// optional fields
|
||||
AccountID types.Int64 `tfsdk:"account_id"`
|
||||
VinsID types.Int64 `tfsdk:"vins_id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
RGID types.Int64 `tfsdk:"rg_id"`
|
||||
ExtIp types.String `tfsdk:"ext_ip"`
|
||||
SortBy types.String `tfsdk:"sort_by"`
|
||||
Page types.Int64 `tfsdk:"page"`
|
||||
Size types.Int64 `tfsdk:"size"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
|
||||
// response fields
|
||||
Data []ItemVINSModel `tfsdk:"items"`
|
||||
EntryCount types.Int64 `tfsdk:"entry_count"`
|
||||
}
|
||||
|
||||
type ItemVINSModel struct {
|
||||
AccountID types.Int64 `tfsdk:"account_id"`
|
||||
AccountName types.String `tfsdk:"account_name"`
|
||||
Computes types.Int64 `tfsdk:"computes"`
|
||||
CreatedBy types.String `tfsdk:"created_by"`
|
||||
CreatedTime types.Int64 `tfsdk:"created_time"`
|
||||
DeletedBy types.String `tfsdk:"deleted_by"`
|
||||
DeletedTime types.Int64 `tfsdk:"deleted_time"`
|
||||
ExternalIP types.String `tfsdk:"external_ip"`
|
||||
ExtnetId types.Int64 `tfsdk:"extnet_id"`
|
||||
FreeIPs types.Int64 `tfsdk:"free_ips"`
|
||||
ID types.Int64 `tfsdk:"vin_id"`
|
||||
Name types.String `tfsdk:"vin_name"`
|
||||
Network types.String `tfsdk:"network"`
|
||||
PriVNFDevID types.Int64 `tfsdk:"pri_vnf_dev_id"`
|
||||
RGID types.Int64 `tfsdk:"rg_id"`
|
||||
RGName types.String `tfsdk:"rg_name"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
UpdatedBy types.String `tfsdk:"updated_by"`
|
||||
UpdatedTime types.Int64 `tfsdk:"updated_time"`
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
func MakeSchemaDataSourceAccount() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
"account_id": schema.Int64Attribute{
|
||||
Required: true,
|
||||
},
|
||||
"dc_location": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ckey": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"acl": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"explicit": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"right": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"type": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"user_group_id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"company": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"companyurl": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"compute_features": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"cpu_allocation_parameter": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"cpu_allocation_ratio": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"created_by": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"created_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"deactivation_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_by": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"displayname": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"resource_limits": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"cu_c": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"cu_d": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"cu_dm": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"cu_i": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"cu_m": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"cu_np": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"gpu_units": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"resource_types": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"send_access_emails": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"uniq_pools": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"updated_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"version": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"vins": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.Int64Type,
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
func MakeSchemaDataSourceAccountList() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
// optional attributes
|
||||
"by_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "filter by id",
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "filter by name",
|
||||
},
|
||||
"acl": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "filter by acl",
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"page": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "page number",
|
||||
},
|
||||
"size": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "page size",
|
||||
},
|
||||
"sort_by": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "sort by one of supported fields, format +|-(field)",
|
||||
},
|
||||
"items": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"dc_location": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ckey": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"acl": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"explicit": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"right": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"type": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"user_group_id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"company": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"companyurl": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"compute_features": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"cpu_allocation_parameter": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"cpu_allocation_ratio": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"created_by": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"created_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"deactivation_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_by": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"displayname": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"resource_limits": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"cu_c": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"cu_d": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"cu_dm": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"cu_i": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"cu_m": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"cu_np": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"gpu_units": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"resource_types": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"send_access_emails": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"uniq_pools": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"updated_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"version": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"vins": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.Int64Type,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"entry_count": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
)
|
||||
|
||||
func MakeSchemaDataSourceAccountVinsList() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
"account_id": schema.Int64Attribute{
|
||||
Required: true,
|
||||
},
|
||||
"vins_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Optional: true,
|
||||
},
|
||||
"rg_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
},
|
||||
"ext_ip": schema.StringAttribute{
|
||||
Optional: true,
|
||||
},
|
||||
"sort_by": schema.StringAttribute{
|
||||
Optional: true,
|
||||
},
|
||||
"page": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
},
|
||||
"size": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
},
|
||||
"items": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"account_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"account_name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"computes": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"created_by": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"created_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_by": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"external_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"extnet_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"free_ips": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"vin_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"vin_name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"network": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"pri_vnf_dev_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"rg_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"rg_name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"updated_by": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"updated_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package utilities
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account"
|
||||
)
|
||||
|
||||
func AccountDataSourceCheckPresence(ctx context.Context, accountId uint64, c *decort.DecortClient) (*account.InfoAccount, error) {
|
||||
tflog.Info(ctx, fmt.Sprintf("CbAccountDataSourceCheckPresence: Get info about account with ID - %v", accountId))
|
||||
|
||||
recordAccount, err := c.CloudBroker().Account().Get(ctx, account.GetRequest{AccountID: accountId})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get info about account with error: %w", err)
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "CbAccountDataSourceCheckPresence: response from CloudBroker().Account().Get",
|
||||
map[string]any{"account_id": accountId, "response": recordAccount})
|
||||
|
||||
return &recordAccount.InfoAccount, err
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package utilities
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/models"
|
||||
)
|
||||
|
||||
func AccountListDataSourceCheckPresence(ctx context.Context, plan *models.DataSourceAccountListModel, c *decort.DecortClient) (*account.ListAccounts, error) {
|
||||
tflog.Info(ctx, "AccountListDataSourceCheckPresence: Get info about list accounts")
|
||||
req := account.ListRequest{}
|
||||
|
||||
if !plan.ByID.IsNull() {
|
||||
req.ByID = uint64(plan.ByID.ValueInt64())
|
||||
}
|
||||
if !plan.Name.IsNull() {
|
||||
req.Name = plan.Name.ValueString()
|
||||
}
|
||||
if !plan.ACL.IsNull() {
|
||||
req.ACL = plan.ACL.ValueString()
|
||||
}
|
||||
if !plan.Status.IsNull() {
|
||||
req.Status = plan.Status.ValueString()
|
||||
}
|
||||
if !plan.Page.IsNull() {
|
||||
req.Page = uint64(plan.Page.ValueInt64())
|
||||
}
|
||||
if !plan.Size.IsNull() {
|
||||
req.Size = uint64(plan.Size.ValueInt64())
|
||||
}
|
||||
if !plan.SortBy.IsNull() {
|
||||
req.SortBy = plan.SortBy.ValueString()
|
||||
}
|
||||
tflog.Info(ctx, "AccountListDataSourceCheckPresence: before call CloudBroker().Account().List", map[string]any{"req": req})
|
||||
|
||||
listAccounts, err := c.CloudBroker().Account().List(ctx, req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get info about accounts with error: %w", err)
|
||||
}
|
||||
tflog.Info(ctx, "AccountListDataSourceCheckPresence: response from CloudBroker().Account().List")
|
||||
|
||||
return listAccounts, err
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package utilities
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/account/models"
|
||||
)
|
||||
|
||||
func AccountVinsListCheck(ctx context.Context, plan *models.DataSourceAccountVinsListModel, c *decort.DecortClient) (*account.ListVINS, error) {
|
||||
tflog.Info(ctx, "AccountVinsListCheck: Get info about list vins")
|
||||
|
||||
vinsListReq := account.ListVINSRequest{}
|
||||
|
||||
if !plan.AccountID.IsNull() {
|
||||
vinsListReq.AccountID = uint64(plan.AccountID.ValueInt64())
|
||||
}
|
||||
if !plan.VinsID.IsNull() {
|
||||
vinsListReq.VINSID = uint64(plan.VinsID.ValueInt64())
|
||||
}
|
||||
if !plan.Name.IsNull() {
|
||||
vinsListReq.Name = plan.Name.ValueString()
|
||||
}
|
||||
if !plan.RGID.IsNull() {
|
||||
vinsListReq.RGID = uint64(plan.RGID.ValueInt64())
|
||||
}
|
||||
if !plan.ExtIp.IsNull() {
|
||||
vinsListReq.ExtIP = plan.ExtIp.ValueString()
|
||||
}
|
||||
if !plan.SortBy.IsNull() {
|
||||
vinsListReq.SortBy = plan.SortBy.ValueString()
|
||||
}
|
||||
if !plan.Page.IsNull() {
|
||||
vinsListReq.Page = uint64(plan.Page.ValueInt64())
|
||||
}
|
||||
if !plan.Size.IsNull() {
|
||||
vinsListReq.Size = uint64(plan.Size.ValueInt64())
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "AccountVinsListCheck: before call CloudBroker().Account().ListVINS", map[string]any{"req": vinsListReq})
|
||||
vinsList, err := c.CloudBroker().Account().ListVINS(ctx, vinsListReq)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get info about vins list with error: %w", err)
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "AccountVinsListCheck: response from CloudBroker().Account().ListVINS")
|
||||
|
||||
return vinsList, err
|
||||
}
|
||||
Reference in New Issue
Block a user