This commit is contained in:
asteam
2024-12-04 13:18:58 +03:00
parent 003e4d656e
commit 76ea459b3d
417 changed files with 30051 additions and 975 deletions

View File

@@ -33,8 +33,8 @@ func RGDataSource(ctx context.Context, state *models.DataSourceRGModel, c *decor
id := uuid.New()
*state = models.DataSourceRGModel{
RGID: state.RGID,
Reason: state.Reason,
RGID: state.RGID,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),

View File

@@ -31,7 +31,6 @@ func RGUsageDataSource(ctx context.Context, state *models.DataSourceRGUsageModel
id := uuid.New()
*state = models.DataSourceRGUsageModel{
RGID: state.RGID,
Reason: state.Reason,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),

View File

@@ -52,7 +52,6 @@ func RGResource(ctx context.Context, plan *models.ResourceRGModel, c *decort.Dec
Description: plan.Description,
Force: plan.Force,
Permanently: plan.Permanently,
Reason: plan.Reason,
RegisterComputes: plan.RegisterComputes,
Restore: plan.Restore,
Enable: plan.Enable,

View File

@@ -8,7 +8,6 @@ import (
type DataSourceRGModel struct {
// request fields
RGID types.Int64 `tfsdk:"rg_id"`
Reason types.String `tfsdk:"reason"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// response fields

View File

@@ -8,7 +8,6 @@ import (
type DataSourceRGUsageModel struct {
// request fields
RGID types.Int64 `tfsdk:"rg_id"`
Reason types.String `tfsdk:"reason"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// response fields

View File

@@ -24,7 +24,6 @@ type ResourceRGModel struct {
Description types.String `tfsdk:"description"`
Force types.Bool `tfsdk:"force"`
Permanently types.Bool `tfsdk:"permanently"`
Reason types.String `tfsdk:"reason"`
RegisterComputes types.Bool `tfsdk:"register_computes"`
Restore types.Bool `tfsdk:"restore"`
Enable types.Bool `tfsdk:"enable"`
@@ -76,27 +75,23 @@ type QuotaModel struct {
}
type AccessModel struct {
User types.String `tfsdk:"user"`
Right types.String `tfsdk:"right"`
Reason types.String `tfsdk:"reason"`
User types.String `tfsdk:"user"`
Right types.String `tfsdk:"right"`
}
type DefNetModel struct {
NetType types.String `tfsdk:"net_type"`
NetId types.Int64 `tfsdk:"net_id"`
Reason types.String `tfsdk:"reason"`
}
var ItemAccess = map[string]attr.Type{
"user": types.StringType,
"right": types.StringType,
"reason": types.StringType,
"user": types.StringType,
"right": types.StringType,
}
var ItemDefNet = map[string]attr.Type{
"net_type": types.StringType,
"net_id": types.Int64Type,
"reason": types.StringType,
}
var ItemACL = map[string]attr.Type{

View File

@@ -237,13 +237,6 @@ func (r *resourceRG) Update(ctx context.Context, req resource.UpdateRequest, res
// Validate if changes in plan are allowed
tflog.Info(ctx, "Update resourceRG: checking def_net is not empty in case of change", map[string]any{
"rg_id": state.Id.ValueString()})
if !state.DefNet.IsNull() && plan.DefNet.IsNull() {
resp.Diagnostics.AddError(
"Update resourceRG: Invalid input provided",
fmt.Sprintf("block def_net must not be empty for resource with rg_id %d", recordRG.ID),
)
return
}
tflog.Info(ctx, "Update resourceRG: checking def_net_type, ipcidr, ext_ip are not changed", map[string]any{
"rg_id": state.Id.ValueString(),
@@ -370,9 +363,6 @@ func (r *resourceRG) Delete(ctx context.Context, req resource.DeleteRequest, res
} else {
delReq.Permanently = state.Permanently.ValueBool()
}
if !state.Reason.IsNull() {
delReq.Reason = state.Reason.ValueString()
}
_, err := r.client.CloudAPI().RG().Delete(ctx, delReq)
if err != nil {
resp.Diagnostics.AddError("Delete resourceRG: Error deleting resource group with error: ", err.Error())

View File

@@ -13,12 +13,6 @@ func MakeSchemaDataSourceRG() map[string]schema.Attribute {
Description: "resource group id",
},
// optional attributes
"reason": schema.StringAttribute{
Optional: true,
Description: "reason for request",
},
//computed attributes
"account_id": schema.Int64Attribute{
Computed: true,

View File

@@ -12,12 +12,6 @@ func MakeSchemaDataSourceRGUsage() map[string]schema.Attribute {
Description: "find by rg id",
},
// optional attributes
"reason": schema.StringAttribute{
Optional: true,
Description: "reason for action",
},
//computed attributes
"id": schema.StringAttribute{
Computed: true,

View File

@@ -109,10 +109,6 @@ func MakeSchemaResourceRG() map[string]schema.Attribute {
Required: true,
Description: "Access rights to set, one of 'R', 'RCX' or 'ARCXDU'",
},
"reason": schema.StringAttribute{
Optional: true,
Description: "Reason for action",
},
},
},
},
@@ -132,10 +128,6 @@ func MakeSchemaResourceRG() map[string]schema.Attribute {
Description: "Network segment ID. If netType is PUBLIC and netId is 0 then default external network segment will be selected. If netType is PRIVATE and netId=0, the first ViNS defined for this RG will be selected. Otherwise, netId identifies either existing external network segment or ViNS.",
// default value is 0
},
"reason": schema.StringAttribute{
Optional: true,
Description: "Reason for action",
},
},
},
"description": schema.StringAttribute{
@@ -152,10 +144,6 @@ func MakeSchemaResourceRG() map[string]schema.Attribute {
Description: "Set to True if you want force delete non-empty RG",
// default value is true
},
"reason": schema.StringAttribute{
Optional: true,
Description: "Set to True if you want force delete non-empty RG",
},
"register_computes": schema.BoolAttribute{
Optional: true,
Description: "Register computes in registration system",
@@ -171,6 +159,13 @@ func MakeSchemaResourceRG() map[string]schema.Attribute {
// default value is true
},
"uniq_pools": schema.ListAttribute{
Optional: true,
Computed: true,
ElementType: types.StringType,
Description: "List of strings with pools. Applies only when updating",
},
// computed attributes
"rg_id": schema.Int64Attribute{
Computed: true,
@@ -267,9 +262,5 @@ func MakeSchemaResourceRG() map[string]schema.Attribute {
Computed: true,
ElementType: types.StringType,
},
"uniq_pools": schema.ListAttribute{
Computed: true,
ElementType: types.StringType,
},
}
}

View File

@@ -13,10 +13,6 @@ import (
func RGUsageCheckPresence(ctx context.Context, plan *models.DataSourceRGUsageModel, c *decort.DecortClient) (*rg.RecordResourceUsage, error) {
usageReq := rg.UsageRequest{RGID: uint64(plan.RGID.ValueInt64())}
if !plan.Reason.IsNull() {
usageReq.Reason = plan.Reason.ValueString()
}
tflog.Info(ctx, "RGUsageCheckPresence: before call CloudAPI().RG().Usage", map[string]any{"response": usageReq})
usage, err := c.CloudAPI().RG().Usage(ctx, usageReq)
if err != nil {

View File

@@ -71,10 +71,8 @@ func CreateRequestResourceRG(ctx context.Context, plan *models.ResourceRGModel)
createReq.MaxNumPublicIP = -1
}
// set up defNet, owner, ipcidr, description, reason, extNetId, extIp, registerComputes optional parameters
if plan.DefNetType.IsNull() {
createReq.DefNet = "PRIVATE" // default value
} else {
// set up defNet, owner, ipcidr, description, extNetId, extIp, registerComputes optional parameters
if !plan.DefNetType.IsNull() {
createReq.DefNet = plan.DefNetType.ValueString()
}
if !plan.Owner.IsNull() {
@@ -86,9 +84,6 @@ func CreateRequestResourceRG(ctx context.Context, plan *models.ResourceRGModel)
if !plan.Description.IsNull() {
createReq.Description = plan.Description.ValueString()
}
if !plan.Reason.IsNull() {
createReq.Reason = plan.Reason.ValueString()
}
if plan.ExtNetID.IsNull() {
createReq.ExtNetID = 0 // default value 0
} else {
@@ -143,9 +138,6 @@ func RestoreRG(ctx context.Context, rgId uint64, c *decort.DecortClient) diag.Di
// EnableRG performs resource group Enable request
func EnableRG(ctx context.Context, rgId uint64, plan *models.ResourceRGModel, c *decort.DecortClient) error {
enableReq := rg.EnableRequest{RGID: rgId}
if !plan.Reason.IsNull() {
enableReq.Reason = plan.Reason.ValueString()
}
tflog.Info(ctx, "utilityEnableRG: before calling CloudAPI().RG().Enable", map[string]any{"rg_id": rgId, "req": enableReq})
@@ -159,10 +151,6 @@ func EnableRG(ctx context.Context, rgId uint64, plan *models.ResourceRGModel, c
// DisableRG performs resource group Disable request
func DisableRG(ctx context.Context, rgId uint64, plan *models.ResourceRGModel, c *decort.DecortClient) error {
disableReq := rg.DisableRequest{RGID: rgId}
if !plan.Reason.IsNull() {
disableReq.Reason = plan.Reason.ValueString()
}
tflog.Info(ctx, "utilityDisableRG: before calling CloudAPI().RG().Disable", map[string]any{"rg_id": rgId, "req": disableReq})
res, err := c.CloudAPI().RG().Disable(ctx, disableReq)
@@ -181,9 +169,6 @@ func UpdateRG(ctx context.Context, rgId uint64, plan, state *models.ResourceRGMo
updateReq := rg.UpdateRequest{
RGID: rgId,
}
if !state.Reason.IsNull() {
updateReq.Reason = state.Reason.ValueString()
}
if !plan.Name.Equal(state.Name) {
updateReq.Name = plan.Name.ValueString()
@@ -216,17 +201,37 @@ func UpdateRG(ctx context.Context, rgId uint64, plan, state *models.ResourceRGMo
updateNeeded = true
}
if !plan.UniqPools.Equal(state.UniqPools) {
if plan.UniqPools.IsNull() || len(plan.UniqPools.Elements()) == 0 {
updateReq.ClearUniqPools = true
} else {
uPoolsList := make([]string, 0, len(plan.UniqPools.Elements()))
diags.Append(plan.UniqPools.ElementsAs(ctx, &uPoolsList, true)...)
if diags.HasError() {
tflog.Error(ctx, "utilityUpdateRG: cannot populate result with plan.UniqPools object element")
return diags
}
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
}
var updQuotaNeeded bool
var quotaPlan, quotaState models.QuotaModel
if !plan.Quota.IsNull() {
diags = plan.Quota.As(ctx, &quotaPlan, basetypes.ObjectAsOptions{})
diags = plan.Quota.As(ctx, &quotaPlan, basetypes.ObjectAsOptions{UnhandledNullAsEmpty: true, UnhandledUnknownAsEmpty: true})
if diags.HasError() {
return diags
}
}
if !state.Quota.IsNull() {
diags = state.Quota.As(ctx, &quotaState, basetypes.ObjectAsOptions{})
diags = state.Quota.As(ctx, &quotaState, basetypes.ObjectAsOptions{UnhandledNullAsEmpty: true, UnhandledUnknownAsEmpty: true})
if diags.HasError() {
return diags
}
@@ -424,9 +429,6 @@ func AccessUpdateRG(ctx context.Context, rgId uint64, plan, state *models.Resour
RGID: rgId,
User: deletedAccessItem.User.ValueString(),
}
if !deletedAccessItem.Reason.IsNull() {
revokeReq.Reason = deletedAccessItem.Reason.ValueString()
}
tflog.Info(ctx, "AccessUpdateRG: before calling CloudAPI().RG().AccessRevoke", map[string]any{"rg_id": plan.Id.ValueString(), "req": revokeReq})
res, err := c.CloudAPI().RG().AccessRevoke(ctx, revokeReq)
@@ -462,9 +464,6 @@ func AccessUpdateRG(ctx context.Context, rgId uint64, plan, state *models.Resour
User: addedAccessItem.User.ValueString(),
Right: addedAccessItem.Right.ValueString(),
}
if !addedAccessItem.Reason.IsNull() {
grantReq.Reason = addedAccessItem.Reason.ValueString()
}
tflog.Info(ctx, "AccessUpdateRG: before calling CloudAPI().RG().AccessGrant", map[string]any{"rg_id": plan.Id.ValueString(), "req": grantReq})
res, err := c.CloudAPI().RG().AccessGrant(ctx, grantReq)
@@ -506,9 +505,6 @@ func AccessCreateRG(ctx context.Context, rgId uint64, plan *models.ResourceRGMod
User: addedAccessItem.User.ValueString(),
Right: addedAccessItem.Right.ValueString(),
}
if !addedAccessItem.Reason.IsNull() {
grantReq.Reason = addedAccessItem.Reason.ValueString()
}
tflog.Info(ctx, "AccessCreateRG: before calling CloudAPI().RG().AccessGrant", map[string]any{
"rg_id": rgId,
@@ -568,7 +564,7 @@ func SetDefNetUpdateRG(ctx context.Context, rgId uint64, plan, state *models.Res
setDefNetNeeded = true
}
} else if !plan.DefNet.IsNull() {
} else {
setDefNetNeeded = true
}
@@ -577,25 +573,36 @@ func SetDefNetUpdateRG(ctx context.Context, rgId uint64, plan, state *models.Res
"rg_id": plan.Id.ValueString(),
"def_net_plan": plan.DefNet,
"def_net_state": state.DefNet})
setDefNetReq.NetType = itemDefNetPlan.NetType.ValueString()
if itemDefNetPlan.NetId.IsNull() {
setDefNetReq.NetID = 0 // default value
} else {
setDefNetReq.NetID = uint64(itemDefNetPlan.NetId.ValueInt64())
}
if !itemDefNetPlan.Reason.IsNull() {
setDefNetReq.Reason = itemDefNetPlan.Reason.ValueString()
}
tflog.Info(ctx, "utilitySetDefNetUpdateRG: before calling CloudAPI().RG().SetDefNet", map[string]any{"rg_id": plan.Id.ValueString(), "req": setDefNetReq})
res, err := c.CloudAPI().RG().SetDefNet(ctx, setDefNetReq)
if err != nil {
diags.AddError(
"SetDefNetUpdateRG: can not set defNet for rg",
err.Error())
return diags
if plan.DefNet.IsNull() {
removeReq := rg.RemoveDefNetRequest{RGID: uint64(state.RGID.ValueInt64())}
res, err := c.CloudAPI().RG().RemoveDefNet(ctx, removeReq)
if err != nil {
diags.AddError(
"SetDefNetUpdateRG: can not remove defNet for rg",
err.Error())
return diags
}
tflog.Info(ctx, "utilitySetDefNetUpdateRG: response from CloudAPI().RG().RemoveDefNet", map[string]any{"rg_id": plan.Id.ValueString(), "response": res})
} else {
setDefNetReq.NetType = itemDefNetPlan.NetType.ValueString()
if itemDefNetPlan.NetId.IsNull() {
setDefNetReq.NetID = 0 // default value
} else {
setDefNetReq.NetID = uint64(itemDefNetPlan.NetId.ValueInt64())
}
tflog.Info(ctx, "utilitySetDefNetUpdateRG: before calling CloudAPI().RG().SetDefNet", map[string]any{"rg_id": plan.Id.ValueString(), "req": setDefNetReq})
res, err := c.CloudAPI().RG().SetDefNet(ctx, setDefNetReq)
if err != nil {
diags.AddError(
"SetDefNetUpdateRG: can not set defNet for rg",
err.Error())
return diags
}
tflog.Info(ctx, "utilitySetDefNetUpdateRG: response from CloudAPI().RG().SetDefNet", map[string]any{"rg_id": plan.Id.ValueString(), "response": res})
}
tflog.Info(ctx, "utilitySetDefNetUpdateRG: response from CloudAPI().RG().SetDefNet", map[string]any{"rg_id": plan.Id.ValueString(), "response": res})
}
if !setDefNetNeeded {
@@ -637,9 +644,6 @@ func SetDefNetCreateRG(ctx context.Context, rgId uint64, plan *models.ResourceRG
} else {
setDefNetReq.NetID = uint64(itemDefNetPlan.NetId.ValueInt64())
}
if !itemDefNetPlan.Reason.IsNull() {
setDefNetReq.Reason = itemDefNetPlan.Reason.ValueString()
}
tflog.Info(ctx, "SetDefNetCreateRG: before calling CloudAPI().RG().SetDefNet", map[string]any{"rg_id": rgId, "req": setDefNetReq})
res, err := c.CloudAPI().RG().SetDefNet(ctx, setDefNetReq)