This commit is contained in:
asteam
2025-07-01 13:44:09 +03:00
parent 5382579a5f
commit ddbb12996d
1041 changed files with 2842 additions and 96448 deletions

View File

@@ -43,7 +43,6 @@ func RGDataSource(ctx context.Context, state *models.DataSourceRGModel, c *clien
Name: types.StringValue(recordRG.Name),
DefNetType: types.StringValue(recordRG.DefNetType),
Description: types.StringValue(recordRG.Description),
RegisterComputes: types.BoolValue(recordRG.RegisterComputes),
AccountName: types.StringValue(recordRG.AccountName),
ACL: flattenACL(ctx, &recordRG.ACL),
CPUAllocationParameter: types.StringValue(recordRG.CPUAllocationParameter),

View File

@@ -69,7 +69,6 @@ func RGListDataSource(ctx context.Context, state *models.DataSourceRGListModel,
LockStatus: types.StringValue(rgItem.LockStatus),
Milestones: types.Int64Value(int64(rgItem.Milestones)),
Name: types.StringValue(rgItem.Name),
RegisterComputes: types.BoolValue(rgItem.RegisterComputes),
ResourceLimits: &models.ResourceLimitsModel{
CUC: types.Float64Value(rgItem.ResourceLimits.CUC),
CUD: types.Float64Value(rgItem.ResourceLimits.CUD),

View File

@@ -68,7 +68,6 @@ func RGListDeletedDataSource(ctx context.Context, state *models.DataSourceRGList
LockStatus: types.StringValue(rgItem.LockStatus),
Milestones: types.Int64Value(int64(rgItem.Milestones)),
Name: types.StringValue(rgItem.Name),
RegisterComputes: types.BoolValue(rgItem.RegisterComputes),
ResourceLimits: &models.ResourceLimitsModel{
CUC: types.Float64Value(rgItem.ResourceLimits.CUC),
CUD: types.Float64Value(rgItem.ResourceLimits.CUD),

View File

@@ -41,21 +41,20 @@ func RGResource(ctx context.Context, plan *models.ResourceRGModel, c *client.Cli
GID: types.Int64Value(int64(recordRG.GID)),
Name: types.StringValue(recordRG.Name),
DefNetType: plan.DefNetType,
IPCIDR: plan.IPCIDR,
Quota: flattenQuota(ctx, &recordRG.ResourceLimits),
ExtNetID: plan.ExtNetID,
ExtIP: plan.ExtIP,
Owner: plan.Owner,
Access: plan.Access,
DefNet: plan.DefNet,
Description: plan.Description,
Force: plan.Force,
Permanently: plan.Permanently,
RegisterComputes: plan.RegisterComputes,
Restore: plan.Restore,
Enable: plan.Enable,
Timeouts: plan.Timeouts,
DefNetType: plan.DefNetType,
IPCIDR: plan.IPCIDR,
Quota: flattenQuota(ctx, &recordRG.ResourceLimits),
ExtNetID: plan.ExtNetID,
ExtIP: plan.ExtIP,
Owner: plan.Owner,
Access: flattenAccess(ctx, &recordRG.ACL),
DefNet: plan.DefNet,
Description: types.StringValue(recordRG.Description),
Force: plan.Force,
Permanently: plan.Permanently,
Restore: plan.Restore,
Enable: types.BoolValue(recordRG.Status == "ENABLED"),
Timeouts: plan.Timeouts,
RGID: types.Int64Value(int64(recordRG.ID)),
LastUpdated: plan.LastUpdated,
@@ -64,6 +63,8 @@ func RGResource(ctx context.Context, plan *models.ResourceRGModel, c *client.Cli
CPUAllocationParameter: types.StringValue(recordRG.CPUAllocationParameter),
CPUAllocationRatio: types.Float64Value(recordRG.CPUAllocationRatio),
DefNetID: types.Int64Value(recordRG.DefNetID),
CreatedBy: types.StringValue(recordRG.CreatedBy),
CreatedTime: types.Int64Value(int64(recordRG.CreatedTime)),
DeletedBy: types.StringValue(recordRG.DeletedBy),
DeletedTime: types.Int64Value(int64(recordRG.DeletedTime)),
Dirty: types.BoolValue(recordRG.Dirty),
@@ -150,3 +151,43 @@ func flattenQuota(ctx context.Context, item *rg.ResourceLimits) types.Object {
}
return quota
}
func flattenAccess(ctx context.Context, aclList *rg.ListACL) types.Set {
tflog.Info(ctx, "Start flattenAccess")
tempSlice := make([]types.Object, 0, len(*aclList)-1)
for i, item := range *aclList {
if i == 0 {
continue
}
temp := models.AccessModel{
Right: types.StringValue(item.Right),
User: types.StringValue(item.UserGroupID),
}
obj, diags := types.ObjectValueFrom(ctx, models.ItemAccess, temp)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenAccess struct to obj", diags))
}
tempSlice = append(tempSlice, obj)
}
res, diags := types.SetValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemAccess}, tempSlice)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenAccess", diags))
}
tflog.Info(ctx, "End flattenAccess")
return res
}
func flattenDefNet(ctx context.Context, dnType string, dnId int64) types.Object {
tflog.Info(ctx, "Start flattenDefNet")
tempStruct := models.DefNetModel{
NetType: types.StringValue(dnType),
NetId: types.Int64Value(int64(dnId)),
}
quota, diags := types.ObjectValueFrom(ctx, models.ItemDefNet, tempStruct)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenDefNet", diags))
}
return quota
}

View File

@@ -31,7 +31,6 @@ type DataSourceRGModel struct {
LockStatus types.String `tfsdk:"lock_status"`
Milestones types.Int64 `tfsdk:"milestones"`
Name types.String `tfsdk:"name"`
RegisterComputes types.Bool `tfsdk:"register_computes"`
ResourceLimits *ResourceLimitsModel `tfsdk:"resource_limits"`
ResTypes types.List `tfsdk:"res_types"`
Secret types.String `tfsdk:"secret"`

View File

@@ -48,7 +48,6 @@ type ItemsRGListModel struct {
LockStatus types.String `tfsdk:"lock_status"`
Milestones types.Int64 `tfsdk:"milestones"`
Name types.String `tfsdk:"name"`
RegisterComputes types.Bool `tfsdk:"register_computes"`
ResourceLimits *ResourceLimitsModel `tfsdk:"resource_limits"`
ResTypes types.List `tfsdk:"resource_types"`
Secret types.String `tfsdk:"secret"`

View File

@@ -46,7 +46,6 @@ type ItemsRGListDeletedModel struct {
LockStatus types.String `tfsdk:"lock_status"`
Milestones types.Int64 `tfsdk:"milestones"`
Name types.String `tfsdk:"name"`
RegisterComputes types.Bool `tfsdk:"register_computes"`
ResourceLimits *ResourceLimitsModel `tfsdk:"resource_limits"`
ResTypes types.List `tfsdk:"resource_types"`
Secret types.String `tfsdk:"secret"`

View File

@@ -13,21 +13,20 @@ type ResourceRGModel struct {
Name types.String `tfsdk:"name"`
// request fields - optional
DefNetType types.String `tfsdk:"def_net_type"`
IPCIDR types.String `tfsdk:"ipcidr"`
ExtNetID types.Int64 `tfsdk:"ext_net_id"`
ExtIP types.String `tfsdk:"ext_ip"`
Owner types.String `tfsdk:"owner"`
Quota types.Object `tfsdk:"quota"`
Access types.List `tfsdk:"access"`
DefNet types.Object `tfsdk:"def_net"`
Description types.String `tfsdk:"description"`
Force types.Bool `tfsdk:"force"`
Permanently types.Bool `tfsdk:"permanently"`
RegisterComputes types.Bool `tfsdk:"register_computes"`
Restore types.Bool `tfsdk:"restore"`
Enable types.Bool `tfsdk:"enable"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
DefNetType types.String `tfsdk:"def_net_type"`
IPCIDR types.String `tfsdk:"ipcidr"`
ExtNetID types.Int64 `tfsdk:"ext_net_id"`
ExtIP types.String `tfsdk:"ext_ip"`
Owner types.String `tfsdk:"owner"`
Quota types.Object `tfsdk:"quota"`
Access types.Set `tfsdk:"access"`
DefNet types.Object `tfsdk:"def_net"`
Description types.String `tfsdk:"description"`
Force types.Bool `tfsdk:"force"`
Permanently types.Bool `tfsdk:"permanently"`
Restore types.Bool `tfsdk:"restore"`
Enable types.Bool `tfsdk:"enable"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// response fields
RGID types.Int64 `tfsdk:"rg_id"`
@@ -38,6 +37,8 @@ type ResourceRGModel struct {
CPUAllocationParameter types.String `tfsdk:"cpu_allocation_parameter"`
CPUAllocationRatio types.Float64 `tfsdk:"cpu_allocation_ratio"`
DefNetID types.Int64 `tfsdk:"def_net_id"`
CreatedBy types.String `tfsdk:"created_by"`
CreatedTime types.Int64 `tfsdk:"created_time"`
DeletedBy types.String `tfsdk:"deleted_by"`
DeletedTime types.Int64 `tfsdk:"deleted_time"`
Dirty types.Bool `tfsdk:"dirty"`

View File

@@ -97,9 +97,6 @@ func MakeSchemaDataSourceRG() map[string]schema.Attribute {
"name": schema.StringAttribute{
Computed: true,
},
"register_computes": schema.BoolAttribute{
Computed: true,
},
"resource_limits": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{

View File

@@ -142,9 +142,6 @@ func MakeSchemaDataSourceRGList() map[string]schema.Attribute {
"name": schema.StringAttribute{
Computed: true,
},
"register_computes": schema.BoolAttribute{
Computed: true,
},
"resource_limits": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{

View File

@@ -134,9 +134,6 @@ func MakeSchemaDataSourceRGListDeleted() map[string]schema.Attribute {
"name": schema.StringAttribute{
Computed: true,
},
"register_computes": schema.BoolAttribute{
Computed: true,
},
"resource_limits": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{

View File

@@ -3,6 +3,7 @@ package schemas
import (
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
@@ -96,7 +97,7 @@ func MakeSchemaResourceRG() map[string]schema.Attribute {
},
},
},
"access": schema.ListNestedAttribute{
"access": schema.SetNestedAttribute{
Optional: true,
Description: "Grant/revoke user or group access to the Resource group as specified",
NestedObject: schema.NestedAttributeObject{
@@ -136,25 +137,28 @@ func MakeSchemaResourceRG() map[string]schema.Attribute {
},
"force": schema.BoolAttribute{
Optional: true,
Computed: true,
Default: booldefault.StaticBool(true),
Description: "Set to True if you want force delete non-empty RG",
// default value is true
},
"permanently": schema.BoolAttribute{
Optional: true,
Computed: true,
Default: booldefault.StaticBool(true),
Description: "Set to True if you want force delete non-empty RG",
// default value is true
},
"register_computes": schema.BoolAttribute{
Optional: true,
Description: "Register computes in registration system",
// default value is false
},
"restore": schema.BoolAttribute{
Optional: true,
Computed: true,
Default: booldefault.StaticBool(true),
// default value is true
},
"enable": schema.BoolAttribute{
Optional: true,
Computed: true,
Default: booldefault.StaticBool(true),
Description: "flag for enable/disable RG",
// default value is true
},
@@ -214,6 +218,12 @@ func MakeSchemaResourceRG() map[string]schema.Attribute {
"def_net_id": schema.Int64Attribute{
Computed: true,
},
"created_by": schema.StringAttribute{
Computed: true,
},
"created_time": schema.Int64Attribute{
Computed: true,
},
"deleted_by": schema.StringAttribute{
Computed: true,
},

View File

@@ -92,11 +92,6 @@ func CreateRequestResourceRG(ctx context.Context, plan *models.ResourceRGModel)
if !plan.ExtIP.IsNull() {
createReq.ExtIP = plan.ExtIP.ValueString()
}
if plan.RegisterComputes.IsNull() {
createReq.RegisterComputes = false // default value
} else {
createReq.RegisterComputes = plan.RegisterComputes.ValueBool()
}
return createReq, nil
}
@@ -160,7 +155,7 @@ func DisableRG(ctx context.Context, rgId uint64, plan *models.ResourceRGModel, c
return err
}
// UpdateRG compares plan and state for resource group fields name, description, quota, register_computes.
// UpdateRG compares plan and state for resource group fields name, description, quota.
// If any changes are detected, Update request is performed. If not, no update is performed.
func UpdateRG(ctx context.Context, rgId uint64, plan, state *models.ResourceRGModel, c *client.Client) diag.Diagnostics {
var updateNeeded bool
@@ -188,19 +183,6 @@ func UpdateRG(ctx context.Context, rgId uint64, plan, state *models.ResourceRGMo
updateNeeded = true
}
if !plan.RegisterComputes.Equal(state.RegisterComputes) {
if plan.RegisterComputes.IsNull() {
updateReq.RegisterComputes = false // default value
} else {
updateReq.RegisterComputes = plan.RegisterComputes.ValueBool()
}
tflog.Info(ctx, "utilityUpdateRG: new register_computes specified", map[string]any{
"rg_id": plan.Id.ValueString(),
"register_computes_plan": plan.RegisterComputes.ValueBool(),
"register_computes_state": state.RegisterComputes.ValueBool()})
updateNeeded = true
}
if !plan.UniqPools.Equal(state.UniqPools) {
if plan.UniqPools.IsNull() || len(plan.UniqPools.Elements()) == 0 {
updateReq.ClearUniqPools = true
@@ -214,10 +196,6 @@ func UpdateRG(ctx context.Context, rgId uint64, plan, state *models.ResourceRGMo
}
updateReq.UniqPools = uPoolsList
}
tflog.Info(ctx, "utilityUpdateRG: new register_computes specified", map[string]any{
"rg_id": plan.Id.ValueString(),
"register_computes_plan": plan.RegisterComputes.ValueBool(),
"register_computes_state": state.RegisterComputes.ValueBool()})
updateNeeded = true
}