This commit is contained in:
asteam
2025-07-01 13:44:09 +03:00
parent 5382579a5f
commit ddbb12996d
1041 changed files with 2842 additions and 96448 deletions

View File

@@ -51,6 +51,7 @@ func AccountDataSource(ctx context.Context, state *models.DataSourceAccountModel
DeactivationTime: types.Float64Value(recordAccount.DeactivationTime),
DeletedBy: types.StringValue(recordAccount.DeletedBy),
DeletedTime: types.Int64Value(int64(recordAccount.DeletedTime)),
Desc: types.StringValue(recordAccount.Description),
DisplayName: types.StringValue(recordAccount.DisplayName),
GUID: types.Int64Value(int64(recordAccount.GUID)),
Machines: flattenMachines(ctx, recordAccount.Machines),

View File

@@ -52,6 +52,7 @@ func AccountListDataSource(ctx context.Context, state *models.DataSourceAccountL
AccountName: types.StringValue(item.Name),
Status: types.StringValue(item.Status),
UpdatedTime: types.Int64Value(int64(item.UpdatedTime)),
Desc: types.StringValue(item.Description),
}
i.ComputeFeatures, diags = types.ListValueFrom(ctx, types.StringType, item.ComputeFeatures)
if diags.HasError() {

View File

@@ -48,6 +48,7 @@ func AccountListDeletedDataSource(ctx context.Context, state *models.DataSourceA
i := models.ItemAccountListDeletedModel{
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
Desc: types.StringValue(item.Description),
AccountID: types.Int64Value(int64(item.ID)),
AccountName: types.StringValue(item.Name),
Status: types.StringValue(item.Status),

View File

@@ -90,6 +90,7 @@ func AccountRGListDataSource(ctx context.Context, state *models.DataSourceAccoun
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
DeletedBy: types.StringValue(item.DeletedBy),
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
Desc: types.StringValue(item.Description),
RGID: types.Int64Value(int64(item.RGID)),
Milestones: types.Int64Value(int64(item.Milestones)),
RGName: types.StringValue(item.RGName),

View File

@@ -7,6 +7,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/flattens"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
@@ -47,13 +48,13 @@ func AccountResource(ctx context.Context, state *models.ResourceAccountModel, c
*state = models.ResourceAccountModel{
// request fields
AccountName: types.StringValue(recordAccount.Name),
Username: state.Username,
EmailAddress: state.EmailAddress,
SendAccessEmails: state.SendAccessEmails,
Users: state.Users,
SendAccessEmails: types.BoolValue(recordAccount.SendAccessEmails),
Users: flattenUsers(ctx, recordAccount.ACL),
Restore: state.Restore,
Permanently: state.Permanently,
Desc: types.StringValue(recordAccount.Description),
Enable: state.Enable,
Reason: state.Reason,
ResourceLimits: flattenResourceLimitsInAccountResource(ctx, recordAccount.ResourceLimits, state),
Timeouts: state.Timeouts,
@@ -67,6 +68,7 @@ func AccountResource(ctx context.Context, state *models.ResourceAccountModel, c
Company: types.StringValue(recordAccount.Company),
CompanyURL: types.StringValue(recordAccount.CompanyURL),
Computes: flattenComputes(ctx, recordAccount.Computes),
ComputeFeatures: flattens.FlattenSimpleTypeToList(ctx, types.StringType, recordAccount.ComputeFeatures),
CPUAllocationParameter: types.StringValue(recordAccount.CPUAllocationParameter),
CPUAllocationRatio: types.Float64Value(recordAccount.CPUAllocationRatio),
CreatedBy: types.StringValue(recordAccount.CreatedBy),
@@ -74,23 +76,22 @@ func AccountResource(ctx context.Context, state *models.ResourceAccountModel, c
DeactivationTime: types.Float64Value(recordAccount.DeactivationTime),
DeletedBy: types.StringValue(recordAccount.DeletedBy),
DeletedTime: types.Int64Value(int64(recordAccount.DeletedTime)),
DisplayName: types.StringValue(recordAccount.DisplayName),
GUID: types.Int64Value(int64(recordAccount.GUID)),
Machines: flattenMachines(ctx, recordAccount.Machines),
Status: types.StringValue(recordAccount.Status),
UpdatedTime: types.Int64Value(int64(recordAccount.UpdatedTime)),
Version: types.Int64Value(int64(recordAccount.Version)),
VINSes: types.Int64Value(int64(recordAccount.VINSes)),
//Description: types.StringValue(recordAccount.Description),
DisplayName: types.StringValue(recordAccount.DisplayName),
GUID: types.Int64Value(int64(recordAccount.GUID)),
Machines: flattenMachines(ctx, recordAccount.Machines),
Status: types.StringValue(recordAccount.Status),
UpdatedTime: types.Int64Value(int64(recordAccount.UpdatedTime)),
Version: types.Int64Value(int64(recordAccount.Version)),
VINS: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, recordAccount.VINS),
VINSes: types.Int64Value(int64(recordAccount.VINSes)),
}
state.VINS, diags = types.ListValueFrom(ctx, types.Int64Type, recordAccount.VINS)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("flattens.AccountResource: cannot flatten recordAccount.VINS to state.VINS", diags))
}
state.ComputeFeatures, diags = types.ListValueFrom(ctx, types.StringType, recordAccount.ComputeFeatures)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("flattens.AccountResource: cannot flatten recordAccount.ComputeFeatures to state.ComputeFeatures", diags))
if state.Enable == types.BoolNull() {
state.Enable = types.BoolValue(false)
if recordAccount.Status == "CONFIRMED" {
state.Enable = types.BoolValue(true)
}
}
tflog.Info(ctx, "flattens.AccountResource: after flatten", map[string]any{"account_id": state.Id.ValueString()})
@@ -137,3 +138,30 @@ func flattenResourceLimitsInAccountResource(ctx context.Context, limits account.
tflog.Info(ctx, "End flattenResourceLimitsInAccountResource")
return res
}
func flattenUsers(ctx context.Context, aclList []account.RecordACL) types.Set {
tflog.Info(ctx, "Start flattenUsers")
tempSlice := make([]types.Object, 0, len(aclList))
for i, item := range aclList {
if i == 0 {
continue
}
temp := models.UsersModel{
UserID: types.StringValue(item.UgroupID),
AccessType: types.StringValue(item.Rights),
}
obj, diags := types.ObjectValueFrom(ctx, models.ItemUsersResource, temp)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenUsers struct to obj", diags))
}
tempSlice = append(tempSlice, obj)
}
res, diags := types.SetValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemUsersResource}, tempSlice)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenUsers", diags))
}
tflog.Info(ctx, "End flattenUsers")
return res
}