fix: region handling in routingtable resources didn't detect default_region changes (#1006)

This commit is contained in:
Marcel Jacek 2025-09-24 15:12:53 +02:00 committed by GitHub
parent e5c2c7eab4
commit 16446d7c4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 62 additions and 1 deletions

View file

@ -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.
@ -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."

View file

@ -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"
@ -36,6 +35,7 @@ var (
_ resource.Resource = &routingTableResource{}
_ resource.ResourceWithConfigure = &routingTableResource{}
_ resource.ResourceWithImportState = &routingTableResource{}
_ resource.ResourceWithModifyPlan = &routingTableResource{}
)
type Model struct {
@ -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{