chore(terraform): use a util func to build internal terraform id (#869)
This commit is contained in:
parent
801ef6033d
commit
b313ef6a39
72 changed files with 205 additions and 538 deletions
|
|
@ -7,6 +7,8 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
authorizationUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/authorization/utils"
|
||||
|
||||
|
|
@ -281,15 +283,7 @@ func mapListMembersResponse(resp *authorization.ListMembersResponse, model *Mode
|
|||
return fmt.Errorf("model input is nil")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ResourceId.ValueString(),
|
||||
model.Role.ValueString(),
|
||||
model.Subject.ValueString(),
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
|
||||
model.Id = utils.BuildInternalTerraformId(model.ResourceId.ValueString(), model.Role.ValueString(), model.Subject.ValueString())
|
||||
model.ResourceId = types.StringPointerValue(resp.ResourceId)
|
||||
|
||||
for _, m := range *resp.Members {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
cdnUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/cdn/utils"
|
||||
|
||||
|
|
@ -274,9 +276,7 @@ func mapCustomDomainFields(customDomain *cdn.CustomDomain, model *CustomDomainMo
|
|||
return fmt.Errorf("Status missing in response")
|
||||
}
|
||||
|
||||
id := model.ProjectId.ValueString() + core.Separator + model.DistributionId.ValueString() + core.Separator + *customDomain.Name
|
||||
|
||||
model.ID = types.StringValue(id)
|
||||
model.ID = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), model.DistributionId.ValueString(), *customDomain.Name)
|
||||
model.Status = types.StringValue(string(*customDomain.Status))
|
||||
|
||||
customDomainErrors := []attr.Value{}
|
||||
|
|
|
|||
|
|
@ -447,9 +447,7 @@ func mapFields(distribution *cdn.Distribution, model *Model) error {
|
|||
return fmt.Errorf("Status missing in response")
|
||||
}
|
||||
|
||||
id := *distribution.ProjectId + core.Separator + *distribution.Id
|
||||
|
||||
model.ID = types.StringValue(id)
|
||||
model.ID = utils.BuildInternalTerraformId(*distribution.ProjectId, *distribution.Id)
|
||||
model.DistributionId = types.StringValue(*distribution.Id)
|
||||
model.ProjectId = types.StringValue(*distribution.ProjectId)
|
||||
model.Status = types.StringValue(string(distribution.GetStatus()))
|
||||
|
|
|
|||
|
|
@ -420,13 +420,8 @@ func mapFields(ctx context.Context, recordSetResp *dns.RecordSetResponse, model
|
|||
|
||||
model.Records = recordsTF
|
||||
}
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
model.ZoneId.ValueString(),
|
||||
recordSetId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
model.Id = utils.BuildInternalTerraformId(
|
||||
model.ProjectId.ValueString(), model.ZoneId.ValueString(), recordSetId,
|
||||
)
|
||||
model.RecordSetId = types.StringPointerValue(recordSet.Id)
|
||||
model.Active = types.BoolPointerValue(recordSet.Active)
|
||||
|
|
|
|||
|
|
@ -487,13 +487,7 @@ func mapFields(ctx context.Context, zoneResp *dns.ZoneResponse, model *Model) er
|
|||
return fmt.Errorf("zone id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
zoneId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), zoneId)
|
||||
|
||||
if z.Primaries == nil {
|
||||
model.Primaries = types.ListNull(types.StringType)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import (
|
|||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
gitUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/git/utils"
|
||||
|
||||
|
|
@ -306,8 +308,7 @@ func mapFields(resp *git.Instance, model *Model) error {
|
|||
}
|
||||
|
||||
// Build the ID by combining the project ID and instance id and assign the model's fields.
|
||||
idParts := []string{model.ProjectId.ValueString(), *resp.Id}
|
||||
model.Id = types.StringValue(strings.Join(idParts, core.Separator))
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), *resp.Id)
|
||||
model.Url = types.StringPointerValue(resp.Url)
|
||||
model.Name = types.StringPointerValue(resp.Name)
|
||||
model.InstanceId = types.StringPointerValue(resp.Id)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
|
|
@ -301,13 +303,7 @@ func mapFields(ctx context.Context, affinityGroupResp *iaas.AffinityGroup, model
|
|||
return fmt.Errorf("affinity group id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
affinityGroupId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), affinityGroupId)
|
||||
|
||||
if affinityGroupResp.Members != nil && len(*affinityGroupResp.Members) > 0 {
|
||||
members, diags := types.ListValueFrom(ctx, types.StringType, *affinityGroupResp.Members)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils"
|
||||
|
|
@ -265,13 +264,7 @@ func mapDataSourceFields(ctx context.Context, imageResp *iaas.Image, model *Data
|
|||
return fmt.Errorf("image id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
imageId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), imageId)
|
||||
|
||||
// Map config
|
||||
var configModel = &configModel{}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
|
|
@ -603,13 +605,7 @@ func mapFields(ctx context.Context, imageResp *iaas.Image, model *Model) error {
|
|||
return fmt.Errorf("image id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
imageId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), imageId)
|
||||
|
||||
// Map config
|
||||
var configModel = &configModel{}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils"
|
||||
|
|
@ -245,13 +244,7 @@ func mapDataSourceFields(ctx context.Context, networkResp *iaas.Network, model *
|
|||
return fmt.Errorf("network id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
networkId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), networkId)
|
||||
|
||||
labels, err := iaasUtils.MapLabels(ctx, networkResp.Labels, model.Labels)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -503,13 +503,7 @@ func mapFields(ctx context.Context, networkResp *iaas.Network, model *Model) err
|
|||
return fmt.Errorf("network id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
networkId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), networkId)
|
||||
|
||||
labels, err := iaasUtils.MapLabels(ctx, networkResp.Labels, model.Labels)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -477,13 +477,7 @@ func mapFields(ctx context.Context, networkAreaResp *iaas.NetworkArea, networkAr
|
|||
return fmt.Errorf("network area id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.OrganizationId.ValueString(),
|
||||
networkAreaId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.OrganizationId.ValueString(), networkAreaId)
|
||||
|
||||
if networkAreaResp.Ipv4 == nil || networkAreaResp.Ipv4.DefaultNameservers == nil {
|
||||
model.DefaultNameservers = types.ListNull(types.StringType)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import (
|
|||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/path"
|
||||
|
|
@ -370,14 +372,7 @@ func mapFields(ctx context.Context, networkAreaRoute *iaas.Route, model *Model)
|
|||
return fmt.Errorf("network area route id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.OrganizationId.ValueString(),
|
||||
model.NetworkAreaId.ValueString(),
|
||||
networkAreaRouteId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.OrganizationId.ValueString(), model.NetworkAreaId.ValueString(), networkAreaRouteId)
|
||||
|
||||
labels, err := iaasUtils.MapLabels(ctx, networkAreaRoute.Labels, model.Labels)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -423,14 +423,7 @@ func mapFields(ctx context.Context, networkInterfaceResp *iaas.NIC, model *Model
|
|||
return fmt.Errorf("network interface id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
model.NetworkId.ValueString(),
|
||||
networkInterfaceId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), model.NetworkId.ValueString(), networkInterfaceId)
|
||||
|
||||
respAllowedAddresses := []string{}
|
||||
var diags diag.Diagnostics
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import (
|
|||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils"
|
||||
|
||||
|
|
@ -142,14 +144,7 @@ func (r *networkInterfaceAttachResource) Create(ctx context.Context, req resourc
|
|||
return
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
projectId,
|
||||
serverId,
|
||||
networkInterfaceId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(projectId, serverId, networkInterfaceId)
|
||||
|
||||
// Set state to fully populated data
|
||||
diags = resp.State.Set(ctx, model)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import (
|
|||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/path"
|
||||
|
|
@ -330,13 +332,7 @@ func mapFields(ctx context.Context, publicIpResp *iaas.PublicIp, model *Model) e
|
|||
return fmt.Errorf("public IP id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
publicIpId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), publicIpId)
|
||||
|
||||
labels, err := iaasUtils.MapLabels(ctx, publicIpResp.Labels, model.Labels)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import (
|
|||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/path"
|
||||
|
|
@ -306,15 +308,9 @@ func mapFields(publicIpResp *iaas.PublicIp, model *Model) error {
|
|||
model.NetworkInterfaceId = types.StringNull()
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
publicIpId,
|
||||
model.NetworkInterfaceId.ValueString(),
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
model.Id = utils.BuildInternalTerraformId(
|
||||
model.ProjectId.ValueString(), publicIpId, model.NetworkInterfaceId.ValueString(),
|
||||
)
|
||||
|
||||
model.PublicIpId = types.StringValue(publicIpId)
|
||||
model.Ip = types.StringPointerValue(publicIpResp.Ip)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils"
|
||||
|
|
@ -175,8 +174,7 @@ func mapPublicIpRanges(_ context.Context, publicIpRanges *[]iaas.PublicNetwork,
|
|||
// Sort to prevent unnecessary recreation of dependent resources due to order changes.
|
||||
sort.Strings(apiIpRanges)
|
||||
|
||||
modelId := strings.Join(apiIpRanges, ",")
|
||||
model.Id = types.StringValue(modelId)
|
||||
model.Id = utils.BuildInternalTerraformId(apiIpRanges...)
|
||||
|
||||
var ipRangesList []attr.Value
|
||||
for _, cidr := range apiIpRanges {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
||||
|
|
@ -349,13 +351,7 @@ func mapFields(ctx context.Context, securityGroupResp *iaas.SecurityGroup, model
|
|||
return fmt.Errorf("security group id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
securityGroupId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), securityGroupId)
|
||||
|
||||
labels, err := iaasUtils.MapLabels(ctx, securityGroupResp.Labels, model.Labels)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -572,15 +572,7 @@ func mapFields(securityGroupRuleResp *iaas.SecurityGroupRule, model *Model) erro
|
|||
return fmt.Errorf("security group rule id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
model.SecurityGroupId.ValueString(),
|
||||
securityGroupRuleId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), model.SecurityGroupId.ValueString(), securityGroupRuleId)
|
||||
model.SecurityGroupRuleId = types.StringValue(securityGroupRuleId)
|
||||
model.Direction = types.StringPointerValue(securityGroupRuleResp.Direction)
|
||||
model.Description = types.StringPointerValue(securityGroupRuleResp.Description)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
|
|
@ -239,13 +238,7 @@ func mapDataSourceFields(ctx context.Context, serverResp *iaas.Server, model *Da
|
|||
return fmt.Errorf("server id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
serverId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), serverId)
|
||||
|
||||
labels, err := iaasUtils.MapLabels(ctx, serverResp.Labels, model.Labels)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -821,13 +821,7 @@ func mapFields(ctx context.Context, serverResp *iaas.Server, model *Model) error
|
|||
return fmt.Errorf("server id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
serverId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), serverId)
|
||||
|
||||
labels, err := iaasUtils.MapLabels(ctx, serverResp.Labels, model.Labels)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import (
|
|||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils"
|
||||
|
||||
|
|
@ -138,14 +140,7 @@ func (r *networkInterfaceAttachResource) Create(ctx context.Context, req resourc
|
|||
return
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
projectId,
|
||||
serverId,
|
||||
serviceAccountEmail,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(projectId, serverId, serviceAccountEmail)
|
||||
|
||||
// Set state to fully populated data
|
||||
diags = resp.State.Set(ctx, model)
|
||||
|
|
|
|||
|
|
@ -513,13 +513,7 @@ func mapFields(ctx context.Context, volumeResp *iaas.Volume, model *Model) error
|
|||
return fmt.Errorf("Volume id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
volumeId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), volumeId)
|
||||
|
||||
labels, err := iaasUtils.MapLabels(ctx, volumeResp.Labels, model.Labels)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import (
|
|||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils"
|
||||
|
||||
|
|
@ -18,7 +20,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"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/iaas"
|
||||
"github.com/stackitcloud/stackit-sdk-go/services/iaas/wait"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
|
||||
|
|
@ -140,7 +142,7 @@ func (r *volumeAttachResource) Create(ctx context.Context, req resource.CreateRe
|
|||
// Create new Volume attachment
|
||||
|
||||
payload := iaas.AddVolumeToServerPayload{
|
||||
DeleteOnTermination: utils.Ptr(false),
|
||||
DeleteOnTermination: sdkUtils.Ptr(false),
|
||||
}
|
||||
_, err := r.client.AddVolumeToServer(ctx, projectId, serverId, volumeId).AddVolumeToServerPayload(payload).Execute()
|
||||
if err != nil {
|
||||
|
|
@ -154,14 +156,7 @@ func (r *volumeAttachResource) Create(ctx context.Context, req resource.CreateRe
|
|||
return
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
projectId,
|
||||
serverId,
|
||||
volumeId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(projectId, serverId, volumeId)
|
||||
|
||||
// Set state to fully populated data
|
||||
diags = resp.State.Set(ctx, model)
|
||||
|
|
|
|||
|
|
@ -1204,14 +1204,7 @@ func mapFields(ctx context.Context, lb *loadbalancer.LoadBalancer, m *Model, reg
|
|||
}
|
||||
m.Region = types.StringValue(region)
|
||||
m.Name = types.StringValue(name)
|
||||
idParts := []string{
|
||||
m.ProjectId.ValueString(),
|
||||
m.Region.ValueString(),
|
||||
name,
|
||||
}
|
||||
m.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
m.Id = utils.BuildInternalTerraformId(m.ProjectId.ValueString(), m.Region.ValueString(), name)
|
||||
|
||||
m.ExternalAddress = types.StringPointerValue(lb.ExternalAddress)
|
||||
m.PrivateAddress = types.StringPointerValue(lb.PrivateAddress)
|
||||
|
|
|
|||
|
|
@ -357,14 +357,10 @@ func mapFields(cred *loadbalancer.CredentialsResponse, m *Model, region string)
|
|||
}
|
||||
m.Username = types.StringValue(username)
|
||||
m.Region = types.StringValue(region)
|
||||
|
||||
idParts := []string{
|
||||
m.Id = utils.BuildInternalTerraformId(
|
||||
m.ProjectId.ValueString(),
|
||||
m.Region.ValueString(),
|
||||
m.CredentialsRef.ValueString(),
|
||||
}
|
||||
m.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import (
|
|||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
logmeUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/logme/utils"
|
||||
|
||||
|
|
@ -312,14 +314,7 @@ func mapFields(credentialsResp *logme.CredentialsResponse, model *Model) error {
|
|||
return fmt.Errorf("credentials id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
model.InstanceId.ValueString(),
|
||||
credentialId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), model.InstanceId.ValueString(), credentialId)
|
||||
model.CredentialId = types.StringValue(credentialId)
|
||||
if credentials != nil {
|
||||
model.Host = types.StringPointerValue(credentials.Host)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
logmeUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/logme/utils"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
||||
|
|
@ -614,13 +616,7 @@ func mapFields(instance *logme.Instance, model *Model) error {
|
|||
return fmt.Errorf("instance id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
instanceId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), instanceId)
|
||||
model.InstanceId = types.StringValue(instanceId)
|
||||
model.PlanId = types.StringPointerValue(instance.PlanId)
|
||||
model.CfGuid = types.StringPointerValue(instance.CfGuid)
|
||||
|
|
|
|||
|
|
@ -322,13 +322,10 @@ func mapFields(ctx context.Context, credentialsResp *mariadb.CredentialsResponse
|
|||
return fmt.Errorf("credentials id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.Id = utils.BuildInternalTerraformId(
|
||||
model.ProjectId.ValueString(),
|
||||
model.InstanceId.ValueString(),
|
||||
credentialId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
|
||||
modelHosts, err := utils.ListValuetoStringSlice(model.Hosts)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import (
|
|||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
mariadbUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/mariadb/utils"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
||||
|
|
@ -507,13 +509,7 @@ func mapFields(instance *mariadb.Instance, model *Model) error {
|
|||
return fmt.Errorf("instance id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
instanceId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), instanceId)
|
||||
model.InstanceId = types.StringValue(instanceId)
|
||||
model.PlanId = types.StringPointerValue(instance.PlanId)
|
||||
model.CfGuid = types.StringPointerValue(instance.CfGuid)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
modelservingUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/modelserving/utils"
|
||||
|
|
@ -538,10 +537,7 @@ func mapCreateResponse(tokenCreateResp *modelserving.CreateTokenResponse, waitRe
|
|||
return fmt.Errorf("response input is nil")
|
||||
}
|
||||
|
||||
idParts := []string{model.ProjectId.ValueString(), region, *tokenCreateResp.Token.Id}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), region, *tokenCreateResp.Token.Id)
|
||||
model.TokenId = types.StringPointerValue(token.Id)
|
||||
model.Name = types.StringPointerValue(token.Name)
|
||||
model.State = types.StringValue(string(waitResp.Token.GetState()))
|
||||
|
|
@ -570,8 +566,7 @@ func mapGetResponse(tokenGetResp *modelserving.GetTokenResponse, model *Model) e
|
|||
validUntil = types.StringValue(tokenGetResp.Token.ValidUntil.Format(time.RFC3339))
|
||||
}
|
||||
|
||||
idParts := []string{model.ProjectId.ValueString(), model.Region.ValueString(), model.TokenId.ValueString()}
|
||||
model.Id = types.StringValue(strings.Join(idParts, core.Separator))
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), model.Region.ValueString(), model.TokenId.ValueString())
|
||||
model.TokenId = types.StringPointerValue(tokenGetResp.Token.Id)
|
||||
model.Name = types.StringPointerValue(tokenGetResp.Token.Name)
|
||||
model.State = types.StringValue(string(tokenGetResp.Token.GetState()))
|
||||
|
|
|
|||
|
|
@ -785,13 +785,7 @@ func mapFields(ctx context.Context, resp *mongodbflex.GetInstanceResponse, model
|
|||
model.BackupSchedule = types.StringPointerValue(instance.BackupSchedule)
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
instanceId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), instanceId)
|
||||
model.InstanceId = types.StringValue(instanceId)
|
||||
model.Name = types.StringPointerValue(instance.Name)
|
||||
model.ACL = aclList
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
mongodbflexUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/mongodbflex/utils"
|
||||
|
|
@ -193,14 +192,7 @@ func mapDataSourceFields(userResp *mongodbflex.GetUserResponse, model *DataSourc
|
|||
} else {
|
||||
return fmt.Errorf("user id not present")
|
||||
}
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
model.InstanceId.ValueString(),
|
||||
userId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), model.InstanceId.ValueString(), userId)
|
||||
model.UserId = types.StringValue(userId)
|
||||
model.Username = types.StringPointerValue(user.Username)
|
||||
model.Database = types.StringPointerValue(user.Database)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import (
|
|||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
mongodbflexUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/mongodbflex/utils"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
|
||||
|
|
@ -396,14 +398,7 @@ func mapFieldsCreate(userResp *mongodbflex.CreateUserResponse, model *Model) err
|
|||
return fmt.Errorf("user id not present")
|
||||
}
|
||||
userId := *user.Id
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
model.InstanceId.ValueString(),
|
||||
userId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), model.InstanceId.ValueString(), userId)
|
||||
model.UserId = types.StringValue(userId)
|
||||
model.Username = types.StringPointerValue(user.Username)
|
||||
model.Database = types.StringPointerValue(user.Database)
|
||||
|
|
@ -449,14 +444,7 @@ func mapFields(userResp *mongodbflex.GetUserResponse, model *Model) error {
|
|||
} else {
|
||||
return fmt.Errorf("user id not present")
|
||||
}
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
model.InstanceId.ValueString(),
|
||||
userId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), model.InstanceId.ValueString(), userId)
|
||||
model.UserId = types.StringValue(userId)
|
||||
model.Username = types.StringPointerValue(user.Username)
|
||||
model.Database = types.StringPointerValue(user.Database)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -494,8 +494,7 @@ func mapFields(ctx context.Context, alertGroup *observability.AlertGroup, model
|
|||
}
|
||||
|
||||
model.Name = types.StringValue(name)
|
||||
idParts := []string{model.ProjectId.ValueString(), model.InstanceId.ValueString(), name}
|
||||
model.Id = types.StringValue(strings.Join(idParts, core.Separator))
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), model.InstanceId.ValueString(), name)
|
||||
|
||||
var interval string
|
||||
if !utils.IsUndefined(model.Interval) {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
observabilityUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/observability/utils"
|
||||
|
|
@ -165,13 +164,8 @@ func mapFields(r *observability.Credentials, model *Model) error {
|
|||
} else {
|
||||
return fmt.Errorf("username id not present")
|
||||
}
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
model.InstanceId.ValueString(),
|
||||
userName,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
model.Id = utils.BuildInternalTerraformId(
|
||||
model.ProjectId.ValueString(), model.InstanceId.ValueString(), userName,
|
||||
)
|
||||
model.Username = types.StringPointerValue(r.Username)
|
||||
model.Password = types.StringPointerValue(r.Password)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
observabilityUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/observability/utils"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
|
||||
|
|
@ -27,7 +29,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"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/observability"
|
||||
"github.com/stackitcloud/stackit-sdk-go/services/observability/wait"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
|
|
@ -1290,13 +1292,7 @@ func mapFields(ctx context.Context, r *observability.GetInstanceResponse, model
|
|||
return fmt.Errorf("instance id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
instanceId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), instanceId)
|
||||
model.InstanceId = types.StringValue(instanceId)
|
||||
model.PlanName = types.StringPointerValue(r.PlanName)
|
||||
model.PlanId = types.StringPointerValue(r.PlanId)
|
||||
|
|
@ -1573,19 +1569,19 @@ func mapGlobalConfigToAttributes(respGlobalConfigs *observability.Global, global
|
|||
if globalConfigsTF != nil {
|
||||
if respGlobalConfigs.SmtpSmarthost == nil &&
|
||||
!globalConfigsTF.SmtpSmartHost.IsNull() && !globalConfigsTF.SmtpSmartHost.IsUnknown() {
|
||||
smtpSmartHost = utils.Ptr(globalConfigsTF.SmtpSmartHost.ValueString())
|
||||
smtpSmartHost = sdkUtils.Ptr(globalConfigsTF.SmtpSmartHost.ValueString())
|
||||
}
|
||||
if respGlobalConfigs.SmtpAuthIdentity == nil &&
|
||||
!globalConfigsTF.SmtpAuthIdentity.IsNull() && !globalConfigsTF.SmtpAuthIdentity.IsUnknown() {
|
||||
smtpAuthIdentity = utils.Ptr(globalConfigsTF.SmtpAuthIdentity.ValueString())
|
||||
smtpAuthIdentity = sdkUtils.Ptr(globalConfigsTF.SmtpAuthIdentity.ValueString())
|
||||
}
|
||||
if respGlobalConfigs.SmtpAuthPassword == nil &&
|
||||
!globalConfigsTF.SmtpAuthPassword.IsNull() && !globalConfigsTF.SmtpAuthPassword.IsUnknown() {
|
||||
smtpAuthPassword = utils.Ptr(globalConfigsTF.SmtpAuthPassword.ValueString())
|
||||
smtpAuthPassword = sdkUtils.Ptr(globalConfigsTF.SmtpAuthPassword.ValueString())
|
||||
}
|
||||
if respGlobalConfigs.SmtpAuthUsername == nil &&
|
||||
!globalConfigsTF.SmtpAuthUsername.IsNull() && !globalConfigsTF.SmtpAuthUsername.IsUnknown() {
|
||||
smtpAuthUsername = utils.Ptr(globalConfigsTF.SmtpAuthUsername.ValueString())
|
||||
smtpAuthUsername = sdkUtils.Ptr(globalConfigsTF.SmtpAuthUsername.ValueString())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1878,7 +1874,7 @@ func toUpdateMetricsStorageRetentionPayload(retentionDaysRaw, retentionDays5m, r
|
|||
|
||||
func updateACL(ctx context.Context, projectId, instanceId string, acl []string, client *observability.APIClient) error {
|
||||
payload := observability.UpdateACLPayload{
|
||||
Acl: utils.Ptr(acl),
|
||||
Acl: sdkUtils.Ptr(acl),
|
||||
}
|
||||
|
||||
_, err := client.UpdateACL(ctx, instanceId, projectId).UpdateACLPayload(payload).Execute()
|
||||
|
|
|
|||
|
|
@ -494,8 +494,7 @@ func mapFields(ctx context.Context, alertGroup *observability.AlertGroup, model
|
|||
}
|
||||
|
||||
model.Name = types.StringValue(name)
|
||||
idParts := []string{model.ProjectId.ValueString(), model.InstanceId.ValueString(), name}
|
||||
model.Id = types.StringValue(strings.Join(idParts, core.Separator))
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), model.InstanceId.ValueString(), name)
|
||||
|
||||
var interval string
|
||||
if !utils.IsUndefined(model.Interval) {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
observabilityUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/observability/utils"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
|
||||
|
|
@ -28,7 +30,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"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/observability"
|
||||
"github.com/stackitcloud/stackit-sdk-go/services/observability/wait"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
|
|
@ -545,16 +547,8 @@ func mapFields(ctx context.Context, sc *observability.Job, model *Model) error {
|
|||
return fmt.Errorf("scrape config name not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
model.InstanceId.ValueString(),
|
||||
scName,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), model.InstanceId.ValueString(), scName)
|
||||
model.Name = types.StringValue(scName)
|
||||
|
||||
model.MetricsPath = types.StringPointerValue(sc.MetricsPath)
|
||||
model.Scheme = types.StringValue(string(sc.GetScheme()))
|
||||
model.ScrapeInterval = types.StringPointerValue(sc.ScrapeInterval)
|
||||
|
|
@ -694,7 +688,7 @@ func toCreatePayload(ctx context.Context, model *Model, saml2Model *saml2Model,
|
|||
ScrapeInterval: conversion.StringValueToPointer(model.ScrapeInterval),
|
||||
ScrapeTimeout: conversion.StringValueToPointer(model.ScrapeTimeout),
|
||||
// potentially lossy conversion, depending on the allowed range for sample_limit
|
||||
SampleLimit: utils.Ptr(float64(model.SampleLimit.ValueInt64())),
|
||||
SampleLimit: sdkUtils.Ptr(float64(model.SampleLimit.ValueInt64())),
|
||||
Scheme: observability.CreateScrapeConfigPayloadGetSchemeAttributeType(conversion.StringValueToPointer(model.Scheme)),
|
||||
}
|
||||
setDefaultsCreateScrapeConfig(&sc, model, saml2Model)
|
||||
|
|
@ -750,13 +744,13 @@ func setDefaultsCreateScrapeConfig(sc *observability.CreateScrapeConfigPayload,
|
|||
sc.Scheme = DefaultScheme.Ptr()
|
||||
}
|
||||
if model.ScrapeInterval.IsNull() || model.ScrapeInterval.IsUnknown() {
|
||||
sc.ScrapeInterval = utils.Ptr(DefaultScrapeInterval)
|
||||
sc.ScrapeInterval = sdkUtils.Ptr(DefaultScrapeInterval)
|
||||
}
|
||||
if model.ScrapeTimeout.IsNull() || model.ScrapeTimeout.IsUnknown() {
|
||||
sc.ScrapeTimeout = utils.Ptr(DefaultScrapeTimeout)
|
||||
sc.ScrapeTimeout = sdkUtils.Ptr(DefaultScrapeTimeout)
|
||||
}
|
||||
if model.SampleLimit.IsNull() || model.SampleLimit.IsUnknown() {
|
||||
sc.SampleLimit = utils.Ptr(float64(DefaultSampleLimit))
|
||||
sc.SampleLimit = sdkUtils.Ptr(float64(DefaultSampleLimit))
|
||||
}
|
||||
// Make the API default more explicit by setting the field.
|
||||
if saml2Model.EnableURLParameters.IsNull() || saml2Model.EnableURLParameters.IsUnknown() {
|
||||
|
|
@ -783,7 +777,7 @@ func toUpdatePayload(ctx context.Context, model *Model, saml2Model *saml2Model,
|
|||
ScrapeInterval: conversion.StringValueToPointer(model.ScrapeInterval),
|
||||
ScrapeTimeout: conversion.StringValueToPointer(model.ScrapeTimeout),
|
||||
// potentially lossy conversion, depending on the allowed range for sample_limit
|
||||
SampleLimit: utils.Ptr(float64(model.SampleLimit.ValueInt64())),
|
||||
SampleLimit: sdkUtils.Ptr(float64(model.SampleLimit.ValueInt64())),
|
||||
Scheme: observability.UpdateScrapeConfigPayloadGetSchemeAttributeType(conversion.StringValueToPointer(model.Scheme)),
|
||||
}
|
||||
setDefaultsUpdateScrapeConfig(&sc, model)
|
||||
|
|
@ -839,12 +833,12 @@ func setDefaultsUpdateScrapeConfig(sc *observability.UpdateScrapeConfigPayload,
|
|||
sc.Scheme = observability.UpdateScrapeConfigPayloadGetSchemeAttributeType(DefaultScheme.Ptr())
|
||||
}
|
||||
if model.ScrapeInterval.IsNull() || model.ScrapeInterval.IsUnknown() {
|
||||
sc.ScrapeInterval = utils.Ptr(DefaultScrapeInterval)
|
||||
sc.ScrapeInterval = sdkUtils.Ptr(DefaultScrapeInterval)
|
||||
}
|
||||
if model.ScrapeTimeout.IsNull() || model.ScrapeTimeout.IsUnknown() {
|
||||
sc.ScrapeTimeout = utils.Ptr(DefaultScrapeTimeout)
|
||||
sc.ScrapeTimeout = sdkUtils.Ptr(DefaultScrapeTimeout)
|
||||
}
|
||||
if model.SampleLimit.IsNull() || model.SampleLimit.IsUnknown() {
|
||||
sc.SampleLimit = utils.Ptr(float64(DefaultSampleLimit))
|
||||
sc.SampleLimit = sdkUtils.Ptr(float64(DefaultSampleLimit))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -322,13 +322,8 @@ func mapFields(ctx context.Context, credentialsResp *opensearch.CredentialsRespo
|
|||
return fmt.Errorf("credentials id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
model.InstanceId.ValueString(),
|
||||
credentialId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
model.Id = utils.BuildInternalTerraformId(
|
||||
model.ProjectId.ValueString(), model.InstanceId.ValueString(), credentialId,
|
||||
)
|
||||
|
||||
modelHosts, err := utils.ListValuetoStringSlice(model.Hosts)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import (
|
|||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
opensearchUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/opensearch/utils"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
||||
|
|
@ -554,13 +556,7 @@ func mapFields(instance *opensearch.Instance, model *Model) error {
|
|||
return fmt.Errorf("instance id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
instanceId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), instanceId)
|
||||
model.InstanceId = types.StringValue(instanceId)
|
||||
model.PlanId = types.StringPointerValue(instance.PlanId)
|
||||
model.CfGuid = types.StringPointerValue(instance.CfGuid)
|
||||
|
|
|
|||
|
|
@ -364,14 +364,8 @@ func mapFields(databaseResp *postgresflex.InstanceDatabase, model *Model, region
|
|||
} else {
|
||||
return fmt.Errorf("database id not present")
|
||||
}
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
region,
|
||||
model.InstanceId.ValueString(),
|
||||
databaseId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
model.Id = utils.BuildInternalTerraformId(
|
||||
model.ProjectId.ValueString(), region, model.InstanceId.ValueString(), databaseId,
|
||||
)
|
||||
model.DatabaseId = types.StringValue(databaseId)
|
||||
model.Name = types.StringPointerValue(databaseResp.Name)
|
||||
|
|
|
|||
|
|
@ -610,14 +610,7 @@ func mapFields(ctx context.Context, resp *postgresflex.InstanceResponse, model *
|
|||
return fmt.Errorf("creating storage: %w", core.DiagsToError(diags))
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
region,
|
||||
instanceId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), region, instanceId)
|
||||
model.InstanceId = types.StringValue(instanceId)
|
||||
model.Name = types.StringPointerValue(instance.Name)
|
||||
model.ACL = aclList
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
postgresflexUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/postgresflex/utils"
|
||||
|
|
@ -200,14 +199,8 @@ func mapDataSourceFields(userResp *postgresflex.GetUserResponse, model *DataSour
|
|||
} else {
|
||||
return fmt.Errorf("user id not present")
|
||||
}
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
region,
|
||||
model.InstanceId.ValueString(),
|
||||
userId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
model.Id = utils.BuildInternalTerraformId(
|
||||
model.ProjectId.ValueString(), region, model.InstanceId.ValueString(), userId,
|
||||
)
|
||||
model.UserId = types.StringValue(userId)
|
||||
model.Username = types.StringPointerValue(user.Username)
|
||||
|
|
|
|||
|
|
@ -455,14 +455,8 @@ func mapFieldsCreate(userResp *postgresflex.CreateUserResponse, model *Model, re
|
|||
return fmt.Errorf("user id not present")
|
||||
}
|
||||
userId := *user.Id
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
region,
|
||||
model.InstanceId.ValueString(),
|
||||
userId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
model.Id = utils.BuildInternalTerraformId(
|
||||
model.ProjectId.ValueString(), region, model.InstanceId.ValueString(), userId,
|
||||
)
|
||||
model.UserId = types.StringValue(userId)
|
||||
model.Username = types.StringPointerValue(user.Username)
|
||||
|
|
@ -509,14 +503,8 @@ func mapFields(userResp *postgresflex.GetUserResponse, model *Model, region stri
|
|||
} else {
|
||||
return fmt.Errorf("user id not present")
|
||||
}
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
region,
|
||||
model.InstanceId.ValueString(),
|
||||
userId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
model.Id = utils.BuildInternalTerraformId(
|
||||
model.ProjectId.ValueString(), region, model.InstanceId.ValueString(), userId,
|
||||
)
|
||||
model.UserId = types.StringValue(userId)
|
||||
model.Username = types.StringPointerValue(user.Username)
|
||||
|
|
|
|||
|
|
@ -336,13 +336,8 @@ func mapFields(ctx context.Context, credentialsResp *rabbitmq.CredentialsRespons
|
|||
return fmt.Errorf("credentials id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
model.InstanceId.ValueString(),
|
||||
credentialId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
model.Id = utils.BuildInternalTerraformId(
|
||||
model.ProjectId.ValueString(), model.InstanceId.ValueString(), credentialId,
|
||||
)
|
||||
model.CredentialId = types.StringValue(credentialId)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import (
|
|||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
rabbitmqUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/rabbitmq/utils"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
||||
|
|
@ -550,13 +552,7 @@ func mapFields(instance *rabbitmq.Instance, model *Model) error {
|
|||
return fmt.Errorf("instance id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
instanceId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), instanceId)
|
||||
model.InstanceId = types.StringValue(instanceId)
|
||||
model.PlanId = types.StringPointerValue(instance.PlanId)
|
||||
model.CfGuid = types.StringPointerValue(instance.CfGuid)
|
||||
|
|
|
|||
|
|
@ -324,14 +324,7 @@ func mapFields(ctx context.Context, credentialsResp *redis.CredentialsResponse,
|
|||
return fmt.Errorf("credentials id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
model.InstanceId.ValueString(),
|
||||
credentialId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), model.InstanceId.ValueString(), credentialId)
|
||||
|
||||
modelHosts, err := utils.ListValuetoStringSlice(model.Hosts)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import (
|
|||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
redisUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/redis/utils"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
||||
|
|
@ -621,13 +623,7 @@ func mapFields(instance *redis.Instance, model *Model) error {
|
|||
return fmt.Errorf("instance id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
instanceId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), instanceId)
|
||||
model.InstanceId = types.StringValue(instanceId)
|
||||
model.PlanId = types.StringPointerValue(instance.PlanId)
|
||||
model.CfGuid = types.StringPointerValue(instance.CfGuid)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import (
|
|||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
secretsmanagerUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/secretsmanager/utils"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
|
||||
|
|
@ -24,7 +26,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/secretsmanager"
|
||||
)
|
||||
|
||||
|
|
@ -361,13 +363,7 @@ func mapFields(instance *secretsmanager.Instance, aclList *secretsmanager.ListAC
|
|||
return fmt.Errorf("instance id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
instanceId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), instanceId)
|
||||
model.InstanceId = types.StringValue(instanceId)
|
||||
model.Name = types.StringPointerValue(instance.Name)
|
||||
|
||||
|
|
@ -441,7 +437,7 @@ func updateACLs(ctx context.Context, projectId, instanceId string, acls []string
|
|||
for cidr, state := range aclsState {
|
||||
if state.isInModel && !state.isCreated {
|
||||
payload := secretsmanager.CreateACLPayload{
|
||||
Cidr: utils.Ptr(cidr),
|
||||
Cidr: sdkUtils.Ptr(cidr),
|
||||
}
|
||||
_, err := client.CreateACL(ctx, projectId, instanceId).CreateACLPayload(payload).Execute()
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
secretsmanagerUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/secretsmanager/utils"
|
||||
|
|
@ -190,14 +189,7 @@ func mapDataSourceFields(user *secretsmanager.User, model *DataSourceModel) erro
|
|||
return fmt.Errorf("user id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
model.InstanceId.ValueString(),
|
||||
userId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), model.InstanceId.ValueString(), userId)
|
||||
model.UserId = types.StringValue(userId)
|
||||
model.Description = types.StringPointerValue(user.Description)
|
||||
model.WriteEnabled = types.BoolPointerValue(user.Write)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import (
|
|||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
secretsmanagerUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/secretsmanager/utils"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
|
||||
|
|
@ -378,14 +380,7 @@ func mapFields(user *secretsmanager.User, model *Model) error {
|
|||
return fmt.Errorf("user id not present")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
model.InstanceId.ValueString(),
|
||||
userId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), model.InstanceId.ValueString(), userId)
|
||||
model.UserId = types.StringValue(userId)
|
||||
model.Description = types.StringPointerValue(user.Description)
|
||||
model.WriteEnabled = types.BoolPointerValue(user.Write)
|
||||
|
|
|
|||
|
|
@ -444,14 +444,9 @@ func mapFields(ctx context.Context, schedule *serverbackup.BackupSchedule, model
|
|||
}
|
||||
|
||||
model.BackupScheduleId = types.Int64PointerValue(schedule.Id)
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
region,
|
||||
model.ServerId.ValueString(),
|
||||
model.ID = utils.BuildInternalTerraformId(
|
||||
model.ProjectId.ValueString(), region, model.ServerId.ValueString(),
|
||||
strconv.FormatInt(model.BackupScheduleId.ValueInt64(), 10),
|
||||
}
|
||||
model.ID = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Name = types.StringPointerValue(schedule.Name)
|
||||
model.Rrule = types.StringPointerValue(schedule.Rrule)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
serverbackupUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/serverbackup/utils"
|
||||
|
|
@ -223,10 +222,7 @@ func mapSchedulesDatasourceFields(ctx context.Context, schedules *serverbackup.G
|
|||
projectId := model.ProjectId.ValueString()
|
||||
serverId := model.ServerId.ValueString()
|
||||
|
||||
idParts := []string{projectId, region, serverId}
|
||||
model.ID = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.ID = utils.BuildInternalTerraformId(projectId, region, serverId)
|
||||
model.Region = types.StringValue(region)
|
||||
|
||||
for _, schedule := range *schedules.Items {
|
||||
|
|
|
|||
|
|
@ -415,14 +415,9 @@ func mapFields(schedule *serverupdate.UpdateSchedule, model *Model, region strin
|
|||
}
|
||||
|
||||
model.UpdateScheduleId = types.Int64PointerValue(schedule.Id)
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
region,
|
||||
model.ServerId.ValueString(),
|
||||
model.ID = utils.BuildInternalTerraformId(
|
||||
model.ProjectId.ValueString(), region, model.ServerId.ValueString(),
|
||||
strconv.FormatInt(model.UpdateScheduleId.ValueInt64(), 10),
|
||||
}
|
||||
model.ID = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Name = types.StringPointerValue(schedule.Name)
|
||||
model.Rrule = types.StringPointerValue(schedule.Rrule)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
serverupdateUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/serverupdate/utils"
|
||||
|
|
@ -209,10 +208,7 @@ func mapSchedulesDatasourceFields(ctx context.Context, schedules *serverupdate.G
|
|||
projectId := model.ProjectId.ValueString()
|
||||
serverId := model.ServerId.ValueString()
|
||||
|
||||
idParts := []string{projectId, region, serverId}
|
||||
model.ID = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.ID = utils.BuildInternalTerraformId(projectId, region, serverId)
|
||||
model.Region = types.StringValue(region)
|
||||
|
||||
for _, schedule := range *schedules.Items {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
serviceaccountUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/serviceaccount/utils"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
||||
|
|
@ -301,8 +303,7 @@ func mapFields(resp *serviceaccount.ServiceAccount, model *Model) error {
|
|||
}
|
||||
|
||||
// Build the ID by combining the project ID and email and assign the model's fields.
|
||||
idParts := []string{model.ProjectId.ValueString(), *resp.Email}
|
||||
model.Id = types.StringValue(strings.Join(idParts, core.Separator))
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), *resp.Email)
|
||||
model.Email = types.StringPointerValue(resp.Email)
|
||||
model.ProjectId = types.StringPointerValue(resp.ProjectId)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
serviceaccountUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/serviceaccount/utils"
|
||||
|
|
@ -325,8 +324,7 @@ func mapCreateResponse(resp *serviceaccount.CreateServiceAccountKeyResponse, mod
|
|||
return fmt.Errorf("service account key id not present")
|
||||
}
|
||||
|
||||
idParts := []string{model.ProjectId.ValueString(), model.ServiceAccountEmail.ValueString(), *resp.Id}
|
||||
model.Id = types.StringValue(strings.Join(idParts, core.Separator))
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), model.ServiceAccountEmail.ValueString(), *resp.Id)
|
||||
model.KeyId = types.StringPointerValue(resp.Id)
|
||||
|
||||
jsonData, err := json.Marshal(resp)
|
||||
|
|
|
|||
|
|
@ -5,9 +5,10 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
serviceaccountUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/serviceaccount/utils"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
|
||||
|
|
@ -344,8 +345,7 @@ func mapCreateResponse(resp *serviceaccount.AccessToken, model *Model) error {
|
|||
validUntil = types.StringValue(validUntilValue.Format(time.RFC3339))
|
||||
}
|
||||
|
||||
idParts := []string{model.ProjectId.ValueString(), model.ServiceAccountEmail.ValueString(), *resp.Id}
|
||||
model.Id = types.StringValue(strings.Join(idParts, core.Separator))
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), model.ServiceAccountEmail.ValueString(), *resp.Id)
|
||||
model.AccessTokenId = types.StringPointerValue(resp.Id)
|
||||
model.Token = types.StringPointerValue(resp.Token)
|
||||
model.Active = types.BoolPointerValue(resp.Active)
|
||||
|
|
@ -379,8 +379,7 @@ func mapListResponse(resp *serviceaccount.AccessTokenMetadata, model *Model) err
|
|||
validUntil = types.StringValue(validUntilValue.Format(time.RFC3339))
|
||||
}
|
||||
|
||||
idParts := []string{model.ProjectId.ValueString(), model.ServiceAccountEmail.ValueString(), *resp.Id}
|
||||
model.Id = types.StringValue(strings.Join(idParts, core.Separator))
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), model.ServiceAccountEmail.ValueString(), *resp.Id)
|
||||
model.AccessTokenId = types.StringPointerValue(resp.Id)
|
||||
model.CreatedAt = createdAt
|
||||
model.ValidUntil = validUntil
|
||||
|
|
|
|||
|
|
@ -1360,14 +1360,8 @@ func mapFields(ctx context.Context, cl *ske.Cluster, m *Model, region string) er
|
|||
return fmt.Errorf("name not present")
|
||||
}
|
||||
m.Name = types.StringValue(name)
|
||||
idParts := []string{
|
||||
m.ProjectId.ValueString(),
|
||||
region,
|
||||
name,
|
||||
}
|
||||
m.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
|
||||
m.Id = utils.BuildInternalTerraformId(m.ProjectId.ValueString(), region, name)
|
||||
m.Region = types.StringValue(region)
|
||||
|
||||
if cl.Kubernetes != nil {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
skeUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/ske/utils"
|
||||
|
|
@ -348,13 +347,8 @@ func mapFields(kubeconfigResp *ske.Kubeconfig, model *Model, creationTime time.T
|
|||
return fmt.Errorf("model input is nil")
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
model.ClusterName.ValueString(),
|
||||
model.KubeconfigId.ValueString(),
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
model.Id = utils.BuildInternalTerraformId(
|
||||
model.ProjectId.ValueString(), model.ClusterName.ValueString(), model.KubeconfigId.ValueString(),
|
||||
)
|
||||
|
||||
if kubeconfigResp.Kubeconfig == nil {
|
||||
|
|
|
|||
|
|
@ -754,14 +754,7 @@ func mapFields(ctx context.Context, resp *sqlserverflex.GetInstanceResponse, mod
|
|||
model.BackupSchedule = types.StringPointerValue(instance.BackupSchedule)
|
||||
}
|
||||
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
region,
|
||||
instanceId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), region, instanceId)
|
||||
model.InstanceId = types.StringValue(instanceId)
|
||||
model.Name = types.StringPointerValue(instance.Name)
|
||||
model.ACL = aclList
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
sqlserverflexUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/sqlserverflex/utils"
|
||||
|
|
@ -205,14 +204,8 @@ func mapDataSourceFields(userResp *sqlserverflex.GetUserResponse, model *DataSou
|
|||
} else {
|
||||
return fmt.Errorf("user id not present")
|
||||
}
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
region,
|
||||
model.InstanceId.ValueString(),
|
||||
userId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
model.Id = utils.BuildInternalTerraformId(
|
||||
model.ProjectId.ValueString(), region, model.InstanceId.ValueString(), userId,
|
||||
)
|
||||
model.UserId = types.StringValue(userId)
|
||||
model.Username = types.StringPointerValue(user.Username)
|
||||
|
|
|
|||
|
|
@ -380,15 +380,7 @@ func mapFieldsCreate(userResp *sqlserverflex.CreateUserResponse, model *Model, r
|
|||
return fmt.Errorf("user id not present")
|
||||
}
|
||||
userId := *user.Id
|
||||
idParts := []string{
|
||||
model.ProjectId.ValueString(),
|
||||
region,
|
||||
model.InstanceId.ValueString(),
|
||||
userId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), region, model.InstanceId.ValueString(), userId)
|
||||
model.UserId = types.StringValue(userId)
|
||||
model.Username = types.StringPointerValue(user.Username)
|
||||
|
||||
|
|
@ -436,14 +428,11 @@ func mapFields(userResp *sqlserverflex.GetUserResponse, model *Model, region str
|
|||
} else {
|
||||
return fmt.Errorf("user id not present")
|
||||
}
|
||||
idParts := []string{
|
||||
model.Id = utils.BuildInternalTerraformId(
|
||||
model.ProjectId.ValueString(),
|
||||
region,
|
||||
model.InstanceId.ValueString(),
|
||||
userId,
|
||||
}
|
||||
model.Id = types.StringValue(
|
||||
strings.Join(idParts, core.Separator),
|
||||
)
|
||||
model.UserId = types.StringValue(userId)
|
||||
model.Username = types.StringPointerValue(user.Username)
|
||||
|
|
|
|||
|
|
@ -153,3 +153,7 @@ func FormatPossibleValues(values []string) string {
|
|||
}
|
||||
return fmt.Sprintf("Possible values are: %s.", strings.Join(formattedValues, ", "))
|
||||
}
|
||||
|
||||
func BuildInternalTerraformId(idParts ...string) types.String {
|
||||
return types.StringValue(strings.Join(idParts, core.Separator))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package utils
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
|
@ -344,3 +345,36 @@ func TestIsUndefined(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildInternalTerraformId(t *testing.T) {
|
||||
type args struct {
|
||||
idParts []string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want types.String
|
||||
}{
|
||||
{
|
||||
name: "no id parts",
|
||||
args: args{
|
||||
idParts: []string{},
|
||||
},
|
||||
want: types.StringValue(""),
|
||||
},
|
||||
{
|
||||
name: "multiple id parts",
|
||||
args: args{
|
||||
idParts: []string{"abc", "foo", "bar", "xyz"},
|
||||
},
|
||||
want: types.StringValue("abc,foo,bar,xyz"),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := BuildInternalTerraformId(tt.args.idParts...); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("BuildInternalTerraformId() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue