1.2.0
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/constants"
|
||||
@@ -34,7 +33,7 @@ func NewResourceVINSStaticRoute() resource.Resource {
|
||||
|
||||
// resourceVINSStaticRoute is the resource implementation.
|
||||
type resourceVINSStaticRoute struct {
|
||||
client *decort.DecortClient
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Create creates the resource and sets the initial Terraform state.
|
||||
@@ -80,17 +79,6 @@ func (r *resourceVINSStaticRoute) Create(ctx context.Context, req resource.Creat
|
||||
Gateway: plan.Gateway.ValueString(),
|
||||
}
|
||||
|
||||
if !plan.ComputeIDs.IsUnknown() {
|
||||
computes := make([]uint64, 0, len(plan.ComputeIDs.Elements()))
|
||||
diags = plan.ComputeIDs.ElementsAs(ctx, &computes, false)
|
||||
if diags.HasError() {
|
||||
resp.Diagnostics.Append(diags...)
|
||||
tflog.Error(ctx, "Create resourceVINSStaticRoute: cannot populate computes with plan.ComputeIDs List elements")
|
||||
return
|
||||
}
|
||||
staticReq.ComputeIds = computes
|
||||
}
|
||||
|
||||
_, err := r.client.CloudAPI().VINS().StaticRouteAdd(ctx, staticReq)
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddError("Create resourceVINSStaticRoute: Error adding static route to vins", err.Error())
|
||||
@@ -166,72 +154,9 @@ func (r *resourceVINSStaticRoute) Read(ctx context.Context, req resource.ReadReq
|
||||
|
||||
// Update updates the resource and sets the updated Terraform state on success.
|
||||
func (r *resourceVINSStaticRoute) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
|
||||
// Retrieve values from plan
|
||||
var plan models.ResourceVINSStaticRouteModel
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceVINSStaticRoute: Error receiving the plan")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceVINSStaticRoute: got plan successfully", map[string]any{"id": plan.Id.ValueString()})
|
||||
|
||||
// Retrieve values from state
|
||||
var state models.ResourceVINSStaticRouteModel
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceVINSStaticRoute: Error receiving the state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceVINSStaticRoute: got state successfully", map[string]any{"id": state.Id.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
updateTimeout, diags := plan.Timeouts.Update(ctx, constants.Timeout20m)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceVINSStaticRoute: set timeouts successfully", map[string]any{
|
||||
"id": state.Id.ValueString(),
|
||||
"updateTimeout": updateTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, updateTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Checking for values in the platform
|
||||
tflog.Info(ctx, "Update resourceVINSStaticRoute: starting input checks", map[string]any{"id": plan.Id.ValueString()})
|
||||
resp.Diagnostics.Append(resourceVINSStaticRouteInputChecks(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceVINS: Error input checks")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceVINSStaticRoute: input checks successful", map[string]any{"id": state.Id.ValueString()})
|
||||
|
||||
// change compute_ids, if needed
|
||||
if !plan.ComputeIDs.Equal(state.ComputeIDs) {
|
||||
resp.Diagnostics.Append(utilities.UpdateComputeIDsVINSStaticRoute(ctx, &plan, &state, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceVINSStaticRoute: Error updating compute_ids")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "Update resourceVINSStaticRoute: resource update is completed", map[string]any{"id": plan.Id.ValueString()})
|
||||
|
||||
// Map response body to schema and populate Computed attribute values
|
||||
resp.Diagnostics.Append(flattens.VINSStaticRouteResource(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
// Set data last update
|
||||
plan.LastUpdated = types.StringValue(time.Now().Format(time.RFC850))
|
||||
|
||||
// Set state to fully populated data
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
tflog.Error(ctx, "Update resourceVINSStaticRoute: This resource cannot be updated")
|
||||
resp.Diagnostics.AddError("This resource cannot be updated", "")
|
||||
return
|
||||
}
|
||||
|
||||
// Delete deletes the resource and removes the Terraform state on success.
|
||||
|
||||
Reference in New Issue
Block a user