chore(terraform): use a util func to build internal terraform id (#869)

This commit is contained in:
Ruben Hönle 2025-06-12 14:41:57 +02:00 committed by GitHub
parent 801ef6033d
commit b313ef6a39
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
72 changed files with 205 additions and 538 deletions

View file

@ -335,14 +335,7 @@ func mapFields(bucketResp *objectstorage.GetBucketResponse, model *Model, region
}
bucket := bucketResp.Bucket
idParts := []string{
model.ProjectId.ValueString(),
region,
model.Name.ValueString(),
}
model.Id = types.StringValue(
strings.Join(idParts, core.Separator),
)
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), region, model.Name.ValueString())
model.URLPathStyle = types.StringPointerValue(bucket.UrlPathStyle)
model.URLVirtualHostedStyle = types.StringPointerValue(bucket.UrlVirtualHostedStyle)
model.Region = types.StringValue(region)

View file

@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net/http"
"strings"
"time"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
@ -201,14 +200,8 @@ func mapDataSourceFields(credentialResp *objectstorage.AccessKey, model *DataSou
model.ExpirationTimestamp = types.StringValue(expirationTimestamp.Format(time.RFC3339))
}
idParts := []string{
model.ProjectId.ValueString(),
region,
model.CredentialsGroupId.ValueString(),
credentialId,
}
model.Id = types.StringValue(
strings.Join(idParts, core.Separator),
model.Id = utils.BuildInternalTerraformId(
model.ProjectId.ValueString(), region, model.CredentialsGroupId.ValueString(), credentialId,
)
model.CredentialId = types.StringValue(credentialId)
model.Name = types.StringPointerValue(credentialResp.DisplayName)

View file

@ -503,14 +503,8 @@ func mapFields(credentialResp *objectstorage.CreateAccessKeyResponse, model *Mod
model.ExpirationTimestamp = types.StringValue(expirationTimestamp.Format(time.RFC3339))
}
idParts := []string{
model.ProjectId.ValueString(),
region,
model.CredentialsGroupId.ValueString(),
credentialId,
}
model.Id = types.StringValue(
strings.Join(idParts, core.Separator),
model.Id = utils.BuildInternalTerraformId(
model.ProjectId.ValueString(), region, model.CredentialsGroupId.ValueString(), credentialId,
)
model.CredentialId = types.StringValue(credentialId)
model.Name = types.StringPointerValue(credentialResp.DisplayName)
@ -548,15 +542,7 @@ func readCredentials(ctx context.Context, model *Model, region string, client *o
foundCredential = true
idParts := []string{
projectId,
region,
credentialsGroupId,
credentialId,
}
model.Id = types.StringValue(
strings.Join(idParts, core.Separator),
)
model.Id = utils.BuildInternalTerraformId(projectId, region, credentialsGroupId, credentialId)
model.Name = types.StringPointerValue(credential.DisplayName)
if credential.Expires == nil {

View file

@ -12,7 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
coreutils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
"github.com/hashicorp/terraform-plugin-framework/path"
@ -22,7 +22,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
"github.com/stackitcloud/stackit-sdk-go/core/utils"
sdkUtils "github.com/stackitcloud/stackit-sdk-go/core/utils"
"github.com/stackitcloud/stackit-sdk-go/services/objectstorage"
)
@ -73,7 +73,7 @@ func (r *credentialsGroupResource) ModifyPlan(ctx context.Context, req resource.
return
}
coreutils.AdaptRegion(ctx, configModel.Region, &planModel.Region, r.providerData.GetRegion(), resp)
utils.AdaptRegion(ctx, configModel.Region, &planModel.Region, r.providerData.GetRegion(), resp)
if resp.Diagnostics.HasError() {
return
}
@ -185,7 +185,7 @@ func (r *credentialsGroupResource) Create(ctx context.Context, req resource.Crea
ctx = tflog.SetField(ctx, "region", region)
createCredentialsGroupPayload := objectstorage.CreateCredentialsGroupPayload{
DisplayName: utils.Ptr(credentialsGroupName),
DisplayName: sdkUtils.Ptr(credentialsGroupName),
}
// Handle project init
@ -324,7 +324,7 @@ func mapFields(credentialsGroupResp *objectstorage.CreateCredentialsGroupRespons
func mapCredentialsGroup(credentialsGroup objectstorage.CredentialsGroup, model *Model, region string) error {
var credentialsGroupId string
if !coreutils.IsUndefined(model.CredentialsGroupId) {
if !utils.IsUndefined(model.CredentialsGroupId) {
credentialsGroupId = model.CredentialsGroupId.ValueString()
} else if credentialsGroup.CredentialsGroupId != nil {
credentialsGroupId = *credentialsGroup.CredentialsGroupId
@ -332,14 +332,7 @@ func mapCredentialsGroup(credentialsGroup objectstorage.CredentialsGroup, model
return fmt.Errorf("credential id not present")
}
idParts := []string{
model.ProjectId.ValueString(),
region,
credentialsGroupId,
}
model.Id = types.StringValue(
strings.Join(idParts, core.Separator),
)
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), region, credentialsGroupId)
model.CredentialsGroupId = types.StringValue(credentialsGroupId)
model.URN = types.StringPointerValue(credentialsGroup.Urn)
model.Name = types.StringPointerValue(credentialsGroup.DisplayName)