1.0.1
This commit is contained in:
@@ -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/cloudbroker/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/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,41 @@
|
||||
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/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"
|
||||
)
|
||||
|
||||
// AccountAvailableTemplatesListDataSource flattens data source for templates list.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func AccountAvailableTemplatesListDataSource(ctx context.Context, state *models.DataSourceAccountAvailableTemplatesListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountAvailableTemplatesListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
templatesList, err := utilities.AccountAvailableTemplatesListDataSourceCheckPresence(ctx, uint64(state.AccountID.ValueInt64()), c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about templates list", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountAvailableTemplatesListDataSource: before flatten")
|
||||
|
||||
*state = models.DataSourceAccountAvailableTemplatesListModel{
|
||||
AccountID: state.AccountID,
|
||||
Timeouts: state.Timeouts,
|
||||
Items: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, templatesList),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountAvailableTemplatesListDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountAvailableTemplatesListDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// 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.ListComputesModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AccountComputesListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
cList, err := utilities.AccountComputesListDataSourceCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about computes list", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountComputesListDataSource: before flatten")
|
||||
|
||||
*state = models.ListComputesModel{
|
||||
AccountID: state.AccountID,
|
||||
Name: state.Name,
|
||||
RGName: state.RGName,
|
||||
RGID: state.RGID,
|
||||
TechStatus: state.TechStatus,
|
||||
IpAddress: state.IpAddress,
|
||||
ExtNetName: state.ExtNetName,
|
||||
ExtNetID: state.ExtNetID,
|
||||
SortBy: state.SortBy,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
EntryCount: types.Int64Value(int64(cList.EntryCount)),
|
||||
}
|
||||
|
||||
data := make([]models.ItemComputeModel, 0, len(cList.Data))
|
||||
|
||||
for _, v := range cList.Data {
|
||||
item := models.ItemComputeModel{
|
||||
AccountID: types.Int64Value(int64(v.AccountID)),
|
||||
AccountName: types.StringValue(v.AccountName),
|
||||
CPUs: types.Int64Value(int64(v.CPUs)),
|
||||
CreatedBy: types.StringValue(v.CreatedBy),
|
||||
CreatedTime: types.Int64Value(int64(v.CreatedTime)),
|
||||
DeletedBy: types.StringValue(v.DeletedBy),
|
||||
DeletedTime: types.Int64Value(int64(v.DeletedTime)),
|
||||
ID: types.Int64Value(int64(v.ID)),
|
||||
Name: types.StringValue(v.Name),
|
||||
RAM: types.Int64Value(int64(v.RAM)),
|
||||
Registered: types.BoolValue(v.Registered),
|
||||
RGID: types.Int64Value(int64(v.RGID)),
|
||||
RgName: types.StringValue(v.RgName),
|
||||
Status: types.StringValue(v.Status),
|
||||
TechStatus: types.StringValue(v.TechStatus),
|
||||
TotalDisksSize: types.Int64Value(int64(v.TotalDisksSize)),
|
||||
UpdatedBy: types.StringValue(v.UpdatedBy),
|
||||
UpdatedTime: types.Int64Value(int64(v.UpdatedTime)),
|
||||
UserManaged: types.BoolValue(v.UserManaged),
|
||||
VINSConnected: types.Int64Value(int64(v.VINSConnected)),
|
||||
}
|
||||
data = append(data, item)
|
||||
}
|
||||
|
||||
state.Items = data
|
||||
|
||||
tflog.Info(ctx, "flattens.AccountComputesListDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.AccountComputesListDataSource")
|
||||
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/cloudbroker/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/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,81 @@
|
||||
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/cloudbroker/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/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,
|
||||
SortBy: state.SortBy,
|
||||
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/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"
|
||||
)
|
||||
|
||||
// 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,104 @@
|
||||
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/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"
|
||||
)
|
||||
|
||||
// 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{
|
||||
DCLocation: types.StringValue(item.DCLocation),
|
||||
Ckey: types.StringValue(item.CKey),
|
||||
Meta: flattens.FlattenSimpleTypeToList(ctx, types.StringType, item.Meta),
|
||||
ComputeFeatures: flattens.FlattenSimpleTypeToList(ctx, types.StringType, item.ComputeFeatures),
|
||||
Company: types.StringValue(item.Company),
|
||||
Companyurl: types.StringValue(item.CompanyURL),
|
||||
CpuAllocationParameter: types.StringValue(item.CPUAllocationParameter),
|
||||
CpuAllocationRatio: types.Float64Value(float64(item.CPUAllocationRatio)),
|
||||
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
|
||||
CreatedBy: types.StringValue(item.CreatedBy),
|
||||
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
|
||||
DeletedBy: types.StringValue(item.DeletedBy),
|
||||
AccountID: types.Int64Value(int64(item.ID)),
|
||||
GUID: types.Int64Value(int64(item.GUID)),
|
||||
AccountName: types.StringValue(item.Name),
|
||||
Status: types.StringValue(item.Status),
|
||||
UpdatedTime: types.Int64Value(int64(item.UpdatedTime)),
|
||||
ResourceLimits: &models.AccountLimitsModel{
|
||||
CUC: types.Float64Value(float64(item.ResourceLimits.CuC)),
|
||||
CUD: types.Float64Value(float64(item.ResourceLimits.CuD)),
|
||||
CUI: types.Float64Value(float64(item.ResourceLimits.CuI)),
|
||||
CUM: types.Float64Value(float64(item.ResourceLimits.CuM)),
|
||||
CUDM: types.Float64Value(float64(item.ResourceLimits.CuDM)),
|
||||
CUNP: types.Float64Value(float64(item.ResourceLimits.CuNP)),
|
||||
GPUUnits: types.Float64Value(float64(item.ResourceLimits.GPUUnits)),
|
||||
},
|
||||
ResourceTypes: flattens.FlattenSimpleTypeToList(ctx, types.StringType, item.ResTypes),
|
||||
SendAccessEmails: types.BoolValue(item.SendAccessEmails),
|
||||
UniqPools: flattens.FlattenSimpleTypeToList(ctx, types.StringType, item.UniqPools),
|
||||
Version: types.Int64Value(int64(item.Version)),
|
||||
Vins: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, item.VINS),
|
||||
}
|
||||
|
||||
aclList := make([]models.RecordACLModel, 0, len(item.ACL))
|
||||
for _, acl := range item.ACL {
|
||||
a := models.RecordACLModel{
|
||||
Explicit: types.BoolValue(acl.Explicit),
|
||||
GUID: types.StringValue(acl.GUID),
|
||||
Right: types.StringValue(acl.Right),
|
||||
Status: types.StringValue(acl.Status),
|
||||
Type: types.StringValue(acl.Type),
|
||||
UserGroupID: types.StringValue(acl.UserGroupID),
|
||||
}
|
||||
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,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/cloudbroker/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/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,124 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/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/cloudbroker/account/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/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.ID)),
|
||||
Milestones: types.Int64Value(int64(item.Milestones)),
|
||||
RGName: types.StringValue(item.Name),
|
||||
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,171 @@
|
||||
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/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"
|
||||
)
|
||||
|
||||
// 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{
|
||||
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),
|
||||
AvailableTemplates: state.AvailableTemplates,
|
||||
Timeouts: state.Timeouts,
|
||||
Id: types.StringValue(strconv.Itoa(int(accountId))),
|
||||
AccountID: types.Int64Value(int64(recordAccount.ID)),
|
||||
DCLocation: types.StringValue(recordAccount.DCLocation),
|
||||
CKey: types.StringValue(recordAccount.CKey),
|
||||
ACL: resourceFlattenACLInAccount(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)),
|
||||
Status: types.StringValue(recordAccount.Status),
|
||||
UpdatedTime: types.Int64Value(int64(recordAccount.UpdatedTime)),
|
||||
Version: types.Int64Value(int64(recordAccount.Version)),
|
||||
}
|
||||
|
||||
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.UniqPools, diags = types.ListValueFrom(ctx, types.StringType, recordAccount.UniqPools)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.AccountResource: cannot flatten recordAccount.UniqPools to state.UniqPools", diags))
|
||||
}
|
||||
|
||||
state.ResourceTypes, diags = types.ListValueFrom(ctx, types.Int64Type, recordAccount.ResTypes)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.AccountResource: cannot flatten recordAccount.ResTypes to state.ResourceTypes", diags))
|
||||
}
|
||||
|
||||
state.ComputeFeatures, diags = types.SetValueFrom(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
|
||||
}
|
||||
|
||||
func resourceFlattenACLInAccount(ctx context.Context, aclList []account.ACL) 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.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),
|
||||
}
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user