1.0.0
This commit is contained in:
@@ -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