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 (
|
|||
"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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue