1.0.0
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"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/cloudapi/flipgroup/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/flipgroup/utilities"
|
||||
)
|
||||
|
||||
// FlipgroupDataSource flattens data source for flipgroup.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func FlipgroupDataSource(ctx context.Context, state *models.DataSourceFLIPGroupModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.FlipgroupDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
fgID := uint64(state.FlipgroupID.ValueInt64())
|
||||
|
||||
recordFG, diags := utilities.FlipgroupDataSourceCheckPresence(ctx, fgID, c)
|
||||
if diags.HasError() {
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.FlipgroupDataSource: before flatten", map[string]any{"flipgroup_id": fgID})
|
||||
|
||||
*state = models.DataSourceFLIPGroupModel{
|
||||
FlipgroupID: state.FlipgroupID,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
AccountID: types.Int64Value(int64(recordFG.AccountID)),
|
||||
AccountName: types.StringValue(recordFG.AccountName),
|
||||
ClientType: types.StringValue(recordFG.ClientType),
|
||||
ConnID: types.Int64Value(int64(recordFG.ConnID)),
|
||||
ConnType: types.StringValue(recordFG.ConnType),
|
||||
CreatedBy: types.StringValue(recordFG.CreatedBy),
|
||||
CreatedTime: types.Int64Value(int64(recordFG.CreatedTime)),
|
||||
DefaultGW: types.StringValue(recordFG.DefaultGW),
|
||||
DeletedBy: types.StringValue(recordFG.DeletedBy),
|
||||
DeletedTime: types.Int64Value(int64(recordFG.DeletedTime)),
|
||||
Description: types.StringValue(recordFG.Description),
|
||||
ID: types.Int64Value(int64(recordFG.ID)),
|
||||
GID: types.Int64Value(int64(recordFG.GID)),
|
||||
GUID: types.Int64Value(int64(recordFG.GUID)),
|
||||
IP: types.StringValue(recordFG.IP),
|
||||
Milestones: types.Int64Value(int64(recordFG.Milestones)),
|
||||
Name: types.StringValue(recordFG.Name),
|
||||
NetID: types.Int64Value(int64(recordFG.NetID)),
|
||||
NetType: types.StringValue(recordFG.NetType),
|
||||
Network: types.StringValue(recordFG.Network),
|
||||
RGID: types.Int64Value(int64(recordFG.RGID)),
|
||||
RGName: types.StringValue(recordFG.RGName),
|
||||
Status: types.StringValue(recordFG.Status),
|
||||
UpdatedBy: types.StringValue(recordFG.UpdatedBy),
|
||||
UpdatedTime: types.Int64Value(int64(recordFG.UpdatedTime)),
|
||||
}
|
||||
|
||||
state.ClientIDs, diags = types.ListValueFrom(ctx, types.Int64Type, recordFG.ClientIDs)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.FlipgroupDataSource: cannot flatten recordFG.ClientIDs to state.ClientIDs", diags))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattens.FlipgroupDataSource", map[string]any{"flipgroup_id": state.ID.ValueInt64()})
|
||||
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/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/flipgroup/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/flipgroup/utilities"
|
||||
)
|
||||
|
||||
// FlipgroupListDataSource flattens data source for flipgroup.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func FlipgroupListDataSource(ctx context.Context, state *models.DataSourceFLIPGroupModelList, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.FlipgroupListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
recordFG, diags := utilities.FlipgroupListDataSourceCheckPresence(ctx, state, c)
|
||||
if diags.HasError() {
|
||||
return diags
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceFLIPGroupModelList{
|
||||
FlipgroupID: state.FlipgroupID,
|
||||
Name: state.Name,
|
||||
VinsID: state.VinsID,
|
||||
VinsName: state.VinsName,
|
||||
ExtnetID: state.ExtnetID,
|
||||
ByIP: state.ByIP,
|
||||
AccountID: state.AccountID,
|
||||
RgID: state.RgID,
|
||||
SortBy: state.SortBy,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
ConnID: state.ConnID,
|
||||
CliendIDs: state.CliendIDs,
|
||||
Status: state.Status,
|
||||
|
||||
ID: types.StringValue(id.String()),
|
||||
EntryCount: types.Int64Value(int64(recordFG.EntryCount)),
|
||||
}
|
||||
|
||||
items := make([]models.ItemFLIPGroupModel, 0, len(recordFG.Data))
|
||||
for _, item := range recordFG.Data {
|
||||
fg := models.ItemFLIPGroupModel{
|
||||
CKey: types.StringValue(item.CKey),
|
||||
Meta: flattens.FlattenSimpleTypeToList(ctx, types.StringType, item.Meta),
|
||||
AccountID: types.Int64Value(int64(item.AccountID)),
|
||||
ClientIDs: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, item.Meta),
|
||||
ClientType: types.StringValue(item.ClientType),
|
||||
ConnID: types.Int64Value(int64(item.ConnID)),
|
||||
ConnType: types.StringValue(item.ConnType),
|
||||
DefaultGW: types.StringValue(item.DefaultGW),
|
||||
Description: types.StringValue(item.Description),
|
||||
GID: types.Int64Value(int64(item.GID)),
|
||||
GUID: types.Int64Value(int64(item.GUID)),
|
||||
ID: types.Int64Value(int64(item.ID)),
|
||||
IP: types.StringValue(item.IP),
|
||||
Milestones: types.Int64Value(int64(item.Milestones)),
|
||||
Name: types.StringValue(item.Name),
|
||||
NetID: types.Int64Value(int64(item.NetID)),
|
||||
NetType: types.StringValue(item.NetType),
|
||||
NetMask: types.Int64Value(int64(item.NetMask)),
|
||||
Status: types.StringValue(item.Status),
|
||||
}
|
||||
items = append(items, fg)
|
||||
}
|
||||
state.Items = items
|
||||
|
||||
tflog.Info(ctx, "End flattens.FlipgroupListDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"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/cloudapi/flipgroup/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/flipgroup/utilities"
|
||||
)
|
||||
|
||||
// FlipgroupResource flattens resource for flipgroup.
|
||||
// Return error in case resource is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func FlipgroupResource(ctx context.Context, plan *models.ResourceFLIPGroupModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.FlipgroupResource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
flipgroupID, err := strconv.ParseUint(plan.ID.ValueString(), 10, 64)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot parse flipgroup ID from state", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
recordFG, diags := utilities.FlipgroupResourceCheckPresence(ctx, flipgroupID, c)
|
||||
if diags.HasError() {
|
||||
return diags
|
||||
}
|
||||
|
||||
*plan = models.ResourceFLIPGroupModel{
|
||||
AccountID: plan.AccountID,
|
||||
Name: plan.Name,
|
||||
NetType: plan.NetType,
|
||||
NetID: plan.NetID,
|
||||
ClientType: plan.ClientType,
|
||||
Timeouts: plan.Timeouts,
|
||||
Description: plan.Description,
|
||||
ClientIDs: plan.ClientIDs,
|
||||
ID: plan.ID,
|
||||
IP: plan.IP,
|
||||
|
||||
AccountName: types.StringValue(recordFG.AccountName),
|
||||
ConnID: types.Int64Value(int64(recordFG.ConnID)),
|
||||
ConnType: types.StringValue(recordFG.ConnType),
|
||||
CreatedBy: types.StringValue(recordFG.CreatedBy),
|
||||
CreatedTime: types.Int64Value(int64(recordFG.CreatedTime)),
|
||||
DefaultGW: types.StringValue(recordFG.DefaultGW),
|
||||
DeletedBy: types.StringValue(recordFG.DeletedBy),
|
||||
DeletedTime: types.Int64Value(int64(recordFG.DeletedTime)),
|
||||
FlipgroupID: types.Int64Value(int64(recordFG.ID)),
|
||||
//ID: types.StringValue(strconv.Itoa(int(recordFG.ID))),
|
||||
GID: types.Int64Value(int64(recordFG.GID)),
|
||||
GUID: types.Int64Value(int64(recordFG.GUID)),
|
||||
Milestones: types.Int64Value(int64(recordFG.Milestones)),
|
||||
Network: types.StringValue(recordFG.Network),
|
||||
RGID: types.Int64Value(int64(recordFG.RGID)),
|
||||
RGName: types.StringValue(recordFG.RGName),
|
||||
Status: types.StringValue(recordFG.Status),
|
||||
UpdatedBy: types.StringValue(recordFG.UpdatedBy),
|
||||
UpdatedTime: types.Int64Value(int64(recordFG.UpdatedTime)),
|
||||
}
|
||||
|
||||
if plan.IP.IsUnknown() {
|
||||
plan.IP = types.StringValue(recordFG.IP)
|
||||
}
|
||||
|
||||
if plan.ClientIDs.IsUnknown() {
|
||||
plan.ClientIDs = flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, recordFG.ClientIDs)
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattens.FlipgroupResource", map[string]any{"flipgroup_id": plan.ID.ValueString()})
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user