Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
_ resource.Resource = &routeResource{}
_ resource.ResourceWithConfigure = &routeResource{}
_ resource.ResourceWithImportState = &routeResource{}
_ resource.ResourceWithModifyPlan = &routeResource{}
)

// NewRoutingTableRouteResource is a helper function to simplify the provider implementation.
Expand Down Expand Up @@ -70,6 +71,36 @@ func (r *routeResource) Configure(ctx context.Context, req resource.ConfigureReq
tflog.Info(ctx, "IaaS alpha client configured")
}

// ModifyPlan implements resource.ResourceWithModifyPlan.
// Use the modifier to set the effective region in the current plan.
func (r *routeResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { // nolint:gocritic // function signature required by Terraform
// skip initial empty configuration to avoid follow-up errors
if req.Config.Raw.IsNull() {
return
}

var configModel shared.RouteModel
resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...)
if resp.Diagnostics.HasError() {
return
}
var planModel shared.RouteModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &planModel)...)
if resp.Diagnostics.HasError() {
return
}

utils.AdaptRegion(ctx, configModel.Region, &planModel.Region, r.providerData.GetRegion(), resp)
if resp.Diagnostics.HasError() {
return
}

resp.Diagnostics.Append(resp.Plan.Set(ctx, planModel)...)
if resp.Diagnostics.HasError() {
return
}
}

// Schema defines the schema for the resource.
func (r *routeResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
description := "Routing table route resource schema. Must have a `region` specified in the provider configuration."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"

"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"

iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils"
Expand Down Expand Up @@ -36,6 +35,7 @@ var (
_ resource.Resource = &routingTableResource{}
_ resource.ResourceWithConfigure = &routingTableResource{}
_ resource.ResourceWithImportState = &routingTableResource{}
_ resource.ResourceWithModifyPlan = &routingTableResource{}
)

type Model struct {
Expand Down Expand Up @@ -89,6 +89,36 @@ func (r *routingTableResource) Configure(ctx context.Context, req resource.Confi
tflog.Info(ctx, "IaaS alpha client configured")
}

// ModifyPlan implements resource.ResourceWithModifyPlan.
// Use the modifier to set the effective region in the current plan.
func (r *routingTableResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { // nolint:gocritic // function signature required by Terraform
// skip initial empty configuration to avoid follow-up errors
if req.Config.Raw.IsNull() {
return
}
var configModel Model
resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...)
if resp.Diagnostics.HasError() {
return
}

var planModel Model
resp.Diagnostics.Append(req.Plan.Get(ctx, &planModel)...)
if resp.Diagnostics.HasError() {
return
}

utils.AdaptRegion(ctx, configModel.Region, &planModel.Region, r.providerData.GetRegion(), resp)
if resp.Diagnostics.HasError() {
return
}

resp.Diagnostics.Append(resp.Plan.Set(ctx, planModel)...)
if resp.Diagnostics.HasError() {
return
}
}

func (r *routingTableResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
description := "Routing table resource schema. Must have a `region` specified in the provider configuration."
resp.Schema = schema.Schema{
Expand Down
Loading