1.0.0
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"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/cloudapi/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/utilities"
|
||||
)
|
||||
|
||||
// AccountListDeletedDataSource flattens data source for account list deleted.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountListDeletedDataSource(ctx context.Context, state *models.DataSourceAccountListDeletedModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountListDeletedDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
accListDel, err := utilities.AccountListDeletedCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about account list deleted", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountListDeletedDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceAccountListDeletedModel{
|
||||
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(accListDel.EntryCount)),
|
||||
}
|
||||
|
||||
items := make([]models.ItemAccountListDeletedModel, 0, len(accListDel.Data))
|
||||
for _, item := range accListDel.Data {
|
||||
i := models.ItemAccountListDeletedModel{
|
||||
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
|
||||
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
|
||||
AccountID: types.Int64Value(int64(item.ID)),
|
||||
AccountName: types.StringValue(item.Name),
|
||||
Status: types.StringValue(item.Status),
|
||||
UpdatedTime: types.Int64Value(int64(item.UpdatedTime)),
|
||||
}
|
||||
|
||||
i.ComputeFeatures, diags = types.ListValueFrom(ctx, types.StringType, item.ComputeFeatures)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.AccountListDeletedDataSource: cannot flatten item.ComputeFeatures to i.ComputeFeatures", diags))
|
||||
}
|
||||
|
||||
aclList := make([]models.RecordACLModel, 0, len(item.ACL))
|
||||
for _, acl := range item.ACL {
|
||||
a := models.RecordACLModel{
|
||||
Explicit: types.BoolValue(acl.IsExplicit),
|
||||
GUID: types.StringValue(acl.GUID),
|
||||
Right: types.StringValue(acl.Rights),
|
||||
Status: types.StringValue(acl.Status),
|
||||
Type: types.StringValue(acl.Type),
|
||||
UserGroupID: types.StringValue(acl.UgroupID),
|
||||
}
|
||||
aclList = append(aclList, a)
|
||||
}
|
||||
|
||||
i.ACL = aclList
|
||||
items = append(items, i)
|
||||
}
|
||||
state.Items = items
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountListDeletedDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountListDeletedDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"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/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/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.AccountDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
accountId := uint64(state.AccountID.ValueInt64())
|
||||
|
||||
recordAccount, err := utilities.AccountDataSourceCheckPresence(ctx, accountId, c)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about account with ID %v", accountId), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountDataSource: before flatten", map[string]any{"account_id": accountId, "recordAccount": recordAccount})
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceAccountModel{
|
||||
AccountID: state.AccountID,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
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),
|
||||
Computes: flattenComputes(ctx, recordAccount.Computes),
|
||||
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)),
|
||||
Machines: flattenMachines(ctx, recordAccount.Machines),
|
||||
AccountName: types.StringValue(recordAccount.Name),
|
||||
ResourceLimits: flattenResourceLimits(ctx, recordAccount.ResourceLimits),
|
||||
SendAccessEmails: types.BoolValue(recordAccount.SendAccessEmails),
|
||||
Status: types.StringValue(recordAccount.Status),
|
||||
UpdatedTime: types.Int64Value(int64(recordAccount.UpdatedTime)),
|
||||
Version: types.Int64Value(int64(recordAccount.Version)),
|
||||
VINSes: types.Int64Value(int64(recordAccount.VINSes)),
|
||||
}
|
||||
|
||||
state.VINS, diags = types.ListValueFrom(ctx, types.Int64Type, recordAccount.VINS)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.AccountDataSource: cannot flatten recordAccount.VINS to state.VINS", diags))
|
||||
}
|
||||
|
||||
state.ComputeFeatures, diags = types.ListValueFrom(ctx, types.StringType, recordAccount.ComputeFeatures)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.AccountDataSource: cannot flatten recordAccount.ComputeFeatures to state.ComputeFeatures", diags))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountDataSource: after flatten", map[string]any{"account_id": state.Id.ValueString()})
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountDataSource", map[string]any{"account_id": state.Id.ValueString()})
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenComputes(ctx context.Context, computes account.Computes) types.Object {
|
||||
tflog.Info(ctx, "Start flattenComputes")
|
||||
temp := models.ComputesInAccountModel{
|
||||
Started: types.Int64Value(int64(computes.Started)),
|
||||
Stopped: types.Int64Value(int64(computes.Stopped)),
|
||||
}
|
||||
|
||||
res, err := types.ObjectValueFrom(ctx, models.ItemComputesInAccount, temp)
|
||||
if err != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenComputes struct to obj", err))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenComputes")
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenMachines(ctx context.Context, machines account.Machines) types.Object {
|
||||
tflog.Info(ctx, "Start flattenMachines")
|
||||
temp := models.MachinesInAccountModel{
|
||||
Running: types.Int64Value(int64(machines.Running)),
|
||||
Halted: types.Int64Value(int64(machines.Halted)),
|
||||
}
|
||||
|
||||
res, err := types.ObjectValueFrom(ctx, models.ItemMachinesInAccount, temp)
|
||||
if err != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenMachines struct to obj", err))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenMachines")
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenResourceLimits(ctx context.Context, limits account.ResourceLimits) types.Object {
|
||||
tflog.Info(ctx, "Start flattenResourceLimits")
|
||||
temp := models.ResourceLimitsInAccountModel{
|
||||
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),
|
||||
}
|
||||
|
||||
res, err := types.ObjectValueFrom(ctx, models.ItemResourceLimitsInAccount, temp)
|
||||
if err != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenResourceLimits struct to obj", err))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenResourceLimits")
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenACLInAccount(ctx context.Context, aclList []account.RecordACL) types.List {
|
||||
tflog.Info(ctx, "Start flattenACLInAccount")
|
||||
tempSlice := make([]types.Object, 0, len(aclList))
|
||||
for _, item := range aclList {
|
||||
temp := models.ACLInAccountModel{
|
||||
Explicit: types.BoolValue(item.IsExplicit),
|
||||
GUID: types.StringValue(item.GUID),
|
||||
Right: types.StringValue(item.Rights),
|
||||
Status: types.StringValue(item.Status),
|
||||
Type: types.StringValue(item.Type),
|
||||
UserGroupID: types.StringValue(item.UgroupID),
|
||||
CanBeDeleted: types.BoolValue(item.CanBeDeleted),
|
||||
}
|
||||
obj, diags := types.ObjectValueFrom(ctx, models.ItemACLInAccount, temp)
|
||||
if diags != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenACLInAccount struct to obj", diags))
|
||||
}
|
||||
tempSlice = append(tempSlice, obj)
|
||||
}
|
||||
|
||||
res, diags := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemACLInAccount}, tempSlice)
|
||||
if diags != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenACLInAccount", diags))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenACLInAccount")
|
||||
return res
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"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/cloudapi/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/utilities"
|
||||
)
|
||||
|
||||
// AccountAuditsDataSourceList flattens data source for account audits.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountAuditsDataSourceList(ctx context.Context, state *models.DataSourceAccountAuditsListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountAuditsDataSourceList")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
accountId := uint64(state.AccountID.ValueInt64())
|
||||
|
||||
auditsList, err := utilities.AccountAuditsListDataSourceCheckPresence(ctx, accountId, c)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about account audits with account ID %v", accountId), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountAuditsDataSourceList: before flatten", map[string]any{"account_id": accountId})
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceAccountAuditsListModel{
|
||||
AccountID: state.AccountID,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
}
|
||||
|
||||
items := make([]models.ItemAuditModel, 0, len(*auditsList))
|
||||
for _, item := range *auditsList {
|
||||
i := models.ItemAuditModel{
|
||||
Call: types.StringValue(item.Call),
|
||||
ResponseTime: types.Float64Value(item.ResponseTime),
|
||||
StatusCode: types.Int64Value(int64(item.StatusCode)),
|
||||
Timestamp: types.Float64Value(item.Timestamp),
|
||||
User: types.StringValue(item.User),
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
state.Items = items
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountAuditsDataSourceList: after flatten", map[string]any{"account_id": state.Id.ValueString()})
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountAuditsDataSourceList", map[string]any{"account_id": state.Id.ValueString()})
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"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/cloudapi/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/utilities"
|
||||
)
|
||||
|
||||
// AccountComputesListDataSource flattens data source for account computes list.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountComputesListDataSource(ctx context.Context, state *models.DataSourceAccountComputesListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountComputesListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
computesList, err := utilities.AccountComputesListCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about account computes list", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountComputesListDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceAccountComputesListModel{
|
||||
AccountID: state.AccountID,
|
||||
ComputeID: state.ComputeID,
|
||||
Name: state.Name,
|
||||
RGName: state.RGName,
|
||||
RGID: state.RGID,
|
||||
TechStatus: state.TechStatus,
|
||||
IPAddress: state.IPAddress,
|
||||
ExtNetName: state.ExtNetName,
|
||||
ExtNetID: state.ExtNetID,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
SortBy: state.SortBy,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
EntryCount: types.Int64Value(int64(computesList.EntryCount)),
|
||||
}
|
||||
|
||||
items := make([]models.ItemComputeModel, 0, len(computesList.Data))
|
||||
for _, item := range computesList.Data {
|
||||
i := models.ItemComputeModel{
|
||||
AccountID: types.Int64Value(int64(item.AccountID)),
|
||||
AccountName: types.StringValue(item.AccountName),
|
||||
CPUs: types.Int64Value(int64(item.CPUs)),
|
||||
CreatedBy: types.StringValue(item.CreatedBy),
|
||||
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
|
||||
DeletedBy: types.StringValue(item.DeletedBy),
|
||||
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
|
||||
ComputeID: types.Int64Value(int64(item.ComputeID)),
|
||||
ComputeName: types.StringValue(item.ComputeName),
|
||||
RAM: types.Int64Value(int64(item.RAM)),
|
||||
Registered: types.BoolValue(item.Registered),
|
||||
RGID: types.Int64Value(int64(item.RGID)),
|
||||
RGName: types.StringValue(item.RGName),
|
||||
Status: types.StringValue(item.Status),
|
||||
TechStatus: types.StringValue(item.TechStatus),
|
||||
TotalDisksSize: types.Int64Value(int64(item.TotalDisksSize)),
|
||||
UpdatedBy: types.StringValue(item.UpdatedBy),
|
||||
UpdatedTime: types.Int64Value(int64(item.UpdatedTime)),
|
||||
UserManaged: types.BoolValue(item.UserManaged),
|
||||
VINSConnected: types.Int64Value(int64(item.VINSConnected)),
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
state.Items = items
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountComputesListDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountComputesListDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"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/cloudapi/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/utilities"
|
||||
)
|
||||
|
||||
// AccountConsumedUnitsDataSource flattens data source for account consumed units.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountConsumedUnitsDataSource(ctx context.Context, state *models.DataSourceAccountConsumedUnitsModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountConsumedUnitsDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
accountId := uint64(state.AccountID.ValueInt64())
|
||||
|
||||
limits, err := utilities.AccountConsumedUnitsDataSourceCheckPresence(ctx, accountId, c)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about account consumed units with account ID %v", accountId), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceAccountConsumedUnitsModel{
|
||||
AccountID: state.AccountID,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
CUC: types.Float64Value(limits.CUC),
|
||||
CUD: types.Float64Value(limits.CUD),
|
||||
CUDM: types.Float64Value(limits.CUDM),
|
||||
CUI: types.Float64Value(limits.CUI),
|
||||
CUM: types.Float64Value(limits.CUM),
|
||||
CUNP: types.Float64Value(limits.CUNP),
|
||||
GPUUnits: types.Float64Value(limits.GPUUnits),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountConsumedUnitsDataSource", map[string]any{"account_id": state.Id.ValueString()})
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"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/cloudapi/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/utilities"
|
||||
)
|
||||
|
||||
// AccountConsumedUnitsByTypeDataSource flattens data source for account consumed units by type.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountConsumedUnitsByTypeDataSource(ctx context.Context, state *models.DataSourceAccountConsumedUnitsByTypeModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountConsumedUnitsByTypeDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
accountId := uint64(state.AccountID.ValueInt64())
|
||||
cuType := state.CUType.ValueString()
|
||||
|
||||
res, err := utilities.AccountConsumedUnitsByTypeDataSourceCheckPresence(ctx, accountId, cuType, c)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about account consumed units by type with account ID %v", accountId), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountConsumedUnitsByTypeDataSource: before flatten", map[string]any{"account_id": accountId, "res": res})
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceAccountConsumedUnitsByTypeModel{
|
||||
AccountID: state.AccountID,
|
||||
CUType: state.CUType,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
CUResult: types.Float64Value(res),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountConsumedUnitsByTypeDataSource", map[string]any{"account_id": state.Id.ValueString()})
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"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/cloudapi/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/utilities"
|
||||
)
|
||||
|
||||
// AccountDisksListDataSource flattens data source for account disks list.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountDisksListDataSource(ctx context.Context, state *models.DataSourceAccountDisksListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountDisksListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
disksList, err := utilities.AccountDisksListCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("flattens.AccountDisksListDataSource: Cannot get info", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountDisksListDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceAccountDisksListModel{
|
||||
AccountID: state.AccountID,
|
||||
DiskID: state.DiskID,
|
||||
Name: state.Name,
|
||||
DiskMaxSize: state.DiskMaxSize,
|
||||
Type: state.Type,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
SortBy: state.SortBy,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
EntryCount: types.Int64Value(int64(disksList.EntryCount)),
|
||||
}
|
||||
|
||||
items := make([]models.ItemDiskModel, 0, len(disksList.Data))
|
||||
for _, item := range disksList.Data {
|
||||
i := models.ItemDiskModel{
|
||||
DiskID: types.Int64Value(int64(item.ID)),
|
||||
DiskName: types.StringValue(item.Name),
|
||||
Pool: types.StringValue(item.Pool),
|
||||
SEPID: types.Int64Value(int64(item.SEPID)),
|
||||
Shareable: types.BoolValue(item.Shareable),
|
||||
SizeMax: types.Int64Value(int64(item.SizeMax)),
|
||||
Type: types.StringValue(item.Type),
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
state.Items = items
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountDisksListDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountDisksListDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"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/cloudapi/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/utilities"
|
||||
)
|
||||
|
||||
// AccountFlipgroupsListDataSource flattens data source for account flipgroups list.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountFlipgroupsListDataSource(ctx context.Context, state *models.DataSourceAccountFlipgroupsListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountFlipgroupsListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
flipgroups, err := utilities.AccountFlipgroupsListCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about account flipgroups list", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountFlipgroupsListDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceAccountFlipgroupsListModel{
|
||||
AccountID: state.AccountID,
|
||||
Name: state.Name,
|
||||
VINSID: state.VINSID,
|
||||
VINSName: state.VINSName,
|
||||
ExtNetID: state.ExtNetID,
|
||||
ByIP: state.ByIP,
|
||||
FLIPGroupID: state.FLIPGroupID,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
EntryCount: types.Int64Value(int64(flipgroups.EntryCount)),
|
||||
}
|
||||
|
||||
items := make([]models.ItemAccountFlipgroupModel, 0, len(flipgroups.Data))
|
||||
for _, item := range flipgroups.Data {
|
||||
i := models.ItemAccountFlipgroupModel{
|
||||
AccountID: types.Int64Value(int64(item.AccountID)),
|
||||
ClientType: types.StringValue(item.ClientType),
|
||||
ConnType: types.StringValue(item.ConnType),
|
||||
CreatedBy: types.StringValue(item.CreatedBy),
|
||||
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
|
||||
DefaultGW: types.StringValue(item.DefaultGW),
|
||||
DeletedBy: types.StringValue(item.DeletedBy),
|
||||
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
|
||||
Description: types.StringValue(item.Description),
|
||||
GID: types.Int64Value(int64(item.GID)),
|
||||
GUID: types.Int64Value(int64(item.GUID)),
|
||||
ID: types.Int64Value(int64(item.ID)),
|
||||
IP: types.StringValue(item.IP),
|
||||
Milestones: types.Int64Value(int64(item.Milestones)),
|
||||
Name: types.StringValue(item.Name),
|
||||
NetID: types.Int64Value(int64(item.NetID)),
|
||||
NetType: types.StringValue(item.NetType),
|
||||
NetMask: types.Int64Value(int64(item.NetMask)),
|
||||
Status: types.StringValue(item.Status),
|
||||
UpdatedBy: types.StringValue(item.UpdatedBy),
|
||||
UpdatedTime: types.Int64Value(int64(item.UpdatedTime)),
|
||||
}
|
||||
|
||||
items = append(items, i)
|
||||
}
|
||||
state.Items = items
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountFlipgroupsListDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
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/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/utilities"
|
||||
)
|
||||
|
||||
// AccountGetResourceConsumptionDataSource flattens data source for account.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountGetResourceConsumptionDataSource(ctx context.Context, state *models.AccountGetResourceConsumptionModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountGetResourceConsumptionDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
accountId := uint64(state.AccountID.ValueInt64())
|
||||
|
||||
record, err := utilities.AccountGetResourceConsumptionDataSourceCheckPresence(ctx, accountId, c)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about account with ID %v", accountId), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountGetResourceConsumptionDataSource: before flatten", map[string]any{"account_id": accountId, "record": record})
|
||||
|
||||
*state = models.AccountGetResourceConsumptionModel{
|
||||
AccountID: state.AccountID,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Consumed: &models.ResourceConsumptionModel{
|
||||
CPU: types.Int64Value(record.Consumed.CPU),
|
||||
DiskSize: types.Float64Value(record.Consumed.DiskSize),
|
||||
DiskSizeMax: types.Float64Value(record.Consumed.DiskSizeMax),
|
||||
ExtIPs: types.Int64Value(record.Consumed.ExtIPs),
|
||||
ExtTraffic: types.Int64Value(record.Consumed.ExtTraffic),
|
||||
GPU: types.Int64Value(record.Consumed.GPU),
|
||||
RAM: types.Int64Value(record.Consumed.RAM),
|
||||
SEPs: flattenResourceConsumptionSep(ctx, record.Consumed.SEPs),
|
||||
},
|
||||
Limits: &models.ResourceConsumptionLimitsModel{
|
||||
CUC: types.Float64Value(record.ResourceLimits.CUC),
|
||||
CUD: types.Float64Value(record.ResourceLimits.CUD),
|
||||
CUI: types.Float64Value(record.ResourceLimits.CUI),
|
||||
CUM: types.Float64Value(record.ResourceLimits.CUM),
|
||||
CUDM: types.Float64Value(record.ResourceLimits.CUDM),
|
||||
CUNP: types.Float64Value(record.ResourceLimits.CUNP),
|
||||
GPUUnits: types.Float64Value(record.ResourceLimits.GPUUnits),
|
||||
},
|
||||
Reserved: &models.ResourceConsumptionModel{
|
||||
CPU: types.Int64Value(record.Reserved.CPU),
|
||||
DiskSize: types.Float64Value(record.Reserved.DiskSize),
|
||||
DiskSizeMax: types.Float64Value(record.Reserved.DiskSizeMax),
|
||||
ExtIPs: types.Int64Value(record.Reserved.ExtIPs),
|
||||
ExtTraffic: types.Int64Value(record.Reserved.ExtTraffic),
|
||||
GPU: types.Int64Value(record.Reserved.GPU),
|
||||
RAM: types.Int64Value(record.Reserved.RAM),
|
||||
SEPs: flattenResourceConsumptionSep(ctx, record.Reserved.SEPs),
|
||||
},
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountGetResourceConsumptionDataSource: after flatten", map[string]any{"account_id": state.AccountID.ValueInt64()})
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountGetResourceConsumptionDataSource", map[string]any{"account_id": state.AccountID.ValueInt64()})
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenResourceConsumptionSep(ctx context.Context, seps map[string]map[string]account.DiskUsage) []models.ResourceConsumptionSepModel {
|
||||
tflog.Info(ctx, "Start flattenResourceConsumption")
|
||||
res := make([]models.ResourceConsumptionSepModel, 0, len(seps))
|
||||
for sepId := range seps {
|
||||
for poolName, diskData := range seps[sepId] {
|
||||
s := models.ResourceConsumptionSepModel{
|
||||
SepID: types.StringValue(sepId),
|
||||
PoolName: types.StringValue(poolName),
|
||||
DiskSize: types.Float64Value(diskData.DiskSize),
|
||||
DiskSizeMax: types.Float64Value(diskData.DiskSizeMax),
|
||||
}
|
||||
res = append(res, s)
|
||||
}
|
||||
}
|
||||
tflog.Info(ctx, "End flattenResourceConsumption")
|
||||
return res
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
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/cloudapi/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/utilities"
|
||||
)
|
||||
|
||||
// AccountGetResourceConsumptionList flattens data source for rg get resource consumption.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountGetResourceConsumptionList(ctx context.Context, state *models.AccountGetResourceConsumptionListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountGetResourceConsumptionList")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
resConsList, err := utilities.AccountGetResourceConsumptionListDataSourceCheckPresence(ctx, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about resource consumptions", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountGetResourceConsumptionList: before flatten")
|
||||
|
||||
*state = models.AccountGetResourceConsumptionListModel{
|
||||
EntryCount: state.EntryCount,
|
||||
Timeouts: state.Timeouts,
|
||||
}
|
||||
|
||||
items := make([]models.AccountGetResourceConsumptionListItemModel, 0, len(resConsList.Data))
|
||||
for _, resConsItem := range resConsList.Data {
|
||||
item := models.AccountGetResourceConsumptionListItemModel{
|
||||
AccountId: types.Int64Value(int64(resConsItem.AccountID)),
|
||||
Consumed: &models.ResourceConsumptionListModel{
|
||||
CPU: types.Int64Value(resConsItem.Consumed.CPU),
|
||||
DiskSize: types.Float64Value(resConsItem.Consumed.DiskSize),
|
||||
DiskSizeMax: types.Float64Value(resConsItem.Consumed.DiskSizeMax),
|
||||
ExtIPs: types.Int64Value(resConsItem.Consumed.ExtIPs),
|
||||
ExtTraffic: types.Int64Value(resConsItem.Consumed.ExtTraffic),
|
||||
GPU: types.Int64Value(resConsItem.Consumed.GPU),
|
||||
RAM: types.Int64Value(resConsItem.Consumed.RAM),
|
||||
},
|
||||
Reserved: &models.ResourceConsumptionListModel{
|
||||
CPU: types.Int64Value(resConsItem.Reserved.CPU),
|
||||
DiskSize: types.Float64Value(resConsItem.Reserved.DiskSize),
|
||||
DiskSizeMax: types.Float64Value(resConsItem.Reserved.DiskSizeMax),
|
||||
ExtIPs: types.Int64Value(resConsItem.Reserved.ExtIPs),
|
||||
ExtTraffic: types.Int64Value(resConsItem.Reserved.ExtTraffic),
|
||||
GPU: types.Int64Value(resConsItem.Reserved.GPU),
|
||||
RAM: types.Int64Value(resConsItem.Reserved.RAM),
|
||||
},
|
||||
}
|
||||
|
||||
sepsConsumed := make([]models.ResourceConsumptionSepListModel, 0, len(resConsItem.Consumed.SEPs))
|
||||
for sepId, data := range resConsItem.Consumed.SEPs {
|
||||
for dataName, diskData := range data {
|
||||
sepItem := models.ResourceConsumptionSepListModel{
|
||||
SepID: types.StringValue(sepId),
|
||||
PoolName: types.StringValue(dataName),
|
||||
DiskSize: types.Float64Value(diskData.DiskSize),
|
||||
DiskSizeMax: types.Float64Value(diskData.DiskSizeMax),
|
||||
}
|
||||
sepsConsumed = append(sepsConsumed, sepItem)
|
||||
}
|
||||
}
|
||||
item.Consumed.SEPs = sepsConsumed
|
||||
|
||||
sepsReserved := make([]models.ResourceConsumptionSepListModel, 0, len(resConsItem.Reserved.SEPs))
|
||||
for sepId, data := range resConsItem.Reserved.SEPs {
|
||||
for dataName, diskData := range data {
|
||||
sepItem := models.ResourceConsumptionSepListModel{
|
||||
SepID: types.StringValue(sepId),
|
||||
PoolName: types.StringValue(dataName),
|
||||
DiskSize: types.Float64Value(diskData.DiskSize),
|
||||
DiskSizeMax: types.Float64Value(diskData.DiskSizeMax),
|
||||
}
|
||||
sepsReserved = append(sepsReserved, sepItem)
|
||||
}
|
||||
}
|
||||
item.Reserved.SEPs = sepsReserved
|
||||
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
state.Items = items
|
||||
state.EntryCount = types.Int64Value(int64(resConsList.EntryCount))
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountGetResourceConsumptionList: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountGetResourceConsumptionList")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"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/cloudapi/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/utilities"
|
||||
)
|
||||
|
||||
// AccountListDataSource 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 AccountListDataSource(ctx context.Context, state *models.DataSourceAccountListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
accountList, err := utilities.AccountListCheckPresence(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,
|
||||
Status: state.Status,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
SortBy: state.SortBy,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
EntryCount: types.Int64Value(int64(accountList.EntryCount)),
|
||||
}
|
||||
items := make([]models.ItemAccountListModel, 0, len(accountList.Data))
|
||||
for _, item := range accountList.Data {
|
||||
i := models.ItemAccountListModel{
|
||||
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
|
||||
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
|
||||
AccountID: types.Int64Value(int64(item.ID)),
|
||||
AccountName: types.StringValue(item.Name),
|
||||
Status: types.StringValue(item.Status),
|
||||
UpdatedTime: types.Int64Value(int64(item.UpdatedTime)),
|
||||
}
|
||||
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))
|
||||
}
|
||||
|
||||
aclList := make([]models.RecordACLModel, 0, len(item.ACL))
|
||||
for _, acl := range item.ACL {
|
||||
a := models.RecordACLModel{
|
||||
Explicit: types.BoolValue(acl.IsExplicit),
|
||||
GUID: types.StringValue(acl.GUID),
|
||||
Right: types.StringValue(acl.Rights),
|
||||
Status: types.StringValue(acl.Status),
|
||||
Type: types.StringValue(acl.Type),
|
||||
UserGroupID: types.StringValue(acl.UgroupID),
|
||||
}
|
||||
aclList = append(aclList, a)
|
||||
}
|
||||
|
||||
i.ACL = aclList
|
||||
items = append(items, i)
|
||||
}
|
||||
state.Items = items
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountListDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountListDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
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/terraform-provider-dynamix/internal/service/cloudapi/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/utilities"
|
||||
)
|
||||
|
||||
// AccountReservedUnitsDataSource flattens data source for account.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountReservedUnitsDataSource(ctx context.Context, state *models.DataSourceAccountReservedUnitsModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountReservedUnitsDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
accountId := uint64(state.AccountID.ValueInt64())
|
||||
|
||||
recordAccount, err := utilities.AccountReservedUnitsCheck(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about account with ID %v", accountId), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountReservedUnitsDataSource: before flatten", map[string]any{"account_id": accountId, "recordAccount": recordAccount})
|
||||
|
||||
*state = models.DataSourceAccountReservedUnitsModel{
|
||||
AccountID: state.AccountID,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
CUC: types.Float64Value(recordAccount.CUC),
|
||||
CUD: types.Float64Value(recordAccount.CUD),
|
||||
CUI: types.Float64Value(recordAccount.CUI),
|
||||
CUM: types.Float64Value(recordAccount.CUM),
|
||||
CUDM: types.Float64Value(recordAccount.CUDM),
|
||||
CUNP: types.Float64Value(recordAccount.CUNP),
|
||||
GPUUnits: types.Float64Value(recordAccount.GPUUnits),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountReservedUnitsDataSource: after flatten", map[string]any{"account_id": state.AccountID.ValueInt64()})
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountReservedUnitsDataSource", map[string]any{"account_id": state.AccountID.ValueInt64()})
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"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/cloudapi/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/utilities"
|
||||
)
|
||||
|
||||
// AccountRGListDataSource flattens data source for account rg list.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountRGListDataSource(ctx context.Context, state *models.DataSourceAccountRGListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountRGListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
rgList, err := utilities.AccountRGListCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about account rg list", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountRGListDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceAccountRGListModel{
|
||||
AccountID: state.AccountID,
|
||||
RGID: state.RGID,
|
||||
VinsID: state.VinsID,
|
||||
VMID: state.VMID,
|
||||
Name: state.Name,
|
||||
Status: state.Status,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
SortBy: state.SortBy,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
EntryCount: types.Int64Value(int64(rgList.EntryCount)),
|
||||
}
|
||||
|
||||
items := make([]models.ItemAccountRGModel, 0, len(rgList.Data))
|
||||
for _, item := range rgList.Data {
|
||||
i := models.ItemAccountRGModel{
|
||||
Computes: &models.RGComputesModel{
|
||||
Started: types.Int64Value(int64(item.Computes.Started)),
|
||||
Stopped: types.Int64Value(int64(item.Computes.Stopped)),
|
||||
},
|
||||
Resources: &models.RGResourcesModel{
|
||||
Consumed: &models.ResourceModel{
|
||||
CPU: types.Int64Value(item.Resources.Consumed.CPU),
|
||||
DiskSize: types.Float64Value(item.Resources.Consumed.DiskSize),
|
||||
DiskSizeMax: types.Float64Value(item.Resources.Consumed.DiskSizeMax),
|
||||
ExtIPs: types.Int64Value(item.Resources.Consumed.ExtIPs),
|
||||
ExtTraffic: types.Int64Value(item.Resources.Consumed.ExtTraffic),
|
||||
GPU: types.Int64Value(item.Resources.Consumed.GPU),
|
||||
RAM: types.Int64Value(item.Resources.Consumed.RAM),
|
||||
SEPs: flattenSep(item.Resources.Consumed.SEPs),
|
||||
},
|
||||
Limits: &models.LimitsRGModel{
|
||||
CPU: types.Int64Value(item.Resources.Limits.CPU),
|
||||
DiskSize: types.Int64Value(item.Resources.Limits.DiskSize),
|
||||
DiskSizeMax: types.Int64Value(item.Resources.Limits.DiskSizeMax),
|
||||
ExtIPs: types.Int64Value(item.Resources.Limits.ExtIPs),
|
||||
ExtTraffic: types.Int64Value(item.Resources.Limits.ExtTraffic),
|
||||
GPU: types.Int64Value(item.Resources.Limits.GPU),
|
||||
RAM: types.Int64Value(item.Resources.Limits.RAM),
|
||||
SEPs: types.Int64Value(int64(item.Resources.Limits.SEPs)),
|
||||
},
|
||||
Reserved: &models.ResourceModel{
|
||||
CPU: types.Int64Value(item.Resources.Reserved.CPU),
|
||||
DiskSize: types.Float64Value(item.Resources.Reserved.DiskSize),
|
||||
DiskSizeMax: types.Float64Value(item.Resources.Reserved.DiskSizeMax),
|
||||
ExtIPs: types.Int64Value(item.Resources.Reserved.ExtIPs),
|
||||
ExtTraffic: types.Int64Value(item.Resources.Reserved.ExtTraffic),
|
||||
GPU: types.Int64Value(item.Resources.Reserved.GPU),
|
||||
RAM: types.Int64Value(item.Resources.Reserved.RAM),
|
||||
SEPs: flattenSep(item.Resources.Reserved.SEPs),
|
||||
},
|
||||
},
|
||||
CreatedBy: types.StringValue(item.CreatedBy),
|
||||
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
|
||||
DeletedBy: types.StringValue(item.DeletedBy),
|
||||
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
|
||||
RGID: types.Int64Value(int64(item.RGID)),
|
||||
Milestones: types.Int64Value(int64(item.Milestones)),
|
||||
RGName: types.StringValue(item.RGName),
|
||||
Status: types.StringValue(item.Status),
|
||||
UpdatedBy: types.StringValue(item.UpdatedBy),
|
||||
UpdatedTime: types.Int64Value(int64(item.UpdatedTime)),
|
||||
VINSes: types.Int64Value(int64(item.VINSes)),
|
||||
}
|
||||
|
||||
items = append(items, i)
|
||||
}
|
||||
state.Items = items
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountRGListDataSource")
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenSep(seps map[string]map[string]account.DiskUsage) []models.SepModel {
|
||||
res := make([]models.SepModel, 0, len(seps))
|
||||
for sepId := range seps {
|
||||
for poolName, diskData := range seps[sepId] {
|
||||
s := models.SepModel{
|
||||
SepID: types.StringValue(sepId),
|
||||
PoolName: types.StringValue(poolName),
|
||||
DiskSize: types.Float64Value(diskData.DiskSize),
|
||||
DiskSizeMax: types.Float64Value(diskData.DiskSizeMax),
|
||||
}
|
||||
res = append(res, s)
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"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/cloudapi/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/utilities"
|
||||
)
|
||||
|
||||
// AccountTemplatesListDataSource flattens data source for account templates list.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountTemplatesListDataSource(ctx context.Context, state *models.DataSourceAccountTemplatesListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountTemplatesListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
templatesList, err := utilities.AccountTemplatesListCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about account templates list", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountTemplatesListDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceAccountTemplatesListModel{
|
||||
AccountID: state.AccountID,
|
||||
IncludeDeleted: state.IncludeDeleted,
|
||||
ImageID: state.ImageID,
|
||||
Name: state.Name,
|
||||
Type: state.Type,
|
||||
SortBy: state.SortBy,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
EntryCount: types.Int64Value(int64(templatesList.EntryCount)),
|
||||
}
|
||||
|
||||
items := make([]models.ItemTemplateModel, 0, len(templatesList.Data))
|
||||
for _, item := range templatesList.Data {
|
||||
i := models.ItemTemplateModel{
|
||||
UNCPath: types.StringValue(item.UNCPath),
|
||||
AccountID: types.Int64Value(int64(item.AccountID)),
|
||||
Description: types.StringValue(item.Description),
|
||||
ID: types.Int64Value(int64(item.ID)),
|
||||
Name: types.StringValue(item.Name),
|
||||
Public: types.BoolValue(item.Public),
|
||||
Size: types.Int64Value(int64(item.Size)),
|
||||
Status: types.StringValue(item.Status),
|
||||
Type: types.StringValue(item.Type),
|
||||
Username: types.StringValue(item.Username),
|
||||
}
|
||||
|
||||
items = append(items, i)
|
||||
}
|
||||
state.Items = items
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountTemplatesListDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -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/cloudapi/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/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,139 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
||||
|
||||
"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/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/utilities"
|
||||
)
|
||||
|
||||
// AccountResource flattens resource for account.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountResource(ctx context.Context, state *models.ResourceAccountModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountResource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
accountId := uint64(state.AccountID.ValueInt64())
|
||||
if accountId == 0 {
|
||||
id, err := strconv.Atoi(state.Id.ValueString())
|
||||
if err != nil {
|
||||
diags.AddError(
|
||||
"flattens.AccountResource: cannot parse resource ID from state",
|
||||
err.Error())
|
||||
return diags
|
||||
}
|
||||
accountId = uint64(id)
|
||||
}
|
||||
|
||||
recordAccount, err := utilities.AccountResourceCheckPresence(ctx, accountId, c)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("flattens.AccountResource: Cannot get info about resource with ID %v", accountId), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountResource: before flatten", map[string]any{"account_id": accountId, "recordAccount": recordAccount})
|
||||
|
||||
*state = models.ResourceAccountModel{
|
||||
// request fields
|
||||
AccountName: types.StringValue(recordAccount.Name),
|
||||
Username: state.Username,
|
||||
EmailAddress: state.EmailAddress,
|
||||
SendAccessEmails: state.SendAccessEmails,
|
||||
Users: state.Users,
|
||||
Restore: state.Restore,
|
||||
Permanently: state.Permanently,
|
||||
Enable: state.Enable,
|
||||
ResourceLimits: flattenResourceLimitsInAccountResource(ctx, recordAccount.ResourceLimits, state),
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
// response fields
|
||||
Id: types.StringValue(strconv.Itoa(int(accountId))),
|
||||
LastUpdated: state.LastUpdated,
|
||||
AccountID: types.Int64Value(int64(recordAccount.ID)),
|
||||
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),
|
||||
Computes: flattenComputes(ctx, recordAccount.Computes),
|
||||
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)),
|
||||
Machines: flattenMachines(ctx, recordAccount.Machines),
|
||||
Status: types.StringValue(recordAccount.Status),
|
||||
UpdatedTime: types.Int64Value(int64(recordAccount.UpdatedTime)),
|
||||
Version: types.Int64Value(int64(recordAccount.Version)),
|
||||
VINSes: types.Int64Value(int64(recordAccount.VINSes)),
|
||||
}
|
||||
|
||||
state.VINS, diags = types.ListValueFrom(ctx, types.Int64Type, recordAccount.VINS)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.AccountResource: cannot flatten recordAccount.VINS to state.VINS", diags))
|
||||
}
|
||||
|
||||
state.ComputeFeatures, diags = types.ListValueFrom(ctx, types.StringType, recordAccount.ComputeFeatures)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.AccountResource: cannot flatten recordAccount.ComputeFeatures to state.ComputeFeatures", diags))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountResource: after flatten", map[string]any{"account_id": state.Id.ValueString()})
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountResource", map[string]any{"account_id": state.Id.ValueString()})
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenResourceLimitsInAccountResource(ctx context.Context, limits account.ResourceLimits, state *models.ResourceAccountModel) types.Object {
|
||||
tflog.Info(ctx, "Start flattenResourceLimitsInAccountResource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
var resourceLimits models.ResourceLimitsInAccountResourceModel
|
||||
diags.Append(state.ResourceLimits.As(ctx, &resourceLimits, basetypes.ObjectAsOptions{})...)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, "flattenResourceLimitsInAccountResource: cannot populate resourceLimits with plan.ResourceLimits object element")
|
||||
}
|
||||
|
||||
if resourceLimits.CUC.ValueFloat64() == 0 {
|
||||
resourceLimits.CUC = types.Float64Value(limits.CUC)
|
||||
}
|
||||
if resourceLimits.CUD.ValueFloat64() == 0 {
|
||||
resourceLimits.CUD = types.Float64Value(limits.CUD)
|
||||
}
|
||||
if resourceLimits.CUI.ValueFloat64() == 0 {
|
||||
resourceLimits.CUI = types.Float64Value(limits.CUI)
|
||||
}
|
||||
if resourceLimits.CUM.ValueFloat64() == 0 {
|
||||
resourceLimits.CUM = types.Float64Value(limits.CUM)
|
||||
}
|
||||
if resourceLimits.CUNP.ValueFloat64() == 0 {
|
||||
resourceLimits.CUNP = types.Float64Value(limits.CUNP)
|
||||
}
|
||||
if resourceLimits.GPUUnits.ValueFloat64() == 0 {
|
||||
resourceLimits.GPUUnits = types.Float64Value(limits.GPUUnits)
|
||||
}
|
||||
|
||||
res, err := types.ObjectValueFrom(ctx, models.ItemResourceLimitsInAccountResource, resourceLimits)
|
||||
if err != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenResourceLimitsInAccountResource struct to obj", err))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenResourceLimitsInAccountResource")
|
||||
return res
|
||||
}
|
||||
Reference in New Issue
Block a user