1.2.2
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/path"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
|
||||
@@ -69,35 +70,42 @@ func (r *resourceBServiceGroup) Create(ctx context.Context, req resource.CreateR
|
||||
ctx, cancel := context.WithTimeout(ctx, createTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Check if input values are valid in the platform
|
||||
tflog.Info(ctx, "Create resourceBServiceGroup: starting input checks", map[string]any{"name": plan.Name.ValueString()})
|
||||
resp.Diagnostics.Append(resourceBServiceGroupInputCheck(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Create resourceBServiceGroup: Error input checks")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Create resourceBServiceGroup: input checks successful", map[string]any{"name": plan.Name.ValueString()})
|
||||
|
||||
// Make create request and get response
|
||||
diags = utilities.BServiceGroupResourceCreate(ctx, &plan, r.client)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "BServiceResourceCreatee: BService group created", map[string]any{"service_id": plan.ServiceID.ValueInt64()})
|
||||
tflog.Info(ctx, "BServiceResourceCreate: BService group created", map[string]any{"service_id": plan.ServiceID.ValueInt64()})
|
||||
|
||||
tflog.Info(ctx, "BServiceResourceCreatee: resource creation is completed", map[string]any{"service_id": plan.ServiceID.ValueInt64()})
|
||||
|
||||
currentParents, diags := types.ListValue(plan.Parents.Type(ctx), plan.Parents.Elements())
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
if !plan.Parents.IsNull() {
|
||||
oldParents := types.ListValueMust(
|
||||
types.Int64Type,
|
||||
[]attr.Value{},
|
||||
)
|
||||
resp.Diagnostics.Append(utilities.BServiceGroupParents(ctx, plan.Parents, oldParents, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "BServiceResourceCreate: resource creation is completed", map[string]any{"service_id": plan.ServiceID.ValueInt64()})
|
||||
|
||||
// Map response body to schema and populate Computed attribute values
|
||||
resp.Diagnostics.Append(flattens.BServiceGroupResource(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
if !plan.Parents.Equal(currentParents) && !currentParents.IsNull() {
|
||||
resp.Diagnostics.Append(utilities.BServiceGroupParents(ctx, plan.Parents, currentParents, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Set state to fully populated data
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
@@ -163,8 +171,7 @@ func (r *resourceBServiceGroup) Update(ctx context.Context, req resource.UpdateR
|
||||
return
|
||||
}
|
||||
|
||||
logMap := map[string]any{"service_id": plan.ID.ValueString()}
|
||||
tflog.Info(ctx, "Update resourceBServiceGroup: got plan successfully", logMap)
|
||||
tflog.Info(ctx, "Update resourceBServiceGroup: got plan successfully", map[string]any{"compgroup_name": plan.Name.ValueString()})
|
||||
|
||||
// Retrieve values from state
|
||||
var state models.ResourceRecordGroupModel
|
||||
@@ -173,6 +180,7 @@ func (r *resourceBServiceGroup) Update(ctx context.Context, req resource.UpdateR
|
||||
tflog.Error(ctx, "Update resourceBServiceGroup: Error receiving the state")
|
||||
return
|
||||
}
|
||||
logMap := map[string]any{"service_id": state.ID.ValueString()}
|
||||
tflog.Info(ctx, "Update resourceBServiceGroup: got state successfully", logMap)
|
||||
|
||||
// Set timeouts
|
||||
@@ -189,12 +197,23 @@ func (r *resourceBServiceGroup) Update(ctx context.Context, req resource.UpdateR
|
||||
ctx, cancel := context.WithTimeout(ctx, updateTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Check if input values are valid in the platform
|
||||
tflog.Info(ctx, "Create resourceBServiceGroup: starting input checks", map[string]any{"name": plan.Name.ValueString()})
|
||||
resp.Diagnostics.Append(resourceBServiceGroupInputCheck(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Create resourceBServiceGroup: Error input checks")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Create resourceBServiceGroup: input checks successful", map[string]any{"name": plan.Name.ValueString()})
|
||||
|
||||
_, err := strconv.Atoi(state.ID.ValueString())
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddError("Update resourceBServiceGroup: Cannot parse ID from state", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
plan.ID = state.ID
|
||||
|
||||
if !plan.CompCount.Equal(state.CompCount) && !plan.CompCount.IsNull() {
|
||||
resp.Diagnostics.Append(utilities.BServiceGroupResize(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
@@ -211,7 +230,7 @@ func (r *resourceBServiceGroup) Update(ctx context.Context, req resource.UpdateR
|
||||
}
|
||||
}
|
||||
|
||||
if !plan.Name.Equal(state.Name) || !plan.RAM.Equal(state.RAM) || !plan.CPU.Equal(state.CPU) || !plan.Disk.Equal(state.Disk) || !plan.Role.Equal(state.Role) {
|
||||
if !plan.Name.Equal(state.Name) || !plan.RAM.Equal(state.RAM) || !plan.CPU.Equal(state.CPU) || !plan.Disk.Equal(state.Disk) || (!plan.Role.Equal(state.Role) && !plan.Role.IsUnknown()) {
|
||||
resp.Diagnostics.Append(utilities.BServiceGroupUpdate(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceBServiceGroup: Error update bservice group")
|
||||
@@ -219,7 +238,7 @@ func (r *resourceBServiceGroup) Update(ctx context.Context, req resource.UpdateR
|
||||
}
|
||||
}
|
||||
|
||||
if !plan.ExtNets.Equal(state.ExtNets) && !plan.ExtNets.IsNull() {
|
||||
if !plan.ExtNets.Equal(state.ExtNets) && !plan.ExtNets.IsUnknown() {
|
||||
resp.Diagnostics.Append(utilities.BServiceGroupExtNet(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceBServiceGroup: Error update extnets bservice")
|
||||
@@ -227,7 +246,7 @@ func (r *resourceBServiceGroup) Update(ctx context.Context, req resource.UpdateR
|
||||
}
|
||||
}
|
||||
|
||||
if !plan.VINSes.Equal(state.VINSes) && !plan.VINSes.IsNull() {
|
||||
if !plan.VINSes.Equal(state.VINSes) && !plan.VINSes.IsUnknown() {
|
||||
resp.Diagnostics.Append(utilities.BServiceGroupVinses(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceBServiceGroup: Error update vinses bservice")
|
||||
@@ -331,7 +350,7 @@ func (r *resourceBServiceGroup) Configure(ctx context.Context, req resource.Conf
|
||||
}
|
||||
|
||||
func (r *resourceBServiceGroup) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
|
||||
idParts := strings.Split(req.ID, ",")
|
||||
idParts := strings.Split(req.ID, "#")
|
||||
|
||||
if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" {
|
||||
resp.Diagnostics.AddError(
|
||||
|
||||
Reference in New Issue
Block a user