|
8 | 8 | "time" |
9 | 9 |
|
10 | 10 | "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" |
11 | | - |
12 | 11 | "github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier" |
13 | 12 |
|
14 | 13 | iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils" |
|
36 | 35 | _ resource.Resource = &routingTableResource{} |
37 | 36 | _ resource.ResourceWithConfigure = &routingTableResource{} |
38 | 37 | _ resource.ResourceWithImportState = &routingTableResource{} |
| 38 | + _ resource.ResourceWithModifyPlan = &routingTableResource{} |
39 | 39 | ) |
40 | 40 |
|
41 | 41 | type Model struct { |
@@ -89,6 +89,36 @@ func (r *routingTableResource) Configure(ctx context.Context, req resource.Confi |
89 | 89 | tflog.Info(ctx, "IaaS alpha client configured") |
90 | 90 | } |
91 | 91 |
|
| 92 | +// ModifyPlan implements resource.ResourceWithModifyPlan. |
| 93 | +// Use the modifier to set the effective region in the current plan. |
| 94 | +func (r *routingTableResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { // nolint:gocritic // function signature required by Terraform |
| 95 | + // skip initial empty configuration to avoid follow-up errors |
| 96 | + if req.Config.Raw.IsNull() { |
| 97 | + return |
| 98 | + } |
| 99 | + var configModel Model |
| 100 | + resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...) |
| 101 | + if resp.Diagnostics.HasError() { |
| 102 | + return |
| 103 | + } |
| 104 | + |
| 105 | + var planModel Model |
| 106 | + resp.Diagnostics.Append(req.Plan.Get(ctx, &planModel)...) |
| 107 | + if resp.Diagnostics.HasError() { |
| 108 | + return |
| 109 | + } |
| 110 | + |
| 111 | + utils.AdaptRegion(ctx, configModel.Region, &planModel.Region, r.providerData.GetRegion(), resp) |
| 112 | + if resp.Diagnostics.HasError() { |
| 113 | + return |
| 114 | + } |
| 115 | + |
| 116 | + resp.Diagnostics.Append(resp.Plan.Set(ctx, planModel)...) |
| 117 | + if resp.Diagnostics.HasError() { |
| 118 | + return |
| 119 | + } |
| 120 | +} |
| 121 | + |
92 | 122 | func (r *routingTableResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { |
93 | 123 | description := "Routing table resource schema. Must have a `region` specified in the provider configuration." |
94 | 124 | resp.Schema = schema.Schema{ |
|
0 commit comments