fix: region handling in routingtable resources didn't detect default_region changes (#1006)
This commit is contained in:
parent
e5c2c7eab4
commit
16446d7c4e
2 changed files with 62 additions and 1 deletions
|
|
@ -31,6 +31,7 @@ var (
|
||||||
_ resource.Resource = &routeResource{}
|
_ resource.Resource = &routeResource{}
|
||||||
_ resource.ResourceWithConfigure = &routeResource{}
|
_ resource.ResourceWithConfigure = &routeResource{}
|
||||||
_ resource.ResourceWithImportState = &routeResource{}
|
_ resource.ResourceWithImportState = &routeResource{}
|
||||||
|
_ resource.ResourceWithModifyPlan = &routeResource{}
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewRoutingTableRouteResource is a helper function to simplify the provider implementation.
|
// 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")
|
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.
|
// Schema defines the schema for the resource.
|
||||||
func (r *routeResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
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."
|
description := "Routing table route resource schema. Must have a `region` specified in the provider configuration."
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
|
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
|
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
|
||||||
|
|
||||||
iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils"
|
iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils"
|
||||||
|
|
@ -36,6 +35,7 @@ var (
|
||||||
_ resource.Resource = &routingTableResource{}
|
_ resource.Resource = &routingTableResource{}
|
||||||
_ resource.ResourceWithConfigure = &routingTableResource{}
|
_ resource.ResourceWithConfigure = &routingTableResource{}
|
||||||
_ resource.ResourceWithImportState = &routingTableResource{}
|
_ resource.ResourceWithImportState = &routingTableResource{}
|
||||||
|
_ resource.ResourceWithModifyPlan = &routingTableResource{}
|
||||||
)
|
)
|
||||||
|
|
||||||
type Model struct {
|
type Model struct {
|
||||||
|
|
@ -89,6 +89,36 @@ func (r *routingTableResource) Configure(ctx context.Context, req resource.Confi
|
||||||
tflog.Info(ctx, "IaaS alpha client configured")
|
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) {
|
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."
|
description := "Routing table resource schema. Must have a `region` specified in the provider configuration."
|
||||||
resp.Schema = schema.Schema{
|
resp.Schema = schema.Schema{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue