terraform-provider-stackitp.../stackit/internal/utils/regions.go
Patrick Koss 435de4c9eb
feat: add model serving resource
* add model serving

* add right provider config

* rename model_serving to modelserving

* add model serving custom endpoint everywhere

* rename file

* add default region, docs for model serving

* add right order of wait handler

* rotate after to token

* fixes

* add initial doc files

* address code comments

* refactor region description

* remove warning for not found resources

* add service enablement

* address code comments

* address code comments

* fix datasource

* fix acc test

* review changes

* review changes

* review changes

* review changes

* review changes

* review changes

* review changes

* review changes

* review changes

* embed markdown description

* go tidy

---------

Co-authored-by: Mauritz Uphoff <mauritz.uphoff@me.com>
Co-authored-by: Mauritz Uphoff <39736813+h3adex@users.noreply.github.com>
2025-03-28 16:20:25 +01:00

39 lines
1.3 KiB
Go

package utils
import (
"context"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
)
// AdaptRegion rewrites the region of a terraform plan
func AdaptRegion(ctx context.Context, configRegion types.String, planRegion *types.String, defaultRegion string, resp *resource.ModifyPlanResponse) {
// Get the intended region. This is either set directly set in the individual
// config or the provider region has to be used
var intendedRegion types.String
if configRegion.IsNull() {
if defaultRegion == "" {
core.LogAndAddError(ctx, &resp.Diagnostics, "set region", "no region defined in config or provider")
return
}
intendedRegion = types.StringValue(defaultRegion)
} else {
intendedRegion = configRegion
}
// check if the currently configured region corresponds to the planned region
// on mismatch override the planned region with the intended region
// and force a replacement of the resource
p := path.Root("region")
if !intendedRegion.Equal(*planRegion) {
resp.RequiresReplace.Append(p)
*planRegion = intendedRegion
}
resp.Diagnostics.Append(resp.Plan.SetAttribute(ctx, p, *planRegion)...)
if resp.Diagnostics.HasError() {
return
}
}