1.1.0
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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, "aPlan, basetypes.ObjectAsOptions{})
|
||||
diags = plan.Quota.As(ctx, "aPlan, basetypes.ObjectAsOptions{UnhandledNullAsEmpty: true, UnhandledUnknownAsEmpty: true})
|
||||
if diags.HasError() {
|
||||
return diags
|
||||
}
|
||||
}
|
||||
if !state.Quota.IsNull() {
|
||||
diags = state.Quota.As(ctx, "aState, basetypes.ObjectAsOptions{})
|
||||
diags = state.Quota.As(ctx, "aState, 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)
|
||||
|
||||
Reference in New Issue
Block a user