1.2.2
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user