|
|
|
|
@@ -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
|
|
|
|
|
}
|
|
|
|
|
|