1.0.1
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
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/cloudbroker/rg"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/rg/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/rg/utilities"
|
||||
)
|
||||
|
||||
// RGDataSource flattens data source for rg (resource group).
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func RGDataSource(ctx context.Context, state *models.DataSourceRGModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.RGDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
rgId := uint64(state.RGID.ValueInt64())
|
||||
|
||||
recordRG, err := utilities.RGCheckPresence(ctx, rgId, c)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about resource group with ID %v", rgId), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.RGDataSource: before flatten", map[string]any{"rg_id": rgId, "recordRG": recordRG})
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceRGModel{
|
||||
RGID: state.RGID,
|
||||
Reason: state.Reason,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
AccountID: types.Int64Value(int64(recordRG.AccountID)),
|
||||
AccountName: types.StringValue(recordRG.AccountName),
|
||||
ACL: flattenACL(ctx, &recordRG.ACL),
|
||||
ComputeFeatures: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &recordRG.ComputeFeatures),
|
||||
Computes: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &recordRG.VMs),
|
||||
CPUAllocationParameter: types.StringValue(recordRG.CPUAllocationParameter),
|
||||
CPUAllocationRatio: types.Float64Value(recordRG.CPUAllocationRatio),
|
||||
CreatedBy: types.StringValue(recordRG.CreatedBy),
|
||||
CreatedTime: types.Int64Value(int64(recordRG.CreatedTime)),
|
||||
DefNetID: types.Int64Value(recordRG.DefNetID),
|
||||
DefNetType: types.StringValue(recordRG.DefNetType),
|
||||
DeletedBy: types.StringValue(recordRG.DeletedBy),
|
||||
DeletedTime: types.Int64Value(int64(recordRG.DeletedTime)),
|
||||
Description: types.StringValue(recordRG.Description),
|
||||
Dirty: types.BoolValue(recordRG.Dirty),
|
||||
GID: types.Int64Value(int64(recordRG.GID)),
|
||||
GUID: types.Int64Value(int64(recordRG.GUID)),
|
||||
LockStatus: types.StringValue(recordRG.LockStatus),
|
||||
Milestones: types.Int64Value(int64(recordRG.Milestones)),
|
||||
Name: types.StringValue(recordRG.Name),
|
||||
RegisterComputes: types.BoolValue(recordRG.RegisterComputes),
|
||||
ResourceLimits: flattenResourceLimits(ctx, &recordRG.ResourceLimits),
|
||||
ResourceTypes: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &recordRG.ResTypes),
|
||||
Secret: types.StringValue(recordRG.Secret),
|
||||
Status: types.StringValue(recordRG.Status),
|
||||
UniqPools: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &recordRG.UniqPools),
|
||||
UpdatedBy: types.StringValue(recordRG.UpdatedBy),
|
||||
UpdatedTime: types.Int64Value(int64(recordRG.UpdatedTime)),
|
||||
VINS: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &recordRG.VINS),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.RGDataSource: after flatten", map[string]any{"rg_id": state.Id.ValueString()})
|
||||
|
||||
tflog.Info(ctx, "End flattens.RGDataSource", map[string]any{"rg_id": state.Id.ValueString()})
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenACL(ctx context.Context, item *rg.ListACL) types.List {
|
||||
tflog.Info(ctx, "Start flattenACLItems")
|
||||
tempSlice := make([]types.Object, 0, len(*item))
|
||||
for _, aclItem := range *item {
|
||||
temp := models.ItemACLModel{
|
||||
Explicit: types.BoolValue(aclItem.Explicit),
|
||||
GUID: types.StringValue(aclItem.GUID),
|
||||
Right: types.StringValue(aclItem.Right),
|
||||
Status: types.StringValue(aclItem.Status),
|
||||
Type: types.StringValue(aclItem.Type),
|
||||
UserGroupID: types.StringValue(aclItem.UserGroupID),
|
||||
}
|
||||
obj, diags := types.ObjectValueFrom(ctx, models.ItemACL, temp)
|
||||
if diags != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenACLItems struct to obj", diags))
|
||||
}
|
||||
tempSlice = append(tempSlice, obj)
|
||||
}
|
||||
|
||||
res, diags := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemACL}, tempSlice)
|
||||
if diags != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenACLItems", diags))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenACLItems")
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenResourceLimits(ctx context.Context, item *rg.ResourceLimits) types.Object {
|
||||
tflog.Info(ctx, "Start flattenResourceLimits")
|
||||
temp := models.ResourceLimitsModel{
|
||||
CUC: types.Float64Value(item.CUC),
|
||||
CUD: types.Float64Value(item.CuD),
|
||||
CUDM: types.Float64Value(item.CUDM),
|
||||
CUI: types.Float64Value(item.CUI),
|
||||
CUM: types.Float64Value(item.CUM),
|
||||
CUNP: types.Float64Value(item.CUNP),
|
||||
GPUUnits: types.Float64Value(item.GPUUnits),
|
||||
}
|
||||
res, diags := types.ObjectValueFrom(ctx, models.ItemResourseModel, temp)
|
||||
if diags != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenResourceLimits struct to obj", diags))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenResourceLimits")
|
||||
return res
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
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/rg/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/rg/utilities"
|
||||
)
|
||||
|
||||
// RGAffinityGroupComputesDataSource flattens data source for rg affinity group computes.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func RGAffinityGroupComputesDataSource(ctx context.Context, state *models.DataSourceRGAffinityGroupComputesModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.RGAffinityGroupComputesDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
agCompsList, err := utilities.RGAffinityGroupComputesCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about resource group affinity group computes", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.RGAffinityGroupComputesDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceRGAffinityGroupComputesModel{
|
||||
RGID: state.RGID,
|
||||
AffinityGroup: state.AffinityGroup,
|
||||
|
||||
Timeouts: state.Timeouts,
|
||||
Id: types.StringValue(id.String()),
|
||||
}
|
||||
|
||||
var diagsItem diag.Diagnostics
|
||||
items := make([]models.ItemAffinityGroupComputeModel, 0, len(*agCompsList))
|
||||
for _, comp := range *agCompsList {
|
||||
item := models.ItemAffinityGroupComputeModel{
|
||||
ComputeID: types.Int64Value(int64(comp.ComputeID)),
|
||||
}
|
||||
|
||||
item.OtherNode, diagsItem = types.ListValueFrom(ctx, types.Int64Type, comp.OtherNode)
|
||||
if diagsItem.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.RGAffinityGroupComputesDataSource: cannot flatten comp.OtherNode to item.OtherNode", diags))
|
||||
}
|
||||
item.OtherNodeIndirect, diagsItem = types.ListValueFrom(ctx, types.Int64Type, comp.OtherNodeIndirect)
|
||||
if diagsItem.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.RGAffinityGroupComputesDataSource: cannot flatten comp.OtherNodeIndirect to item.OtherNodeIndirect", diags))
|
||||
}
|
||||
item.OtherNodeIndirectSoft, diagsItem = types.ListValueFrom(ctx, types.Int64Type, comp.OtherNodeIndirectSoft)
|
||||
if diagsItem.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.RGAffinityGroupComputesDataSource: cannot flatten comp.OtherNodeIndirectSoft to item.OtherNodeIndirectSoft", diags))
|
||||
}
|
||||
item.OtherNodeSoft, diagsItem = types.ListValueFrom(ctx, types.Int64Type, comp.OtherNodeSoft)
|
||||
if diagsItem.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.RGAffinityGroupComputesDataSource: cannot flatten comp.OtherNodeSoft to item.OtherNodeSoft", diags))
|
||||
}
|
||||
item.SameNode, diagsItem = types.ListValueFrom(ctx, types.Int64Type, comp.SameNode)
|
||||
if diagsItem.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.RGAffinityGroupComputesDataSource: cannot flatten comp.SameNode to item.SameNode", diags))
|
||||
}
|
||||
item.SameNodeSoft, diagsItem = types.ListValueFrom(ctx, types.Int64Type, comp.SameNodeSoft)
|
||||
if diagsItem.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.RGAffinityGroupComputesDataSource: cannot flatten comp.SameNodeSoft to item.SameNodeSoft", diags))
|
||||
}
|
||||
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
state.Items = items
|
||||
|
||||
tflog.Info(ctx, "flattens.RGAffinityGroupComputesDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.RGAffinityGroupComputesDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
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/rg/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/rg/utilities"
|
||||
)
|
||||
|
||||
// RGAffinityGroupsGetDataSource flattens data source for rg affinity groups get.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func RGAffinityGroupsGetDataSource(ctx context.Context, state *models.DataSourceRGAffinityGroupsGetModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.RGAffinityGroupsGetDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
agItem, err := utilities.RGAffinityGroupsGetCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about resource group affinity groups get", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.RGAffinityGroupsGetDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceRGAffinityGroupsGetModel{
|
||||
RGID: state.RGID,
|
||||
AffinityGroup: state.AffinityGroup,
|
||||
|
||||
Timeouts: state.Timeouts,
|
||||
Id: types.StringValue(id.String()),
|
||||
}
|
||||
|
||||
var diagsItem diag.Diagnostics
|
||||
state.Ids, diagsItem = types.ListValueFrom(ctx, types.Int64Type, agItem)
|
||||
if diagsItem.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.RGAffinityGroupsGetDataSource: cannot flatten agItem to state.Ids", diags))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.RGAffinityGroupsGetDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.RGAffinityGroupsGetDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -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/cloudbroker/rg/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/rg/utilities"
|
||||
)
|
||||
|
||||
// RGAffinityGroupsListDataSource flattens data source for rg affinity groups list.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func RGAffinityGroupsListDataSource(ctx context.Context, state *models.DataSourceRGAffinityGroupsListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.RGAffinityGroupsListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
agList, err := utilities.RGAffinityGroupsListCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about resource group affinity groups list", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.RGAffinityGroupsListDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceRGAffinityGroupsListModel{
|
||||
RGID: state.RGID,
|
||||
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
}
|
||||
|
||||
items := make([]models.ItemAffinityGroupModel, 0, len(agList.Data))
|
||||
for _, data := range agList.Data {
|
||||
for agLabel, listAG := range data {
|
||||
item := models.ItemAffinityGroupModel{
|
||||
Label: types.StringValue(agLabel),
|
||||
}
|
||||
|
||||
ids := make([]models.ItemIDModel, 0, len(listAG))
|
||||
for _, agItem := range listAG {
|
||||
idItem := models.ItemIDModel{
|
||||
Id: types.Int64Value(int64(agItem.ID)),
|
||||
NodeId: types.Int64Value(int64(agItem.NodeID)),
|
||||
}
|
||||
ids = append(ids, idItem)
|
||||
}
|
||||
item.Ids = ids
|
||||
items = append(items, item)
|
||||
}
|
||||
}
|
||||
state.AffinityGroups = items
|
||||
state.EntryCount = types.Int64Value(int64(agList.EntryCount))
|
||||
|
||||
tflog.Info(ctx, "flattens.RGAffinityGroupsListDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.RGAffinityGroupsListDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
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/rg/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/rg/utilities"
|
||||
)
|
||||
|
||||
// RGAuditsDataSource flattens data source for rg audits.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func RGAuditsDataSource(ctx context.Context, state *models.DataSourceRGAuditsModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.RGAuditsDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
rgAudits, err := utilities.RGAuditsCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about resource group audits", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.RGAuditsDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceRGAuditsModel{
|
||||
RGID: state.RGID,
|
||||
Timeouts: state.Timeouts,
|
||||
Id: types.StringValue(id.String()),
|
||||
}
|
||||
|
||||
items := make([]models.ItemsRGAuditModel, 0, len(*rgAudits))
|
||||
for _, auditItem := range *rgAudits {
|
||||
item := models.ItemsRGAuditModel{
|
||||
Call: types.StringValue(auditItem.Call),
|
||||
ResponseTime: types.Float64Value(auditItem.ResponseTime),
|
||||
StatusCode: types.Int64Value(int64(auditItem.StatusCode)),
|
||||
Timestamp: types.Float64Value(auditItem.Timestamp),
|
||||
User: types.StringValue(auditItem.User),
|
||||
}
|
||||
|
||||
items = append(items, item)
|
||||
}
|
||||
state.Items = items
|
||||
|
||||
tflog.Info(ctx, "flattens.RGAuditsDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.RGAuditsDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
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/cloudbroker/rg"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/rg/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/rg/utilities"
|
||||
)
|
||||
|
||||
// RGGetResourceConsumptionDataSource 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 RGGetResourceConsumptionDataSource(ctx context.Context, state *models.DataSourceRGGetResourceConsumptionModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.RGGetResourceConsumptionDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
resourceItem, err := utilities.RGGetResourceConsumptionCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about resource group get resource consumption", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.RGGetResourceConsumptionDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceRGGetResourceConsumptionModel{
|
||||
RGID: state.RGID,
|
||||
Timeouts: state.Timeouts,
|
||||
Id: types.StringValue(id.String()),
|
||||
|
||||
Consumed: flattenResource(ctx, &resourceItem.Consumed),
|
||||
Reserved: flattenResource(ctx, &resourceItem.Reserved),
|
||||
ResourceLimits: flattenResourceLimits(ctx, &resourceItem.ResourceLimits),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.RGGetResourceConsumptionDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.RGGetResourceConsumptionDataSource")
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenResource(ctx context.Context, item *rg.Reservation) types.Object {
|
||||
tflog.Info(ctx, "Start flattenResource")
|
||||
temp := models.ResourceModel{
|
||||
CPU: types.Int64Value(item.CPU),
|
||||
DiskSize: types.Float64Value(item.DiskSize),
|
||||
DiskSizeMax: types.Float64Value(item.DiskSizeMax),
|
||||
ExtIPs: types.Int64Value(item.ExtIPs),
|
||||
ExtTraffic: types.Int64Value(item.ExtTraffic),
|
||||
GPU: types.Int64Value(item.GPU),
|
||||
RAM: types.Int64Value(item.RAM),
|
||||
SEPs: flattenSEPs(ctx, item.SEPs),
|
||||
}
|
||||
res, diags := types.ObjectValueFrom(ctx, models.ItemResource, temp)
|
||||
if diags != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenResource struct to obj", diags))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenResource")
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenSEPs(ctx context.Context, seps map[string]map[string]rg.DiskUsage) types.List {
|
||||
tflog.Info(ctx, "Start flattenSEPs")
|
||||
tempSlice := make([]types.Object, 0, len(seps))
|
||||
for sepId, data := range seps {
|
||||
for dataName, diskData := range data {
|
||||
sepItem := models.SEPsModel{
|
||||
SepID: types.StringValue(sepId),
|
||||
DataName: types.StringValue(dataName),
|
||||
DiskSize: types.Float64Value(diskData.DiskSize),
|
||||
DiskSizeMax: types.Float64Value(diskData.DiskSizeMax),
|
||||
}
|
||||
obj, err := types.ObjectValueFrom(ctx, models.ItemSEPs, sepItem)
|
||||
if err != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenSEPs struct to obj", err))
|
||||
}
|
||||
tempSlice = append(tempSlice, obj)
|
||||
}
|
||||
}
|
||||
|
||||
res, err := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemSEPs}, tempSlice)
|
||||
if err != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenSEPs", err))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenSEPs")
|
||||
return res
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
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/rg/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/rg/utilities"
|
||||
)
|
||||
|
||||
// RGListDataSource flattens data source for rg list.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func RGListDataSource(ctx context.Context, state *models.DataSourceRGListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.RGListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
rgList, err := utilities.RGListCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about resource group list", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.RGListDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceRGListModel{
|
||||
ById: state.ById,
|
||||
Name: state.Name,
|
||||
AccountId: state.AccountId,
|
||||
AccountName: state.AccountName,
|
||||
CreatedAfter: state.CreatedAfter,
|
||||
CreatedBefore: state.CreatedBefore,
|
||||
Status: state.Status,
|
||||
LockStatus: state.LockStatus,
|
||||
IncludeDeleted: state.IncludeDeleted,
|
||||
SortBy: state.SortBy,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
Id: types.StringValue(id.String()),
|
||||
}
|
||||
|
||||
items := make([]models.ItemsRGListModel, 0, len(rgList.Data))
|
||||
for _, rgItem := range rgList.Data {
|
||||
item := models.ItemsRGListModel{
|
||||
AccountACL: flattenACL(ctx, &rgItem.ACL),
|
||||
AccountID: types.Int64Value(int64(rgItem.AccountID)),
|
||||
AccountName: types.StringValue(rgItem.AccountName),
|
||||
ComputeFeatures: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &rgItem.ComputeFeatures),
|
||||
CPUAllocationParameter: types.StringValue(rgItem.CPUAllocationParameter),
|
||||
CPUAllocationRatio: types.Float64Value(rgItem.CPUAllocationRatio),
|
||||
CreatedBy: types.StringValue(rgItem.CreatedBy),
|
||||
CreatedTime: types.Int64Value(int64(rgItem.CreatedTime)),
|
||||
DefNetID: types.Int64Value(rgItem.DefNetID),
|
||||
DefNetType: types.StringValue(rgItem.DefNetType),
|
||||
DeletedBy: types.StringValue(rgItem.DeletedBy),
|
||||
DeletedTime: types.Int64Value(int64(rgItem.DeletedTime)),
|
||||
Description: types.StringValue(rgItem.Description),
|
||||
Dirty: types.BoolValue(rgItem.Dirty),
|
||||
GID: types.Int64Value(int64(rgItem.GID)),
|
||||
GUID: types.Int64Value(int64(rgItem.GUID)),
|
||||
RGID: types.Int64Value(int64(rgItem.ID)),
|
||||
LockStatus: types.StringValue(rgItem.LockStatus),
|
||||
Milestones: types.Int64Value(int64(rgItem.Milestones)),
|
||||
Name: types.StringValue(rgItem.Name),
|
||||
ResTypes: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &rgItem.ResTypes),
|
||||
RegisterComputes: types.BoolValue(rgItem.RegisterComputes),
|
||||
ResourceLimits: flattenResourceLimits(ctx, &rgItem.ResourceLimits),
|
||||
Secret: types.StringValue(rgItem.Secret),
|
||||
Status: types.StringValue(rgItem.Status),
|
||||
UniqPools: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &rgItem.UniqPools),
|
||||
UpdatedBy: types.StringValue(rgItem.UpdatedBy),
|
||||
UpdatedTime: types.Int64Value(int64(rgItem.UpdatedTime)),
|
||||
VINS: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &rgItem.VINS),
|
||||
VMS: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &rgItem.VMs),
|
||||
}
|
||||
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
state.Items = items
|
||||
state.EntryCount = types.Int64Value(int64(rgList.EntryCount))
|
||||
|
||||
tflog.Info(ctx, "flattens.RGListDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.RGListDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
|
||||
|
||||
"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/rg/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/rg/utilities"
|
||||
)
|
||||
|
||||
// RGListComputesDataSource flattens data source for rg list.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func RGListComputesDataSource(ctx context.Context, state *models.DataSourceRGListComputesModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.RGListComputesDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
rgListComputes, err := utilities.RGListComputesCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about resource group list computes", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.RGListComputesDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceRGListComputesModel{
|
||||
RGID: state.RGID,
|
||||
ComputeID: state.ComputeID,
|
||||
Name: state.Name,
|
||||
AccountID: state.AccountID,
|
||||
TechStatus: state.TechStatus,
|
||||
Status: state.Status,
|
||||
IPAddress: state.IPAddress,
|
||||
ExtNetName: state.ExtNetName,
|
||||
ExtNetID: state.ExtNetID,
|
||||
SortBy: state.SortBy,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
}
|
||||
|
||||
items := make([]models.ItemsRGListComputeModel, 0, len(rgListComputes.Data))
|
||||
for _, compItem := range rgListComputes.Data {
|
||||
item := models.ItemsRGListComputeModel{
|
||||
AccountID: types.Int64Value(int64(compItem.AccountID)),
|
||||
AccountName: types.StringValue(compItem.AccountName),
|
||||
AffinityLabel: types.StringValue(compItem.AffinityLabel),
|
||||
AffinityRules: flattenAffinityRules(ctx, &compItem.AffinityRules),
|
||||
AffinityWeight: types.Int64Value(int64(compItem.AffinityWeight)),
|
||||
AntiAffinityRules: flattenAffinityRules(ctx, &compItem.AntiAffinityRules),
|
||||
CPUs: types.Int64Value(int64(compItem.CPUs)),
|
||||
CreatedBy: types.StringValue(compItem.CreatedBy),
|
||||
CreatedTime: types.Int64Value(int64(compItem.CreatedTime)),
|
||||
DeletedBy: types.StringValue(compItem.DeletedBy),
|
||||
DeletedTime: types.Int64Value(int64(compItem.DeletedTime)),
|
||||
ID: types.Int64Value(int64(compItem.ID)),
|
||||
Name: types.StringValue(compItem.Name),
|
||||
RAM: types.Int64Value(int64(compItem.RAM)),
|
||||
Registered: types.BoolValue(compItem.Registered),
|
||||
RGID: types.Int64Value(int64(compItem.RGID)),
|
||||
RGName: types.StringValue(compItem.RGName),
|
||||
Status: types.StringValue(compItem.Status),
|
||||
TechStatus: types.StringValue(compItem.TechStatus),
|
||||
TotalDisksSize: types.Int64Value(int64(compItem.TotalDisksSize)),
|
||||
UpdatedBy: types.StringValue(compItem.UpdatedBy),
|
||||
UpdatedTime: types.Int64Value(int64(compItem.UpdatedTime)),
|
||||
UserManaged: types.BoolValue(compItem.UserManaged),
|
||||
VINSConnected: types.Int64Value(int64(compItem.VINSConnected)),
|
||||
}
|
||||
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
state.Items = items
|
||||
state.EntryCount = types.Int64Value(int64(rgListComputes.EntryCount))
|
||||
|
||||
tflog.Info(ctx, "flattens.RGListComputesDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.RGListComputesDataSource")
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenAffinityRules(ctx context.Context, items *rg.ListRules) types.List {
|
||||
tflog.Info(ctx, "Start flattenAffinityRules")
|
||||
tempSlice := make([]types.Object, 0, len(*items))
|
||||
for _, ruleItem := range *items {
|
||||
temp := models.AffinityRuleModel{
|
||||
GUID: types.StringValue(ruleItem.GUID),
|
||||
Key: types.StringValue(ruleItem.Key),
|
||||
Mode: types.StringValue(ruleItem.Mode),
|
||||
Policy: types.StringValue(ruleItem.Policy),
|
||||
Topology: types.StringValue(ruleItem.Topology),
|
||||
Value: types.StringValue(ruleItem.Value),
|
||||
}
|
||||
|
||||
obj, diags := types.ObjectValueFrom(ctx, models.ItemAffinityRule, temp)
|
||||
if diags != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenAffinityRules struct to obj", diags))
|
||||
}
|
||||
tempSlice = append(tempSlice, obj)
|
||||
}
|
||||
|
||||
res, diags := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemAffinityRule}, tempSlice)
|
||||
if diags != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenAffinityRules", diags))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenAffinityRules")
|
||||
return res
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
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/rg/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/rg/utilities"
|
||||
)
|
||||
|
||||
// RGListDeletedDataSource flattens data source for rg list deleted.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func RGListDeletedDataSource(ctx context.Context, state *models.DataSourceRGListDeletedModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.RGListDeletedDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
rgList, err := utilities.RGListDeletedCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about resource group list deleted", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.RGListDeletedDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceRGListDeletedModel{
|
||||
ById: state.ById,
|
||||
Name: state.Name,
|
||||
AccountId: state.AccountId,
|
||||
AccountName: state.AccountName,
|
||||
CreatedAfter: state.CreatedAfter,
|
||||
CreatedBefore: state.CreatedBefore,
|
||||
LockStatus: state.LockStatus,
|
||||
SortBy: state.SortBy,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
}
|
||||
|
||||
items := make([]models.ItemsRGListDeletedModel, 0, len(rgList.Data))
|
||||
for _, rgItem := range rgList.Data {
|
||||
item := models.ItemsRGListDeletedModel{
|
||||
AccountACL: flattenACL(ctx, &rgItem.ACL),
|
||||
AccountID: types.Int64Value(int64(rgItem.AccountID)),
|
||||
AccountName: types.StringValue(rgItem.AccountName),
|
||||
ComputeFeatures: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &rgItem.ComputeFeatures),
|
||||
CPUAllocationParameter: types.StringValue(rgItem.CPUAllocationParameter),
|
||||
CPUAllocationRatio: types.Float64Value(rgItem.CPUAllocationRatio),
|
||||
CreatedBy: types.StringValue(rgItem.CreatedBy),
|
||||
CreatedTime: types.Int64Value(int64(rgItem.CreatedTime)),
|
||||
DefNetID: types.Int64Value(rgItem.DefNetID),
|
||||
DefNetType: types.StringValue(rgItem.DefNetType),
|
||||
DeletedBy: types.StringValue(rgItem.DeletedBy),
|
||||
DeletedTime: types.Int64Value(int64(rgItem.DeletedTime)),
|
||||
Description: types.StringValue(rgItem.Description),
|
||||
Dirty: types.BoolValue(rgItem.Dirty),
|
||||
GID: types.Int64Value(int64(rgItem.GID)),
|
||||
GUID: types.Int64Value(int64(rgItem.GUID)),
|
||||
RGID: types.Int64Value(int64(rgItem.ID)),
|
||||
LockStatus: types.StringValue(rgItem.LockStatus),
|
||||
Milestones: types.Int64Value(int64(rgItem.Milestones)),
|
||||
Name: types.StringValue(rgItem.Name),
|
||||
ResTypes: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &rgItem.ResTypes),
|
||||
RegisterComputes: types.BoolValue(rgItem.RegisterComputes),
|
||||
ResourceLimits: flattenResourceLimits(ctx, &rgItem.ResourceLimits),
|
||||
Secret: types.StringValue(rgItem.Secret),
|
||||
Status: types.StringValue(rgItem.Status),
|
||||
UniqPools: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &rgItem.UniqPools),
|
||||
UpdatedBy: types.StringValue(rgItem.UpdatedBy),
|
||||
UpdatedTime: types.Int64Value(int64(rgItem.UpdatedTime)),
|
||||
VINS: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &rgItem.VINS),
|
||||
VMS: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &rgItem.VMs),
|
||||
}
|
||||
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
state.Items = items
|
||||
state.EntryCount = types.Int64Value(int64(rgList.EntryCount))
|
||||
|
||||
tflog.Info(ctx, "flattens.RGListDeletedDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.RGListDeletedDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"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/rg/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/rg/utilities"
|
||||
)
|
||||
|
||||
// RGListLBDataSource flattens data source for rg list lb.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func RGListLBDataSource(ctx context.Context, state *models.DataSourceRGListLBModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.RGListLBDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
rgListLB, err := utilities.RGListLBCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about resource group list lb", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.RGListLBDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceRGListLBModel{
|
||||
RGID: state.RGID,
|
||||
ByID: state.ByID,
|
||||
Name: state.Name,
|
||||
TechStatus: state.TechStatus,
|
||||
Status: state.Status,
|
||||
FrontIP: state.FrontIP,
|
||||
BackIP: state.BackIP,
|
||||
SortBy: state.SortBy,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
}
|
||||
|
||||
items := make([]models.ItemsRGListLBModel, 0, len(rgListLB.Data))
|
||||
for _, lbItem := range rgListLB.Data {
|
||||
acl, _ := json.Marshal(lbItem.ACL)
|
||||
item := models.ItemsRGListLBModel{
|
||||
HAMode: types.BoolValue(lbItem.HAMode),
|
||||
ACL: types.StringValue(string(acl)),
|
||||
CreatedBy: types.StringValue(lbItem.CreatedBy),
|
||||
CreatedTime: types.Int64Value(int64(lbItem.CreatedTime)),
|
||||
DeletedBy: types.StringValue(lbItem.DeletedBy),
|
||||
DeletedTime: types.Int64Value(int64(lbItem.DeletedTime)),
|
||||
Description: types.StringValue(lbItem.Description),
|
||||
DPAPIUser: types.StringValue(lbItem.DPAPIUser),
|
||||
ExtNetID: types.Int64Value(int64(lbItem.ExtNetID)),
|
||||
GID: types.Int64Value(int64(lbItem.GID)),
|
||||
GUID: types.Int64Value(int64(lbItem.GUID)),
|
||||
ID: types.Int64Value(int64(lbItem.ID)),
|
||||
ImageID: types.Int64Value(int64(lbItem.ImageID)),
|
||||
Milestones: types.Int64Value(int64(lbItem.Milestones)),
|
||||
Name: types.StringValue(lbItem.Name),
|
||||
PrimaryNode: models.RecordNodeModel{
|
||||
BackendIP: types.StringValue(lbItem.PrimaryNode.BackendIP),
|
||||
ComputeID: types.Int64Value(int64(lbItem.PrimaryNode.ComputeID)),
|
||||
FrontendIP: types.StringValue(lbItem.PrimaryNode.FrontendIP),
|
||||
GUID: types.StringValue(lbItem.PrimaryNode.GUID),
|
||||
MGMTIP: types.StringValue(lbItem.PrimaryNode.MGMTIP),
|
||||
NetworkID: types.Int64Value(int64(lbItem.PrimaryNode.NetworkID)),
|
||||
},
|
||||
RGName: types.StringValue(lbItem.RGName),
|
||||
SecondaryNode: models.RecordNodeModel{
|
||||
BackendIP: types.StringValue(lbItem.SecondaryNode.BackendIP),
|
||||
ComputeID: types.Int64Value(int64(lbItem.SecondaryNode.ComputeID)),
|
||||
FrontendIP: types.StringValue(lbItem.SecondaryNode.FrontendIP),
|
||||
GUID: types.StringValue(lbItem.SecondaryNode.GUID),
|
||||
MGMTIP: types.StringValue(lbItem.SecondaryNode.MGMTIP),
|
||||
NetworkID: types.Int64Value(int64(lbItem.SecondaryNode.NetworkID)),
|
||||
},
|
||||
Status: types.StringValue(lbItem.Status),
|
||||
TechStatus: types.StringValue(lbItem.TechStatus),
|
||||
UpdatedBy: types.StringValue(lbItem.UpdatedBy),
|
||||
UpdatedTime: types.Int64Value(int64(lbItem.UpdatedTime)),
|
||||
VINSID: types.Int64Value(int64(lbItem.VINSID)),
|
||||
}
|
||||
|
||||
// flatten Backends
|
||||
backends := make([]models.ItemBackendModel, 0, len(lbItem.Backends))
|
||||
for _, backendItem := range lbItem.Backends {
|
||||
be := models.ItemBackendModel{
|
||||
Algorithm: types.StringValue(backendItem.Algorithm),
|
||||
GUID: types.StringValue(backendItem.GUID),
|
||||
Name: types.StringValue(backendItem.Name),
|
||||
ServerDefaultSettings: models.RecordServerSettingsModel{
|
||||
Inter: types.Int64Value(int64(backendItem.ServerDefaultSettings.Inter)),
|
||||
GUID: types.StringValue(backendItem.ServerDefaultSettings.GUID),
|
||||
DownInter: types.Int64Value(int64(backendItem.ServerDefaultSettings.DownInter)),
|
||||
Rise: types.Int64Value(int64(backendItem.ServerDefaultSettings.Rise)),
|
||||
Fall: types.Int64Value(int64(backendItem.ServerDefaultSettings.Fall)),
|
||||
SlowStart: types.Int64Value(int64(backendItem.ServerDefaultSettings.SlowStart)),
|
||||
MaxConn: types.Int64Value(int64(backendItem.ServerDefaultSettings.MaxConn)),
|
||||
MaxQueue: types.Int64Value(int64(backendItem.ServerDefaultSettings.MaxQueue)),
|
||||
Weight: types.Int64Value(int64(backendItem.ServerDefaultSettings.Weight)),
|
||||
},
|
||||
}
|
||||
|
||||
servers := make([]models.ItemServerModel, 0, len(backendItem.Servers))
|
||||
for _, server := range backendItem.Servers {
|
||||
s := models.ItemServerModel{
|
||||
Address: types.StringValue(server.Address),
|
||||
Check: types.StringValue(server.Check),
|
||||
GUID: types.StringValue(server.GUID),
|
||||
Name: types.StringValue(server.Name),
|
||||
Port: types.Int64Value(int64(server.Port)),
|
||||
ServerSettings: models.RecordServerSettingsModel{
|
||||
Inter: types.Int64Value(int64(server.ServerSettings.Inter)),
|
||||
GUID: types.StringValue(server.ServerSettings.GUID),
|
||||
DownInter: types.Int64Value(int64(server.ServerSettings.DownInter)),
|
||||
Rise: types.Int64Value(int64(server.ServerSettings.Rise)),
|
||||
Fall: types.Int64Value(int64(server.ServerSettings.Fall)),
|
||||
SlowStart: types.Int64Value(int64(server.ServerSettings.SlowStart)),
|
||||
MaxConn: types.Int64Value(int64(server.ServerSettings.MaxConn)),
|
||||
MaxQueue: types.Int64Value(int64(server.ServerSettings.MaxQueue)),
|
||||
Weight: types.Int64Value(int64(server.ServerSettings.Weight)),
|
||||
},
|
||||
}
|
||||
servers = append(servers, s)
|
||||
}
|
||||
be.Servers = servers
|
||||
backends = append(backends, be)
|
||||
}
|
||||
item.Backends = backends
|
||||
|
||||
// flatten Frontends
|
||||
frontends := make([]models.ItemFrontendModel, 0, len(lbItem.Frontends))
|
||||
for _, frontendItem := range lbItem.Frontends {
|
||||
fr := models.ItemFrontendModel{
|
||||
Backend: types.StringValue(frontendItem.Backend),
|
||||
GUID: types.StringValue(frontendItem.GUID),
|
||||
Name: types.StringValue(frontendItem.Name),
|
||||
}
|
||||
bindings := make([]models.ItemBindingModel, 0, len(frontendItem.Bindings))
|
||||
for _, bingingItem := range frontendItem.Bindings {
|
||||
b := models.ItemBindingModel{
|
||||
Address: types.StringValue(bingingItem.Address),
|
||||
GUID: types.StringValue(bingingItem.GUID),
|
||||
Name: types.StringValue(bingingItem.Name),
|
||||
Port: types.Int64Value(int64(bingingItem.Port)),
|
||||
}
|
||||
bindings = append(bindings, b)
|
||||
}
|
||||
fr.Bindings = bindings
|
||||
frontends = append(frontends, fr)
|
||||
}
|
||||
item.Frontends = frontends
|
||||
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
state.Items = items
|
||||
state.EntryCount = types.Int64Value(int64(rgListLB.EntryCount))
|
||||
|
||||
tflog.Info(ctx, "flattens.RGListLBDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.RGListLBDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
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/rg/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/rg/utilities"
|
||||
)
|
||||
|
||||
// RGListPFWDataSource flattens data source for rg list pfw.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func RGListPFWDataSource(ctx context.Context, state *models.DataSourceRGListPFWModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.RGListPFWDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
rgListPFW, err := utilities.RGListPFWCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about resource group list pfw", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.RGListPFWDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceRGListPFWModel{
|
||||
RGID: state.RGID,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
}
|
||||
|
||||
items := make([]models.ItemsRGListPFWModel, 0, len(rgListPFW.Data))
|
||||
for _, pfwItem := range rgListPFW.Data {
|
||||
item := models.ItemsRGListPFWModel{
|
||||
PublicPortEnd: types.Int64Value(int64(pfwItem.PublicPortEnd)),
|
||||
PublicPortStart: types.Int64Value(int64(pfwItem.PublicPortStart)),
|
||||
VMID: types.Int64Value(int64(pfwItem.VMID)),
|
||||
VMIP: types.StringValue(pfwItem.VMIP),
|
||||
VMName: types.StringValue(pfwItem.VMName),
|
||||
VMPort: types.Int64Value(int64(pfwItem.VMPort)),
|
||||
VINSID: types.Int64Value(int64(pfwItem.VINSID)),
|
||||
VINSName: types.StringValue(pfwItem.VINSName),
|
||||
}
|
||||
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
state.Items = items
|
||||
state.EntryCount = types.Int64Value(int64(rgListPFW.EntryCount))
|
||||
|
||||
tflog.Info(ctx, "flattens.RGListPFWDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.RGListPFWDataSource")
|
||||
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/cloudbroker/rg/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/rg/utilities"
|
||||
)
|
||||
|
||||
// RGListVinsDataSource flattens data source for rg list.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func RGListVinsDataSource(ctx context.Context, state *models.DataSourceRGListVinsModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.RGListVinsDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
rgListVins, err := utilities.RGListVinsCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about resource group list vins", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.RGListVinsDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceRGListVinsModel{
|
||||
RGID: state.RGID,
|
||||
Name: state.Name,
|
||||
AccountID: state.AccountID,
|
||||
ExtIP: state.ExtIP,
|
||||
VINSID: state.VINSID,
|
||||
SortBy: state.SortBy,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
}
|
||||
|
||||
items := make([]models.ItemsRGListVinsModel, 0, len(rgListVins.Data))
|
||||
for _, vinsItem := range rgListVins.Data {
|
||||
item := models.ItemsRGListVinsModel{
|
||||
AccountID: types.Int64Value(int64(vinsItem.AccountID)),
|
||||
AccountName: types.StringValue(vinsItem.AccountName),
|
||||
Computes: types.Int64Value(int64(vinsItem.Computes)),
|
||||
CreatedBy: types.StringValue(vinsItem.CreatedBy),
|
||||
CreatedTime: types.Int64Value(int64(vinsItem.CreatedTime)),
|
||||
DeletedBy: types.StringValue(vinsItem.DeletedBy),
|
||||
DeletedTime: types.Int64Value(int64(vinsItem.DeletedTime)),
|
||||
ExternalIP: types.StringValue(vinsItem.ExternalIP),
|
||||
ExtnetID: types.Int64Value(int64(vinsItem.ExtnetId)),
|
||||
FreeIPs: types.Int64Value(int64(vinsItem.FreeIPs)),
|
||||
ID: types.Int64Value(int64(vinsItem.ID)),
|
||||
Name: types.StringValue(vinsItem.Name),
|
||||
Network: types.StringValue(vinsItem.Network),
|
||||
PriVNFDevID: types.Int64Value(int64(vinsItem.PriVNFDevID)),
|
||||
RGID: types.Int64Value(int64(vinsItem.RGID)),
|
||||
RGName: types.StringValue(vinsItem.RGName),
|
||||
Status: types.StringValue(vinsItem.Status),
|
||||
UpdatedBy: types.StringValue(vinsItem.UpdatedBy),
|
||||
UpdatedTime: types.Int64Value(int64(vinsItem.UpdatedTime)),
|
||||
}
|
||||
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
state.Items = items
|
||||
state.EntryCount = types.Int64Value(int64(rgListVins.EntryCount))
|
||||
|
||||
tflog.Info(ctx, "flattens.RGListVinsDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.RGListVinsDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
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/rg/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/rg/utilities"
|
||||
)
|
||||
|
||||
// RGResourceConsumptionListDataSource flattens data source for rg resource consumption list.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func RGResourceConsumptionListDataSource(ctx context.Context, state *models.DataSourceRGResourceConsumptionListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.RGResourceConsumptionListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
resConsList, err := utilities.RGResourceConsumptionListCheckPresence(ctx, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about resource group resource consumption list", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.RGResourceConsumptionListDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceRGResourceConsumptionListModel{
|
||||
Timeouts: state.Timeouts,
|
||||
Id: types.StringValue(id.String()),
|
||||
}
|
||||
|
||||
items := make([]models.ItemResourceConsumptionModel, 0, len(resConsList.Data))
|
||||
for _, resConsItem := range resConsList.Data {
|
||||
item := models.ItemResourceConsumptionModel{
|
||||
RGID: types.Int64Value(int64(resConsItem.RGID)),
|
||||
Consumed: flattenResource(ctx, &resConsItem.Consumed),
|
||||
Reserved: flattenResource(ctx, &resConsItem.Reserved),
|
||||
ResourceLimits: flattenResourceLimits(ctx, &resConsItem.ResourceLimits),
|
||||
}
|
||||
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
state.Items = items
|
||||
state.EntryCount = types.Int64Value(int64(resConsList.EntryCount))
|
||||
|
||||
tflog.Info(ctx, "flattens.RGResourceConsumptionListDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.RGResourceConsumptionListDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
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/rg/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/rg/utilities"
|
||||
)
|
||||
|
||||
// RGUsageDataSource flattens data source for rg usage.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func RGUsageDataSource(ctx context.Context, state *models.DataSourceRGUsageModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.RGUsageDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
usageInfo, err := utilities.RGUsageCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about resource group usage", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.RGUsageDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceRGUsageModel{
|
||||
RGID: state.RGID,
|
||||
Reason: state.Reason,
|
||||
Timeouts: state.Timeouts,
|
||||
Id: types.StringValue(id.String()),
|
||||
|
||||
CPU: types.Int64Value(int64(usageInfo.CPU)),
|
||||
DiskSize: types.Int64Value(int64(usageInfo.DiskSize)),
|
||||
DiskSizeMax: types.Int64Value(int64(usageInfo.DiskSizeMax)),
|
||||
ExtIPs: types.Int64Value(int64(usageInfo.ExtIPs)),
|
||||
ExtTraffic: types.Int64Value(int64(usageInfo.ExtTraffic)),
|
||||
GPU: types.Int64Value(int64(usageInfo.GPU)),
|
||||
RAM: types.Int64Value(int64(usageInfo.RAM)),
|
||||
SEPs: flattenSEPs(ctx, usageInfo.SEPs),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.RGUsageDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.RGUsageDataSource")
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user