1.1.0
This commit is contained in:
@@ -39,6 +39,7 @@ func LBResource(ctx context.Context, plan *models.ResourceLBModel, c *decort.Dec
|
||||
Timeouts: plan.Timeouts,
|
||||
SysctlParams: plan.SysctlParams,
|
||||
Permanently: plan.Permanently,
|
||||
Restore: plan.Restore,
|
||||
Restart: plan.Restart,
|
||||
Enable: plan.Enable,
|
||||
ConfigReset: plan.ConfigReset,
|
||||
|
||||
@@ -83,7 +83,7 @@ func (r *resourceLB) Create(ctx context.Context, req resource.CreateRequest, res
|
||||
// framework would mark resource as tainted and delete it, which would be unwanted behaviour.
|
||||
|
||||
// enable or disable lb, warnings added to resp.Diagnostics in case of failure.
|
||||
if !plan.Enable.IsNull() { // Enable is optional
|
||||
if !plan.Enable.ValueBool() { // Enable is optional
|
||||
diags := utilities.LBEnableDisable(ctx, &plan, r.client)
|
||||
for _, d := range diags {
|
||||
if d.Severity() == diag.SeverityError {
|
||||
@@ -307,17 +307,10 @@ func (r *resourceLB) Delete(ctx context.Context, req resource.DeleteRequest, res
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
var permanently bool
|
||||
if state.Permanently.IsNull() {
|
||||
permanently = true
|
||||
} else {
|
||||
permanently = state.Permanently.ValueBool()
|
||||
}
|
||||
|
||||
// Delete existing lb
|
||||
delReq := lb.DeleteRequest{
|
||||
LBID: uint64(state.LBID.ValueInt64()),
|
||||
Permanently: permanently,
|
||||
Permanently: state.Permanently.ValueBool(),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "Delete resourceLB: calling CloudAPI().LB().Delete", map[string]any{
|
||||
|
||||
@@ -2,6 +2,7 @@ package schemas
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
@@ -36,6 +37,8 @@ func MakeSchemaResourceLB() map[string]schema.Attribute {
|
||||
},
|
||||
"enable": schema.BoolAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Default: booldefault.StaticBool(true),
|
||||
},
|
||||
"restart": schema.BoolAttribute{
|
||||
Optional: true,
|
||||
@@ -45,9 +48,13 @@ func MakeSchemaResourceLB() map[string]schema.Attribute {
|
||||
},
|
||||
"permanently": schema.BoolAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Default: booldefault.StaticBool(true),
|
||||
},
|
||||
"restore": schema.BoolAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Default: booldefault.StaticBool(true),
|
||||
},
|
||||
"safe": schema.BoolAttribute{
|
||||
Optional: true,
|
||||
|
||||
@@ -91,7 +91,7 @@ func LBEnableDisable(ctx context.Context, plan *models.ResourceLBModel, c *decor
|
||||
diags.AddError("Cannot parsed ID lb from state", err.Error())
|
||||
return diags
|
||||
}
|
||||
if plan.Enable.IsNull() || plan.Enable.ValueBool() {
|
||||
if plan.Enable.ValueBool() {
|
||||
tflog.Info(ctx, "Enable lb with ID", map[string]any{"lb_id": plan.ID.ValueString()})
|
||||
_, err := c.CloudAPI().LB().Enable(ctx, lb.DisableEnableRequest{LBID: lbId})
|
||||
if err != nil {
|
||||
@@ -131,7 +131,7 @@ func LBReadStatus(ctx context.Context, plan *models.ResourceLBModel, c *decort.D
|
||||
diags.AddError("Error:", fmt.Sprintf("The lb is in status: %s, please, contact support for more information", lbItem.Status))
|
||||
return diags
|
||||
case status.Deleted:
|
||||
if plan.Restore.ValueBool() || plan.Restore.IsNull() {
|
||||
if plan.Restore.ValueBool() {
|
||||
diags = LBRestore(ctx, plan, c)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, "Error restore lb", map[string]any{"lb_id": plan.ID.ValueString()})
|
||||
@@ -141,7 +141,7 @@ func LBReadStatus(ctx context.Context, plan *models.ResourceLBModel, c *decort.D
|
||||
diags.AddError("LB in status Deleted:", "please clean state, or restore lb")
|
||||
return diags
|
||||
}
|
||||
if plan.Enable.ValueBool() || plan.Enable.IsNull() {
|
||||
if plan.Enable.ValueBool() {
|
||||
diags = LBEnableDisable(ctx, plan, c)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, "Error enable/disable lb", map[string]any{"lb_id": plan.ID.ValueString()})
|
||||
@@ -196,7 +196,7 @@ func LBStartStop(ctx context.Context, plan *models.ResourceLBModel, c *decort.De
|
||||
diags.AddError("Cannot parsed ID lb from state", err.Error())
|
||||
return diags
|
||||
}
|
||||
if plan.Enable.IsNull() || plan.Enable.ValueBool() {
|
||||
if plan.Enable.ValueBool() {
|
||||
if plan.Start.ValueBool() || plan.Start.IsNull() {
|
||||
tflog.Info(ctx, "Start lb with ID", map[string]any{"lb_id": plan.ID.ValueString()})
|
||||
_, err := c.CloudAPI().LB().Start(ctx, lb.StartRequest{LBID: lbId})
|
||||
@@ -206,7 +206,7 @@ func LBStartStop(ctx context.Context, plan *models.ResourceLBModel, c *decort.De
|
||||
}
|
||||
}
|
||||
}
|
||||
if plan.Enable.ValueBool() || plan.Enable.IsNull() {
|
||||
if plan.Enable.ValueBool() {
|
||||
tflog.Info(ctx, "Stop lb with ID", map[string]any{"lb_id": plan.ID.ValueString()})
|
||||
if !plan.Start.ValueBool() && !plan.Start.IsNull() {
|
||||
_, err := c.CloudAPI().LB().Stop(ctx, lb.StopRequest{LBID: lbId})
|
||||
|
||||
Reference in New Issue
Block a user