This commit is contained in:
asteam
2025-04-17 12:31:12 +03:00
parent b8f118097e
commit 5382579a5f
166 changed files with 16413 additions and 221 deletions

View File

@@ -40,14 +40,14 @@ func BServiceResource(ctx context.Context, state *models.RecordBasicServiceResou
tflog.Info(ctx, "flattens.BServiceResource: before flatten", map[string]any{"service_id": serviceId, "recordBService": recordBService})
*state = models.RecordBasicServiceResourceModel{
Name: state.Name,
RGID: state.RGID,
Name: types.StringValue(recordBService.Name),
RGID: types.Int64Value(int64(recordBService.RGID)),
Permanently: state.Permanently,
Enable: state.Enable,
Restore: state.Restore,
Start: state.Start,
Snapshots: state.Snapshots,
Timeouts: state.Timeouts,
Snapshots: flattenSnapshot(ctx, state.Snapshots, recordBService.Snapshots),
SSHKey: types.StringValue(recordBService.SSHKey),
SSHUser: types.StringValue(recordBService.SSHUser),
ServiceId: types.Int64Value(int64(recordBService.ID)),
@@ -142,3 +142,43 @@ func flattenGroups(ctx context.Context, items bservice.ListGroups) types.List {
tflog.Info(ctx, "End flattenGroups")
return res
}
func flattenSnapshot(ctx context.Context, snapshots types.Set, items bservice.ListSnapshots) types.Set {
tflog.Info(ctx, "Start flattenSnapshot")
tempSlice := make([]types.Object, 0, len(items))
for _, v := range items {
temp := models.ItemSnapshotResourceModel{
GUID: types.StringValue(v.GUID),
Label: types.StringValue(v.Label),
Rollback: flattenSnapshotRollback(ctx, snapshots, v),
Timestamp: types.Int64Value(int64(v.Timestamp)),
Valid: types.BoolValue(v.Valid),
}
obj, diags := types.ObjectValueFrom(ctx, models.ItemSnapshotResource, temp)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenSnapshot struct to obj", diags))
}
tempSlice = append(tempSlice, obj)
}
res, diags := types.SetValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemSnapshotResource}, tempSlice)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenSnapshot", diags))
}
tflog.Info(ctx, "End flattenSnapshot")
return res
}
func flattenSnapshotRollback(ctx context.Context, snapshots types.Set, item bservice.ItemSnapshot) types.Bool {
tflog.Info(ctx, "Start flattenSnapshotRollback")
snapshotsList := snapshots.Elements()
for _, snapshot := range snapshotsList {
snapshotMap := snapshot.(types.Object).Attributes()
if snapshotMap["label"].(types.String).ValueString() == item.Label {
return types.BoolValue(snapshotMap["rollback"].(types.Bool).ValueBool())
}
}
tflog.Info(ctx, "End flattenSnapshotRollback")
return types.BoolValue(false)
}

View File

@@ -50,14 +50,14 @@ func BServiceGroupResource(ctx context.Context, plan *models.ResourceRecordGroup
}
*plan = models.ResourceRecordGroupModel{
ServiceID: plan.ServiceID,
ServiceID: types.Int64Value(int64(recordResourceGroup.ServiceID)),
CompCount: plan.CompCount,
Name: plan.Name,
CPU: plan.CPU,
RAM: plan.RAM,
Disk: plan.Disk,
ImageID: plan.ImageID,
Driver: plan.Driver,
Name: types.StringValue(recordResourceGroup.Name),
CPU: types.Int64Value(int64(recordResourceGroup.CPU)),
RAM: types.Int64Value(int64(recordResourceGroup.RAM)),
Disk: types.Int64Value(int64(recordResourceGroup.Disk)),
ImageID: types.Int64Value(int64(recordResourceGroup.ImageID)),
Driver: types.StringValue(recordResourceGroup.Driver),
SEPID: types.Int64Value(int64(recordResourceGroup.SEPID)),
SepPool: types.StringValue(recordResourceGroup.PoolName),
CloudInit: plan.CloudInit,
@@ -71,9 +71,9 @@ func BServiceGroupResource(ctx context.Context, plan *models.ResourceRecordGroup
ForceUpdate: plan.ForceUpdate,
Parents: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, recordResourceGroup.Parents),
RemoveComputes: plan.RemoveComputes,
CompgroupID: plan.CompgroupID,
ID: types.StringValue(strconv.Itoa(int(plan.CompgroupID.ValueInt64()))),
SID: types.StringValue(strconv.Itoa(int(plan.ServiceID.ValueInt64()))),
CompgroupID: types.Int64Value(int64(recordResourceGroup.ID)),
ID: types.StringValue(strconv.Itoa(int(recordResourceGroup.ID))),
SID: types.StringValue(strconv.Itoa(int(recordResourceGroup.ServiceID))),
Timeouts: plan.Timeouts,
AccountID: types.Int64Value(int64(recordResourceGroup.AccountID)),
AccountName: types.StringValue(recordResourceGroup.AccountName),
@@ -95,6 +95,10 @@ func BServiceGroupResource(ctx context.Context, plan *models.ResourceRecordGroup
UpdatedTime: types.Int64Value(int64(recordResourceGroup.UpdatedTime)),
}
if plan.CompCount == types.Int64Null() {
plan.CompCount = types.Int64Value(int64(len(recordResourceGroup.Computes)))
}
tflog.Info(ctx, "End BServiceGroupResource", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": plan.CompgroupID.ValueInt64()})
return nil
}