chore(terraform): refactor region overrides in mapping funcs (#872)

This commit is contained in:
Ruben Hönle 2025-06-06 16:17:02 +02:00 committed by GitHub
parent 0272a86292
commit 5e5404b459
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
31 changed files with 185 additions and 194 deletions

View file

@ -115,12 +115,7 @@ func (r *bucketDataSource) Read(ctx context.Context, req datasource.ReadRequest,
}
projectId := model.ProjectId.ValueString()
bucketName := model.Name.ValueString()
var region string
if utils.IsUndefined(model.Region) {
region = r.providerData.GetRegion()
} else {
region = model.Region.ValueString()
}
region := r.providerData.GetRegionWithOverride(model.Region)
ctx = tflog.SetField(ctx, "project_id", projectId)
ctx = tflog.SetField(ctx, "name", bucketName)

View file

@ -230,10 +230,7 @@ func (r *bucketResource) Read(ctx context.Context, req resource.ReadRequest, res
}
projectId := model.ProjectId.ValueString()
bucketName := model.Name.ValueString()
region := model.Region.ValueString()
if region == "" {
region = r.providerData.GetRegion()
}
region := r.providerData.GetRegionWithOverride(model.Region)
ctx = tflog.SetField(ctx, "project_id", projectId)
ctx = tflog.SetField(ctx, "name", bucketName)

View file

@ -124,12 +124,7 @@ func (r *credentialDataSource) Read(ctx context.Context, req datasource.ReadRequ
projectId := model.ProjectId.ValueString()
credentialsGroupId := model.CredentialsGroupId.ValueString()
credentialId := model.CredentialId.ValueString()
var region string
if utils.IsUndefined(model.Region) {
region = r.providerData.GetRegion()
} else {
region = model.Region.ValueString()
}
region := r.providerData.GetRegionWithOverride(model.Region)
ctx = tflog.SetField(ctx, "project_id", projectId)
ctx = tflog.SetField(ctx, "credentials_group_id", credentialsGroupId)

View file

@ -328,10 +328,7 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest,
projectId := model.ProjectId.ValueString()
credentialsGroupId := model.CredentialsGroupId.ValueString()
credentialId := model.CredentialId.ValueString()
region := model.Region.ValueString()
if region == "" {
region = r.providerData.GetRegion()
}
region := r.providerData.GetRegionWithOverride(model.Region)
ctx = tflog.SetField(ctx, "project_id", projectId)
ctx = tflog.SetField(ctx, "credentials_group_id", credentialsGroupId)

View file

@ -12,7 +12,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
@ -114,12 +113,7 @@ func (r *credentialsGroupDataSource) Read(ctx context.Context, req datasource.Re
}
projectId := model.ProjectId.ValueString()
credentialsGroupId := model.CredentialsGroupId.ValueString()
var region string
if utils.IsUndefined(model.Region) {
region = r.providerData.GetRegion()
} else {
region = model.Region.ValueString()
}
region := r.providerData.GetRegionWithOverride(model.Region)
ctx = tflog.SetField(ctx, "project_id", projectId)
ctx = tflog.SetField(ctx, "credentials_group_id", credentialsGroupId)

View file

@ -226,14 +226,11 @@ func (r *credentialsGroupResource) Read(ctx context.Context, req resource.ReadRe
}
projectId := model.ProjectId.ValueString()
credentialsGroupId := model.CredentialsGroupId.ValueString()
region := model.Region.ValueString()
region := r.providerData.GetRegionWithOverride(model.Region)
ctx = tflog.SetField(ctx, "project_id", projectId)
ctx = tflog.SetField(ctx, "credentials_group_id", credentialsGroupId)
ctx = tflog.SetField(ctx, "region", region)
if region == "" {
region = r.providerData.GetRegion()
}
found, err := readCredentialsGroups(ctx, &model, region, r.client)
if err != nil {