From 62ab6fe1d3919882379f1476bbe1316814b5de33 Mon Sep 17 00:00:00 2001 From: Carlo Goetz Date: Thu, 26 Mar 2026 10:34:22 +0100 Subject: [PATCH 1/2] feat(alb) migrate to versioned sdk STACKITTPR-533 --- go.mod | 2 +- go.sum | 2 + stackit/internal/conversion/conversion.go | 25 +++ .../internal/conversion/conversion_test.go | 56 +++++ stackit/internal/services/alb/alb_acc_test.go | 20 +- .../alb/applicationloadbalancer/datasource.go | 19 +- .../alb/applicationloadbalancer/resource.go | 195 +++++++++--------- .../applicationloadbalancer/resource_test.go | 169 +++++++-------- stackit/internal/services/alb/utils/util.go | 2 +- .../internal/services/alb/utils/util_test.go | 2 +- 10 files changed, 289 insertions(+), 203 deletions(-) diff --git a/go.mod b/go.mod index e7f626846..32f15e7b9 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/hashicorp/terraform-plugin-log v0.10.0 github.com/hashicorp/terraform-plugin-testing v1.14.0 github.com/stackitcloud/stackit-sdk-go/core v0.23.0 - github.com/stackitcloud/stackit-sdk-go/services/alb v0.9.3 + github.com/stackitcloud/stackit-sdk-go/services/alb v0.12.1 github.com/stackitcloud/stackit-sdk-go/services/cdn v1.13.0 github.com/stackitcloud/stackit-sdk-go/services/dns v0.19.1 github.com/stackitcloud/stackit-sdk-go/services/edge v0.7.0 diff --git a/go.sum b/go.sum index 976240e19..5dfdc9ecc 100644 --- a/go.sum +++ b/go.sum @@ -155,6 +155,8 @@ github.com/stackitcloud/stackit-sdk-go/core v0.23.0 h1:zPrOhf3Xe47rKRs1fg/AqKYUi github.com/stackitcloud/stackit-sdk-go/core v0.23.0/go.mod h1:osMglDby4csGZ5sIfhNyYq1bS1TxIdPY88+skE/kkmI= github.com/stackitcloud/stackit-sdk-go/services/alb v0.9.3 h1:X82TZfc6lg8ZoYdckiv5+OsV0d+81Q2TFMJh1TfxGWk= github.com/stackitcloud/stackit-sdk-go/services/alb v0.9.3/go.mod h1:V6+MolxM/M2FWyWZA+FRFKEzzUe10MU9eEVfMvxHGi8= +github.com/stackitcloud/stackit-sdk-go/services/alb v0.12.1 h1:RKaxAymxlyxxE0Gta3yRuQWf07LnlcX+mfGnVB96NHA= +github.com/stackitcloud/stackit-sdk-go/services/alb v0.12.1/go.mod h1:FHkV5L9vCQha+5MX+NdMdYjQIHXcLr95+bu1FN91QOM= github.com/stackitcloud/stackit-sdk-go/services/authorization v0.12.0 h1:HxPgBu04j5tj6nfZ2r0l6v4VXC0/tYOGe4sA5Addra8= github.com/stackitcloud/stackit-sdk-go/services/authorization v0.12.0/go.mod h1:uYI9pHAA2g84jJN25ejFUxa0/JtfpPZqMDkctQ1BzJk= github.com/stackitcloud/stackit-sdk-go/services/cdn v1.13.0 h1:iRJK2d3I2QqWp8hqhxlkCtQDNb7fwKHkik9ogmcx2o8= diff --git a/stackit/internal/conversion/conversion.go b/stackit/internal/conversion/conversion.go index e6721ac17..7dea0d14f 100644 --- a/stackit/internal/conversion/conversion.go +++ b/stackit/internal/conversion/conversion.go @@ -173,6 +173,31 @@ func StringSetToPointer(set basetypes.SetValue) (*[]string, error) { return &result, nil } +// StringSetToSlice converts basetypes.SetValue to a slice of strings. +// It returns nil if the value is null or unknown. +// Note: It sorts the resulting slice to ensure deterministic behavior. +func StringSetToSlice(set basetypes.SetValue) ([]string, error) { + if set.IsNull() || set.IsUnknown() { + return nil, nil + } + elements := set.Elements() + result := make([]string, 0, len(elements)) + + for i, el := range elements { + elStr, ok := el.(types.String) + if !ok { + return nil, fmt.Errorf("element %d in set is not a string (type: %T)", i, el) + } + result = append(result, elStr.ValueString()) + } + + // Because Sets are unordered in Terraform, we sort here to + // prevent non-deterministic behavior in the provider logic or API calls. + sort.Strings(result) + + return result, nil +} + // ToJSONMApPartialUpdatePayload returns a map[string]interface{} to be used in a PATCH request payload. // It takes a current map as it is in the terraform state and a desired map as it is in the user configuratiom // and builds a map which sets to null keys that should be removed, updates the values of existing keys and adds new keys diff --git a/stackit/internal/conversion/conversion_test.go b/stackit/internal/conversion/conversion_test.go index 3bfb042c5..91ecf2d22 100644 --- a/stackit/internal/conversion/conversion_test.go +++ b/stackit/internal/conversion/conversion_test.go @@ -393,3 +393,59 @@ func TestParseEphemeralProviderData(t *testing.T) { }) } } + +func TestStringSetToSlice(t *testing.T) { + t.Parallel() + tests := []struct { + name string + in basetypes.SetValue + want []string + wantErr bool + }{ + { + name: "unknown", + in: basetypes.NewSetUnknown(types.StringType), + want: nil, + }, + { + name: "null", + in: basetypes.NewSetNull(types.StringType), + want: nil, + }, + { + name: "invalid type", + in: basetypes.NewSetValueMust(types.Int64Type, []attr.Value{types.Int64Value(123)}), + wantErr: true, + }, + { + name: "some values, sorting", + in: basetypes.NewSetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("xyz"), + types.StringValue("abc"), + }, + ), + want: []string{ + "abc", + "xyz", + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got, err := StringSetToSlice(tt.in) + if tt.wantErr && err == nil { + t.Fatal("expected error") + } + if !tt.wantErr && err != nil { + t.Fatalf("expected no error, got: %v", err) + } + if d := cmp.Diff(got, tt.want); d != "" { + t.Fatalf("no match, diff: %s", d) + } + }) + } +} diff --git a/stackit/internal/services/alb/alb_acc_test.go b/stackit/internal/services/alb/alb_acc_test.go index 27a04c41e..80d9e40a2 100644 --- a/stackit/internal/services/alb/alb_acc_test.go +++ b/stackit/internal/services/alb/alb_acc_test.go @@ -12,12 +12,12 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/stackitcloud/stackit-sdk-go/services/alb/wait" + "github.com/stackitcloud/stackit-sdk-go/services/alb/v2api/wait" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" stackitSdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" "github.com/stackitcloud/stackit-sdk-go/core/utils" - "github.com/stackitcloud/stackit-sdk-go/services/alb" + albSdk "github.com/stackitcloud/stackit-sdk-go/services/alb/v2api" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/testutil" ) @@ -621,12 +621,12 @@ func TestAccALBResourceMax(t *testing.T) { func testAccCheckALBDestroy(s *terraform.State) error { ctx := context.Background() - var client *alb.APIClient + var client *albSdk.APIClient var err error if testutil.ALBCustomEndpoint == "" { - client, err = alb.NewAPIClient() + client, err = albSdk.NewAPIClient() } else { - client, err = alb.NewAPIClient( + client, err = albSdk.NewAPIClient( stackitSdkConfig.WithEndpoint(testutil.ALBCustomEndpoint), ) } @@ -648,27 +648,27 @@ func testAccCheckALBDestroy(s *terraform.State) error { loadbalancersToDestroy = append(loadbalancersToDestroy, loadbalancerName) } - loadbalancersResp, err := client.ListLoadBalancers(ctx, testutil.ProjectId, region).Execute() + loadbalancersResp, err := client.DefaultAPI.ListLoadBalancers(ctx, testutil.ProjectId, region).Execute() if err != nil { return fmt.Errorf("getting loadbalancersResp: %w", err) } - if loadbalancersResp.LoadBalancers == nil || (loadbalancersResp.LoadBalancers != nil && len(*loadbalancersResp.LoadBalancers) == 0) { + if loadbalancersResp.LoadBalancers == nil || (loadbalancersResp.LoadBalancers != nil && len(loadbalancersResp.LoadBalancers) == 0) { fmt.Print("No load balancers found for project \n") return nil } - items := *loadbalancersResp.LoadBalancers + items := loadbalancersResp.LoadBalancers for i := range items { if items[i].Name == nil { continue } if utils.Contains(loadbalancersToDestroy, *items[i].Name) { - _, err := client.DeleteLoadBalancerExecute(ctx, testutil.ProjectId, region, *items[i].Name) + _, err := client.DefaultAPI.DeleteLoadBalancer(ctx, testutil.ProjectId, region, *items[i].Name).Execute() if err != nil { return fmt.Errorf("destroying load balancer %s during CheckDestroy: %w", *items[i].Name, err) } - _, err = wait.DeleteLoadbalancerWaitHandler(ctx, client, testutil.ProjectId, region, *items[i].Name).WaitWithContext(ctx) + _, err = wait.DeleteLoadbalancerWaitHandler(ctx, client.DefaultAPI, testutil.ProjectId, region, *items[i].Name).WaitWithContext(ctx) if err != nil { return fmt.Errorf("destroying load balancer %s during CheckDestroy: waiting for deletion %w", *items[i].Name, err) } diff --git a/stackit/internal/services/alb/applicationloadbalancer/datasource.go b/stackit/internal/services/alb/applicationloadbalancer/datasource.go index 944e4fe71..f2df501c5 100644 --- a/stackit/internal/services/alb/applicationloadbalancer/datasource.go +++ b/stackit/internal/services/alb/applicationloadbalancer/datasource.go @@ -13,7 +13,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" - albSdk "github.com/stackitcloud/stackit-sdk-go/services/alb" + legacyAlb "github.com/stackitcloud/stackit-sdk-go/services/alb" + albSdk "github.com/stackitcloud/stackit-sdk-go/services/alb/v2api" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils" ) @@ -57,9 +58,9 @@ func (r *albDataSource) Configure(ctx context.Context, req datasource.ConfigureR // Schema defines the schema for the resource. func (r *albDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { - protocolOptions := sdkUtils.EnumSliceToStringSlice(albSdk.AllowedListenerProtocolEnumValues) - roleOptions := sdkUtils.EnumSliceToStringSlice(albSdk.AllowedNetworkRoleEnumValues) - errorOptions := sdkUtils.EnumSliceToStringSlice(albSdk.AllowedLoadBalancerErrorTypesEnumValues) + protocolOptions := sdkUtils.EnumSliceToStringSlice(legacyAlb.AllowedListenerProtocolEnumValues) + roleOptions := sdkUtils.EnumSliceToStringSlice(legacyAlb.AllowedNetworkRoleEnumValues) + errorOptions := sdkUtils.EnumSliceToStringSlice(legacyAlb.AllowedLoadBalancerErrorTypesEnumValues) descriptions := map[string]string{ "main": "Application Load Balancer resource schema.", @@ -201,7 +202,7 @@ func (r *albDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, re Description: descriptions["listeners.name"], Computed: true, }, - "port": schema.Int64Attribute{ + "port": schema.Int32Attribute{ Description: descriptions["port"], Computed: true, }, @@ -433,7 +434,7 @@ func (r *albDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, re Description: descriptions["active_health_check"], Computed: true, Attributes: map[string]schema.Attribute{ - "healthy_threshold": schema.Int64Attribute{ + "healthy_threshold": schema.Int32Attribute{ Description: descriptions["healthy_threshold"], Computed: true, }, @@ -449,7 +450,7 @@ func (r *albDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, re Description: descriptions["timeout"], Computed: true, }, - "unhealthy_threshold": schema.Int64Attribute{ + "unhealthy_threshold": schema.Int32Attribute{ Description: descriptions["unhealthy_threshold"], Computed: true, }, @@ -474,7 +475,7 @@ func (r *albDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, re Description: descriptions["target_pools.name"], Computed: true, }, - "target_port": schema.Int64Attribute{ + "target_port": schema.Int32Attribute{ Description: descriptions["target_port"], Computed: true, }, @@ -555,7 +556,7 @@ func (r *albDataSource) Read(ctx context.Context, req datasource.ReadRequest, re ctx = tflog.SetField(ctx, "name", name) ctx = tflog.SetField(ctx, "region", region) - albResp, err := r.client.GetLoadBalancer(ctx, projectId, region, name).Execute() + albResp, err := r.client.DefaultAPI.GetLoadBalancer(ctx, projectId, region, name).Execute() if err != nil { utils.LogError( ctx, diff --git a/stackit/internal/services/alb/applicationloadbalancer/resource.go b/stackit/internal/services/alb/applicationloadbalancer/resource.go index eb9b647a0..523ba88b1 100644 --- a/stackit/internal/services/alb/applicationloadbalancer/resource.go +++ b/stackit/internal/services/alb/applicationloadbalancer/resource.go @@ -11,7 +11,7 @@ import ( "time" "github.com/hashicorp/terraform-plugin-framework-validators/boolvalidator" - "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" + "github.com/hashicorp/terraform-plugin-framework-validators/int32validator" "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "github.com/hashicorp/terraform-plugin-framework-validators/mapvalidator" "github.com/hashicorp/terraform-plugin-framework-validators/setvalidator" @@ -32,8 +32,9 @@ import ( "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/stackitcloud/stackit-sdk-go/core/oapierror" sdkUtils "github.com/stackitcloud/stackit-sdk-go/core/utils" - albSdk "github.com/stackitcloud/stackit-sdk-go/services/alb" - "github.com/stackitcloud/stackit-sdk-go/services/alb/wait" + legacyAlb "github.com/stackitcloud/stackit-sdk-go/services/alb" + albSdk "github.com/stackitcloud/stackit-sdk-go/services/alb/v2api" + "github.com/stackitcloud/stackit-sdk-go/services/alb/v2api/wait" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" albUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/alb/utils" @@ -87,7 +88,7 @@ var targetSecurityGroupType = map[string]attr.Type{ // Struct corresponding to Model.Listeners[i] type listener struct { Name types.String `tfsdk:"name"` - Port types.Int64 `tfsdk:"port"` + Port types.Int32 `tfsdk:"port"` Protocol types.String `tfsdk:"protocol"` Http types.Object `tfsdk:"http"` Https types.Object `tfsdk:"https"` @@ -97,7 +98,7 @@ type listener struct { // Types corresponding to listener var listenerTypes = map[string]attr.Type{ "name": types.StringType, - "port": types.Int64Type, + "port": types.Int32Type, "protocol": types.StringType, "http": types.ObjectType{AttrTypes: httpTypes}, "https": types.ObjectType{AttrTypes: httpsTypes}, @@ -256,7 +257,7 @@ var observabilityOptionTypes = map[string]attr.Type{ type targetPool struct { ActiveHealthCheck types.Object `tfsdk:"active_health_check"` Name types.String `tfsdk:"name"` - TargetPort types.Int64 `tfsdk:"target_port"` + TargetPort types.Int32 `tfsdk:"target_port"` Targets types.Set `tfsdk:"targets"` TLSConfig types.Object `tfsdk:"tls_config"` } @@ -265,29 +266,29 @@ type targetPool struct { var targetPoolTypes = map[string]attr.Type{ "active_health_check": types.ObjectType{AttrTypes: activeHealthCheckTypes}, "name": types.StringType, - "target_port": types.Int64Type, + "target_port": types.Int32Type, "targets": types.SetType{ElemType: types.ObjectType{AttrTypes: targetTypes}}, "tls_config": types.ObjectType{AttrTypes: tlsConfigTypes}, } // Struct corresponding to targetPool.ActiveHealthCheck type activeHealthCheck struct { - HealthyThreshold types.Int64 `tfsdk:"healthy_threshold"` + HealthyThreshold types.Int32 `tfsdk:"healthy_threshold"` HttpHealthChecks types.Object `tfsdk:"http_health_checks"` Interval types.String `tfsdk:"interval"` IntervalJitter types.String `tfsdk:"interval_jitter"` Timeout types.String `tfsdk:"timeout"` - UnhealthyThreshold types.Int64 `tfsdk:"unhealthy_threshold"` + UnhealthyThreshold types.Int32 `tfsdk:"unhealthy_threshold"` } // Types corresponding to activeHealthCheck var activeHealthCheckTypes = map[string]attr.Type{ - "healthy_threshold": types.Int64Type, + "healthy_threshold": types.Int32Type, "http_health_checks": types.ObjectType{AttrTypes: httpHealthChecksTypes}, "interval": types.StringType, "interval_jitter": types.StringType, "timeout": types.StringType, - "unhealthy_threshold": types.Int64Type, + "unhealthy_threshold": types.Int32Type, } type httpHealthChecks struct { @@ -388,9 +389,9 @@ func (r *applicationLoadBalancerResource) Configure(ctx context.Context, req res // Schema defines the schema for the resource. func (r *applicationLoadBalancerResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { - protocolOptions := sdkUtils.EnumSliceToStringSlice(albSdk.AllowedListenerProtocolEnumValues) - roleOptions := sdkUtils.EnumSliceToStringSlice(albSdk.AllowedNetworkRoleEnumValues) - errorOptions := sdkUtils.EnumSliceToStringSlice(albSdk.AllowedLoadBalancerErrorTypesEnumValues) + protocolOptions := sdkUtils.EnumSliceToStringSlice(legacyAlb.AllowedListenerProtocolEnumValues) + roleOptions := sdkUtils.EnumSliceToStringSlice(legacyAlb.AllowedNetworkRoleEnumValues) + errorOptions := sdkUtils.EnumSliceToStringSlice(legacyAlb.AllowedLoadBalancerErrorTypesEnumValues) descriptions := map[string]string{ "main": "Application Load Balancer resource schema.", @@ -588,11 +589,11 @@ The example below creates the supporting infrastructure using the STACKIT Terraf ), }, }, - "port": schema.Int64Attribute{ + "port": schema.Int32Attribute{ Description: descriptions["port"], Required: true, - Validators: []validator.Int64{ - int64validator.Between(1, 65535), + Validators: []validator.Int32{ + int32validator.Between(1, 65535), }, }, "protocol": schema.StringAttribute{ @@ -965,11 +966,11 @@ The example below creates the supporting infrastructure using the STACKIT Terraf Description: descriptions["active_health_check"], Optional: true, Attributes: map[string]schema.Attribute{ - "healthy_threshold": schema.Int64Attribute{ + "healthy_threshold": schema.Int32Attribute{ Description: descriptions["healthy_threshold"], Required: true, - Validators: []validator.Int64{ - int64validator.Between(1, 999), + Validators: []validator.Int32{ + int32validator.Between(1, 999), }, }, "interval": schema.StringAttribute{ @@ -1002,11 +1003,11 @@ The example below creates the supporting infrastructure using the STACKIT Terraf ), }, }, - "unhealthy_threshold": schema.Int64Attribute{ + "unhealthy_threshold": schema.Int32Attribute{ Description: descriptions["unhealthy_threshold"], Required: true, - Validators: []validator.Int64{ - int64validator.Between(1, 999), + Validators: []validator.Int32{ + int32validator.Between(1, 999), }, }, "http_health_checks": schema.SingleNestedAttribute{ @@ -1048,10 +1049,10 @@ The example below creates the supporting infrastructure using the STACKIT Terraf ), }, }, - "target_port": schema.Int64Attribute{ + "target_port": schema.Int32Attribute{ Description: descriptions["target_port"], Required: true, - Validators: []validator.Int64{int64validator.Between(1, 65535)}, + Validators: []validator.Int32{int32validator.Between(1, 65535)}, }, "targets": schema.SetNestedAttribute{ Description: descriptions["targets"], @@ -1164,7 +1165,7 @@ func (r *applicationLoadBalancerResource) Create(ctx context.Context, req resour } // Create a new Application Load Balancer - createResp, err := r.client.CreateLoadBalancer(ctx, projectId, region).CreateLoadBalancerPayload(*payload).Execute() + createResp, err := r.client.DefaultAPI.CreateLoadBalancer(ctx, projectId, region).CreateLoadBalancerPayload(*payload).Execute() if err != nil { errStr := utils.PrettyApiErr(ctx, &resp.Diagnostics, err) core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating Application Load Balancer", fmt.Sprintf("Calling API for create: %v", errStr)) @@ -1182,7 +1183,7 @@ func (r *applicationLoadBalancerResource) Create(ctx context.Context, req resour return } - waitResp, err := wait.CreateOrUpdateLoadbalancerWaitHandler(ctx, r.client, projectId, region, *createResp.Name).SetTimeout(90 * time.Minute).WaitWithContext(ctx) + waitResp, err := wait.CreateOrUpdateLoadbalancerWaitHandler(ctx, r.client.DefaultAPI, projectId, region, *createResp.Name).SetTimeout(90 * time.Minute).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating Application Load Balancer", fmt.Sprintf("Application Load Balancer creation waiting: %v", err)) return @@ -1221,7 +1222,7 @@ func (r *applicationLoadBalancerResource) Read(ctx context.Context, req resource ctx = tflog.SetField(ctx, "name", name) ctx = tflog.SetField(ctx, "region", region) - lbResp, err := r.client.GetLoadBalancer(ctx, projectId, region, name).Execute() + lbResp, err := r.client.DefaultAPI.GetLoadBalancer(ctx, projectId, region, name).Execute() if err != nil { var oapiErr *oapierror.GenericOpenAPIError if errors.As(err, &oapiErr) { @@ -1289,7 +1290,7 @@ func (r *applicationLoadBalancerResource) Update(ctx context.Context, req resour } // Update target pool - updateResp, err := r.client.UpdateLoadBalancer(ctx, projectId, region, name).UpdateLoadBalancerPayload(*payload).Execute() + updateResp, err := r.client.DefaultAPI.UpdateLoadBalancer(ctx, projectId, region, name).UpdateLoadBalancerPayload(*payload).Execute() if err != nil { errStr := utils.PrettyApiErr(ctx, &resp.Diagnostics, err) core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating Application Load Balancer", fmt.Sprintf("Calling API for update: %v", errStr)) @@ -1298,7 +1299,7 @@ func (r *applicationLoadBalancerResource) Update(ctx context.Context, req resour ctx = core.LogResponse(ctx) - waitResp, err := wait.CreateOrUpdateLoadbalancerWaitHandler(ctx, r.client, projectId, region, *updateResp.Name).SetTimeout(90 * time.Minute).WaitWithContext(ctx) + waitResp, err := wait.CreateOrUpdateLoadbalancerWaitHandler(ctx, r.client.DefaultAPI, projectId, region, *updateResp.Name).SetTimeout(90 * time.Minute).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating Application Load Balancer", fmt.Sprintf("Application Load Balancer update waiting: %v", err)) return @@ -1340,7 +1341,7 @@ func (r *applicationLoadBalancerResource) Delete(ctx context.Context, req resour ctx = tflog.SetField(ctx, "region", region) // Delete Application Load Balancer - _, err := r.client.DeleteLoadBalancer(ctx, projectId, region, name).Execute() + _, err := r.client.DefaultAPI.DeleteLoadBalancer(ctx, projectId, region, name).Execute() if err != nil { errStr := utils.PrettyApiErr(ctx, &resp.Diagnostics, err) core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting Application Load Balancer", fmt.Sprintf("Calling API for delete: %v", errStr)) @@ -1349,7 +1350,7 @@ func (r *applicationLoadBalancerResource) Delete(ctx context.Context, req resour ctx = core.LogResponse(ctx) - _, err = wait.DeleteLoadbalancerWaitHandler(ctx, r.client, projectId, region, name).WaitWithContext(ctx) + _, err = wait.DeleteLoadbalancerWaitHandler(ctx, r.client.DefaultAPI, projectId, region, name).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting Application Load Balancer", fmt.Sprintf("Application Load Balancer deleting waiting: %v", err)) return @@ -1417,7 +1418,7 @@ func toCreatePayload(ctx context.Context, model *Model) (*albSdk.CreateLoadBalan }, nil } -func toLabelPayload(ctx context.Context, model *Model) (albSdk.CreateLoadBalancerPayloadGetLabelsAttributeType, error) { //nolint:gocritic //This needs to be a pointer of a pointe anyway due to how the SDK works +func toLabelPayload(ctx context.Context, model *Model) (*map[string]string, error) { //nolint:gocritic //This needs to be a pointer of a pointe anyway due to how the SDK works if utils.IsUndefined(model.Labels) { return nil, nil } @@ -1430,7 +1431,7 @@ func toLabelPayload(ctx context.Context, model *Model) (albSdk.CreateLoadBalance return &payload, nil } -func toListenersPayload(ctx context.Context, model *Model) (*[]albSdk.Listener, error) { +func toListenersPayload(ctx context.Context, model *Model) ([]albSdk.Listener, error) { if utils.IsUndefined(model.Listeners) { return nil, nil } @@ -1456,13 +1457,13 @@ func toListenersPayload(ctx context.Context, model *Model) (*[]albSdk.Listener, Http: httpPayload, Https: httpsPayload, Name: conversion.StringValueToPointer(listenerModel.Name), - Port: conversion.Int64ValueToPointer(listenerModel.Port), - Protocol: albSdk.ListenerGetProtocolAttributeType(conversion.StringValueToPointer(listenerModel.Protocol)), + Port: conversion.Int32ValueToPointer(listenerModel.Port), + Protocol: conversion.StringValueToPointer(listenerModel.Protocol), WafConfigName: conversion.StringValueToPointer(listenerModel.WafConfigName), }) } - return &payload, nil + return payload, nil } func toHttpPayload(ctx context.Context, listenerModel *listener) (*albSdk.ProtocolOptionsHTTP, error) { @@ -1487,7 +1488,7 @@ func toHttpPayload(ctx context.Context, listenerModel *listener) (*albSdk.Protoc return &payload, nil } -func toHostsPayload(ctx context.Context, httpModel *httpALB) (albSdk.ProtocolOptionsHTTPGetHostsAttributeType, error) { +func toHostsPayload(ctx context.Context, httpModel *httpALB) ([]albSdk.HostConfig, error) { if utils.IsUndefined(httpModel.Hosts) { return nil, nil } @@ -1498,7 +1499,7 @@ func toHostsPayload(ctx context.Context, httpModel *httpALB) (albSdk.ProtocolOpt return nil, fmt.Errorf("converting hosts: %w", core.DiagsToError(diags)) } - payload := albSdk.ProtocolOptionsHTTPGetHostsArgType{} + var payload []albSdk.HostConfig for i := range hostsModel { hostModel := hostsModel[i] if utils.IsUndefined(hostModel.Host) { @@ -1513,10 +1514,10 @@ func toHostsPayload(ctx context.Context, httpModel *httpALB) (albSdk.ProtocolOpt Rules: rulesPayload, }) } - return &payload, nil + return payload, nil } -func toRulesPayload(ctx context.Context, hostConfigModel *hostConfig) (albSdk.HostConfigGetRulesAttributeType, error) { +func toRulesPayload(ctx context.Context, hostConfigModel *hostConfig) ([]albSdk.Rule, error) { if utils.IsUndefined(hostConfigModel.Rules) { return nil, nil } @@ -1555,10 +1556,10 @@ func toRulesPayload(ctx context.Context, hostConfigModel *hostConfig) (albSdk.Ho WebSocket: conversion.BoolValueToPointer(ruleModel.WebSocket), }) } - return &payload, nil + return payload, nil } -func toQueryParametersPayload(ctx context.Context, ruleModel *rule) (albSdk.RuleGetQueryParametersAttributeType, error) { +func toQueryParametersPayload(ctx context.Context, ruleModel *rule) ([]albSdk.QueryParameter, error) { if utils.IsUndefined(ruleModel.QueryParameters) { return nil, nil } @@ -1569,7 +1570,7 @@ func toQueryParametersPayload(ctx context.Context, ruleModel *rule) (albSdk.Rule return nil, fmt.Errorf("converting query parameter payload: %w", core.DiagsToError(diags)) } - payload := albSdk.RuleGetQueryParametersArgType{} + payload := make([]albSdk.QueryParameter, 0, len(queryParametersModel)) for i := range queryParametersModel { queryParameterModel := queryParametersModel[i] payload = append(payload, albSdk.QueryParameter{ @@ -1578,10 +1579,10 @@ func toQueryParametersPayload(ctx context.Context, ruleModel *rule) (albSdk.Rule }) } - return &payload, nil + return payload, nil } -func toPathPayload(ctx context.Context, ruleModel *rule) (albSdk.RuleGetPathAttributeType, error) { +func toPathPayload(ctx context.Context, ruleModel *rule) (*albSdk.Path, error) { if utils.IsUndefined(ruleModel.Path) { return nil, nil } @@ -1599,14 +1600,14 @@ func toPathPayload(ctx context.Context, ruleModel *rule) (albSdk.RuleGetPathAttr return nil, fmt.Errorf("path prefix and exact match are specified at the same time") } - payload := albSdk.RuleGetPathArgType{ + payload := albSdk.Path{ ExactMatch: conversion.StringValueToPointer(pathModel.Exact), Prefix: conversion.StringValueToPointer(pathModel.Prefix), } return &payload, nil } -func toCookiePersistencePayload(ctx context.Context, ruleModel *rule) (albSdk.RuleGetCookiePersistenceAttributeType, error) { +func toCookiePersistencePayload(ctx context.Context, ruleModel *rule) (*albSdk.CookiePersistence, error) { if utils.IsUndefined(ruleModel.CookiePersistence) { return nil, nil } @@ -1617,7 +1618,7 @@ func toCookiePersistencePayload(ctx context.Context, ruleModel *rule) (albSdk.Ru return nil, fmt.Errorf("converting cookie persistence config: %w", core.DiagsToError(diags)) } - payload := albSdk.RuleGetCookiePersistenceArgType{ + payload := albSdk.CookiePersistence{ Name: conversion.StringValueToPointer(cookieModel.Name), Ttl: conversion.StringValueToPointer(cookieModel.Ttl), } @@ -1625,7 +1626,7 @@ func toCookiePersistencePayload(ctx context.Context, ruleModel *rule) (albSdk.Ru return &payload, nil } -func toHeadersPayload(ctx context.Context, ruleModel *rule) (albSdk.RuleGetHeadersAttributeType, error) { +func toHeadersPayload(ctx context.Context, ruleModel *rule) ([]albSdk.HttpHeader, error) { if utils.IsUndefined(ruleModel.Headers) { return nil, nil } @@ -1636,7 +1637,7 @@ func toHeadersPayload(ctx context.Context, ruleModel *rule) (albSdk.RuleGetHeade return nil, fmt.Errorf("converting headers: %w", core.DiagsToError(diags)) } - payload := albSdk.RuleGetHeadersArgType{} + payload := make([]albSdk.HttpHeader, 0, len(headersModel)) for i := range headersModel { header := headersModel[i] payload = append(payload, albSdk.HttpHeader{ @@ -1644,10 +1645,10 @@ func toHeadersPayload(ctx context.Context, ruleModel *rule) (albSdk.RuleGetHeade Name: conversion.StringValueToPointer(header.Name), }) } - return &payload, nil + return payload, nil } -func toHttpsPayload(ctx context.Context, listenerModel *listener) (albSdk.ListenerGetHttpsAttributeType, error) { +func toHttpsPayload(ctx context.Context, listenerModel *listener) (*albSdk.ProtocolOptionsHTTPS, error) { if utils.IsUndefined(listenerModel.Https) { return nil, nil } @@ -1663,7 +1664,7 @@ func toHttpsPayload(ctx context.Context, listenerModel *listener) (albSdk.Listen return nil, fmt.Errorf("converting certificate config: %w", err) } - payload := albSdk.ListenerGetHttpsArgType{ + payload := albSdk.ProtocolOptionsHTTPS{ CertificateConfig: certificateConfigPayload, } @@ -1684,7 +1685,7 @@ func toCertificateConfigPayload(ctx context.Context, https *https) (*albSdk.Cert return nil, fmt.Errorf("converting certificate config: no certificate config found") } - certificateConfigSet, err := conversion.StringSetToPointer(certificateConfigModel.CertificateConfigIDs) + certificateConfigSet, err := conversion.StringSetToSlice(certificateConfigModel.CertificateConfigIDs) if err != nil { return nil, fmt.Errorf("converting certificate config list: %w", err) } @@ -1695,7 +1696,7 @@ func toCertificateConfigPayload(ctx context.Context, https *https) (*albSdk.Cert return &payload, nil } -func toNetworksPayload(ctx context.Context, model *Model) (*[]albSdk.Network, error) { +func toNetworksPayload(ctx context.Context, model *Model) ([]albSdk.Network, error) { if utils.IsUndefined(model.Networks) { return nil, nil } @@ -1711,11 +1712,11 @@ func toNetworksPayload(ctx context.Context, model *Model) (*[]albSdk.Network, er networkModel := networksModel[i] payload = append(payload, albSdk.Network{ NetworkId: conversion.StringValueToPointer(networkModel.NetworkId), - Role: albSdk.NetworkGetRoleAttributeType(conversion.StringValueToPointer(networkModel.Role)), + Role: conversion.StringValueToPointer(networkModel.Role), }) } - return &payload, nil + return payload, nil } func toOptionsPayload(ctx context.Context, model *Model) (*albSdk.LoadBalancerOptions, error) { @@ -1741,7 +1742,7 @@ func toOptionsPayload(ctx context.Context, model *Model) (*albSdk.LoadBalancerOp if diags.HasError() { return nil, fmt.Errorf("converting allowed source ranges: %w", core.DiagsToError(diags)) } - accessControlPayload.AllowedSourceRanges = &allowedSourceRangesModel + accessControlPayload.AllowedSourceRanges = allowedSourceRangesModel } observabilityPayload := &albSdk.LoadbalancerOptionObservability{} @@ -1785,7 +1786,7 @@ func toOptionsPayload(ctx context.Context, model *Model) (*albSdk.LoadBalancerOp return &payload, nil } -func toTargetPoolsPayload(ctx context.Context, model *Model) (*[]albSdk.TargetPool, error) { +func toTargetPoolsPayload(ctx context.Context, model *Model) ([]albSdk.TargetPool, error) { if utils.IsUndefined(model.TargetPools) { return nil, nil } @@ -1816,16 +1817,16 @@ func toTargetPoolsPayload(ctx context.Context, model *Model) (*[]albSdk.TargetPo payload = append(payload, albSdk.TargetPool{ ActiveHealthCheck: activeHealthCheckPayload, Name: conversion.StringValueToPointer(targetPoolModel.Name), - TargetPort: conversion.Int64ValueToPointer(targetPoolModel.TargetPort), + TargetPort: conversion.Int32ValueToPointer(targetPoolModel.TargetPort), Targets: targetsPayload, TlsConfig: tlsConfigPayload, }) } - return &payload, nil + return payload, nil } -func toTlsConfigPayload(ctx context.Context, tp *targetPool) (albSdk.TargetPoolGetTlsConfigAttributeType, error) { +func toTlsConfigPayload(ctx context.Context, tp *targetPool) (*albSdk.TlsConfig, error) { if utils.IsUndefined(tp.TLSConfig) { return nil, nil } @@ -1836,7 +1837,7 @@ func toTlsConfigPayload(ctx context.Context, tp *targetPool) (albSdk.TargetPoolG return nil, fmt.Errorf("converting target pool TLS config: %w", core.DiagsToError(diags)) } - payload := albSdk.TargetPoolGetTlsConfigArgType{ + payload := albSdk.TlsConfig{ Enabled: conversion.BoolValueToPointer(tlsConfigModel.Enabled), SkipCertificateValidation: conversion.BoolValueToPointer(tlsConfigModel.SkipCertValidation), } @@ -1895,7 +1896,7 @@ func toUpdatePayload(ctx context.Context, model *Model) (*albSdk.UpdateLoadBalan // toExternalAddress needs to exist because during UPDATE the model will always have it, but // we do not send it if ephemeral_address or private_network_only options are set. -func toExternalAddress(ctx context.Context, m *Model) (albSdk.UpdateLoadBalancerPayloadGetExternalAddressAttributeType, error) { +func toExternalAddress(ctx context.Context, m *Model) (*string, error) { if utils.IsUndefined(m.Options) { // no ephemeral or private option are set return conversion.StringValueToPointer(m.ExternalAddress), nil @@ -1942,16 +1943,16 @@ func toActiveHealthCheckPayload(ctx context.Context, tp *targetPool) (*albSdk.Ac } return &albSdk.ActiveHealthCheck{ - HealthyThreshold: conversion.Int64ValueToPointer(activeHealthCheckModel.HealthyThreshold), + HealthyThreshold: conversion.Int32ValueToPointer(activeHealthCheckModel.HealthyThreshold), Interval: conversion.StringValueToPointer(activeHealthCheckModel.Interval), IntervalJitter: conversion.StringValueToPointer(activeHealthCheckModel.IntervalJitter), Timeout: conversion.StringValueToPointer(activeHealthCheckModel.Timeout), - UnhealthyThreshold: conversion.Int64ValueToPointer(activeHealthCheckModel.UnhealthyThreshold), + UnhealthyThreshold: conversion.Int32ValueToPointer(activeHealthCheckModel.UnhealthyThreshold), HttpHealthChecks: httpHealthChecksPayload, }, nil } -func toHttpHealthChecksPayload(ctx context.Context, check *activeHealthCheck) (albSdk.ActiveHealthCheckGetHttpHealthChecksAttributeType, error) { +func toHttpHealthChecksPayload(ctx context.Context, check *activeHealthCheck) (*albSdk.HttpHealthChecks, error) { if utils.IsUndefined(check.HttpHealthChecks) { return nil, nil } @@ -1962,7 +1963,7 @@ func toHttpHealthChecksPayload(ctx context.Context, check *activeHealthCheck) (a return nil, fmt.Errorf("converting active health check: %w", core.DiagsToError(diags)) } - okStatus, err := conversion.StringSetToPointer(httpHealthChecksModel.OkStatus) + okStatus, err := conversion.StringSetToSlice(httpHealthChecksModel.OkStatus) if err != nil { return nil, fmt.Errorf("converting active health check ok status: %w", err) } @@ -1974,7 +1975,7 @@ func toHttpHealthChecksPayload(ctx context.Context, check *activeHealthCheck) (a return &payload, nil } -func toTargetsPayload(ctx context.Context, tp *targetPool) (*[]albSdk.Target, error) { +func toTargetsPayload(ctx context.Context, tp *targetPool) ([]albSdk.Target, error) { if utils.IsUndefined(tp.Targets) { return nil, nil } @@ -1994,7 +1995,7 @@ func toTargetsPayload(ctx context.Context, tp *targetPool) (*[]albSdk.Target, er }) } - return &payload, nil + return payload, nil } // mapFields and all other map functions in this file translate an API resource into a Terraform model. @@ -2075,7 +2076,7 @@ func mapErrors(applicationLoadBalancerResp *albSdk.LoadBalancer, m *Model) error } var errorsSet []attr.Value - for i, errorsResp := range *applicationLoadBalancerResp.Errors { + for i, errorsResp := range applicationLoadBalancerResp.Errors { errorMap := map[string]attr.Value{ "description": types.StringPointerValue(errorsResp.Description), "type": types.StringPointerValue((*string)(errorsResp.Type)), @@ -2179,7 +2180,7 @@ func mapListeners(ctx context.Context, applicationLoadBalancerResp *albSdk.LoadB } var listenersSet []attr.Value - for i, listenerResp := range *applicationLoadBalancerResp.Listeners { + for i, listenerResp := range applicationLoadBalancerResp.Listeners { var configMatch *listener for j := range configListeners { if !configListeners[j].Name.IsNull() && configListeners[j].Name.ValueString() == *listenerResp.Name { @@ -2194,7 +2195,7 @@ func mapListeners(ctx context.Context, applicationLoadBalancerResp *albSdk.LoadB listenerMap := map[string]attr.Value{ "name": types.StringPointerValue(listenerResp.Name), - "port": types.Int64PointerValue(listenerResp.Port), + "port": types.Int32PointerValue(listenerResp.Port), "protocol": types.StringValue(string(listenerResp.GetProtocol())), "waf_config_name": types.StringPointerValue(listenerResp.WafConfigName), } @@ -2229,7 +2230,7 @@ func mapListeners(ctx context.Context, applicationLoadBalancerResp *albSdk.LoadB return nil } -func mapHttp(ctx context.Context, httpResp albSdk.ListenerGetHttpAttributeType, l map[string]attr.Value, httpModel basetypes.ObjectValue) error { +func mapHttp(ctx context.Context, httpResp *albSdk.ProtocolOptionsHTTP, l map[string]attr.Value, httpModel basetypes.ObjectValue) error { if httpResp == nil { l["http"] = types.ObjectNull(httpTypes) return nil @@ -2260,7 +2261,7 @@ func mapHttp(ctx context.Context, httpResp albSdk.ListenerGetHttpAttributeType, return nil } -func mapHosts(ctx context.Context, hostsResp albSdk.ProtocolOptionsHTTPGetHostsAttributeType, h map[string]attr.Value, hostsModel types.List) error { +func mapHosts(ctx context.Context, hostsResp []albSdk.HostConfig, h map[string]attr.Value, hostsModel types.List) error { if hostsResp == nil { h["hosts"] = types.ListNull(types.ObjectType{AttrTypes: hostConfigTypes}) return nil @@ -2273,7 +2274,7 @@ func mapHosts(ctx context.Context, hostsResp albSdk.ProtocolOptionsHTTPGetHostsA } var hostsSet []attr.Value - for i, hostResp := range *hostsResp { + for i, hostResp := range hostsResp { var configMatch *hostConfig for _, ch := range configHosts { if !ch.Host.IsNull() && ch.Host.ValueString() == *hostResp.Host { @@ -2315,7 +2316,7 @@ func mapHosts(ctx context.Context, hostsResp albSdk.ProtocolOptionsHTTPGetHostsA return nil } -func mapRules(ctx context.Context, rulesResp albSdk.HostConfigGetRulesAttributeType, h map[string]attr.Value, rulesModel types.List) error { +func mapRules(ctx context.Context, rulesResp []albSdk.Rule, h map[string]attr.Value, rulesModel types.List) error { if rulesResp == nil { h["rules"] = types.ListNull(types.ObjectType{AttrTypes: ruleTypes}) return nil @@ -2328,7 +2329,7 @@ func mapRules(ctx context.Context, rulesResp albSdk.HostConfigGetRulesAttributeT } var rulesList []attr.Value - for i, ruleResp := range *rulesResp { + for i, ruleResp := range rulesResp { webSocket := types.BoolValue(false) // If the webSocket is nil in the response we set it to false in the TF state to // prevent an inconsistent result after apply error @@ -2381,7 +2382,7 @@ func mapRules(ctx context.Context, rulesResp albSdk.HostConfigGetRulesAttributeT return nil } -func mapPath(pathResp albSdk.RuleGetPathAttributeType, r map[string]attr.Value) error { +func mapPath(pathResp *albSdk.Path, r map[string]attr.Value) error { if pathResp == nil { r["path"] = types.ObjectNull(pathTypes) return nil @@ -2401,14 +2402,14 @@ func mapPath(pathResp albSdk.RuleGetPathAttributeType, r map[string]attr.Value) return nil } -func mapQueryParameters(queryParamsResp albSdk.RuleGetQueryParametersAttributeType, r map[string]attr.Value) error { +func mapQueryParameters(queryParamsResp []albSdk.QueryParameter, r map[string]attr.Value) error { if queryParamsResp == nil { r["query_parameters"] = types.SetNull(types.ObjectType{AttrTypes: queryParameterTypes}) return nil } var queryParamsSet []attr.Value - for i, queryParamResp := range *queryParamsResp { + for i, queryParamResp := range queryParamsResp { queryParamMap := map[string]attr.Value{ "name": types.StringPointerValue(queryParamResp.Name), "exact_match": types.StringPointerValue(queryParamResp.ExactMatch), @@ -2434,14 +2435,14 @@ func mapQueryParameters(queryParamsResp albSdk.RuleGetQueryParametersAttributeTy return nil } -func mapHeaders(headersResp albSdk.RuleGetHeadersAttributeType, r map[string]attr.Value) error { +func mapHeaders(headersResp []albSdk.HttpHeader, r map[string]attr.Value) error { if headersResp == nil { r["headers"] = types.SetNull(types.ObjectType{AttrTypes: headersTypes}) return nil } var headersSet []attr.Value - for i, headerResp := range *headersResp { + for i, headerResp := range headersResp { headerMap := map[string]attr.Value{ "name": types.StringPointerValue(headerResp.Name), "exact_match": types.StringPointerValue(headerResp.ExactMatch), @@ -2467,7 +2468,7 @@ func mapHeaders(headersResp albSdk.RuleGetHeadersAttributeType, r map[string]att return nil } -func mapCookiePersistence(cookiePersistResp albSdk.RuleGetCookiePersistenceAttributeType, r map[string]attr.Value) error { +func mapCookiePersistence(cookiePersistResp *albSdk.CookiePersistence, r map[string]attr.Value) error { if cookiePersistResp == nil { r["cookie_persistence"] = types.ObjectNull(cookiePersistenceTypes) return nil @@ -2487,7 +2488,7 @@ func mapCookiePersistence(cookiePersistResp albSdk.RuleGetCookiePersistenceAttri return nil } -func mapHttps(ctx context.Context, httpsResp albSdk.ListenerGetHttpsAttributeType, l map[string]attr.Value) error { +func mapHttps(ctx context.Context, httpsResp *albSdk.ProtocolOptionsHTTPS, l map[string]attr.Value) error { if httpsResp == nil { l["https"] = types.ObjectNull(httpsTypes) return nil @@ -2509,7 +2510,7 @@ func mapHttps(ctx context.Context, httpsResp albSdk.ListenerGetHttpsAttributeTyp return nil } -func mapCertificates(ctx context.Context, certResp albSdk.ProtocolOptionsHTTPSGetCertificateConfigAttributeType, h map[string]attr.Value) error { +func mapCertificates(ctx context.Context, certResp *albSdk.CertificateConfig, h map[string]attr.Value) error { if certResp == nil { h["certificate_config"] = types.ObjectNull(certificateConfigTypes) return nil @@ -2539,7 +2540,7 @@ func mapNetworks(applicationLoadBalancerResp *albSdk.LoadBalancer, m *Model) err } var networksSet []attr.Value - for i, networkResp := range *applicationLoadBalancerResp.Networks { + for i, networkResp := range applicationLoadBalancerResp.Networks { networkMap := map[string]attr.Value{ "network_id": types.StringPointerValue(networkResp.NetworkId), "role": types.StringValue(string(networkResp.GetRole())), @@ -2669,7 +2670,7 @@ func mapAccessControl(accessControlResp *albSdk.LoadbalancerOptionAccessControl, } if accessControlResp.HasAllowedSourceRanges() { var allowedSourceRangesSet []attr.Value - for _, rangeResp := range *accessControlResp.AllowedSourceRanges { + for _, rangeResp := range accessControlResp.AllowedSourceRanges { rangeTF := types.StringValue(rangeResp) allowedSourceRangesSet = append(allowedSourceRangesSet, rangeTF) } @@ -2705,7 +2706,7 @@ func mapTargetPools(ctx context.Context, applicationLoadBalancerResp *albSdk.Loa } var targetPoolsSet []attr.Value - for i, targetPoolResp := range *applicationLoadBalancerResp.TargetPools { + for i, targetPoolResp := range applicationLoadBalancerResp.TargetPools { var configMatch *targetPool for j := range configTargetPools { if !configTargetPools[j].Name.IsNull() && configTargetPools[j].Name.ValueString() == *targetPoolResp.Name { @@ -2720,7 +2721,7 @@ func mapTargetPools(ctx context.Context, applicationLoadBalancerResp *albSdk.Loa targetPoolMap := map[string]attr.Value{ "name": types.StringPointerValue(targetPoolResp.Name), - "target_port": types.Int64PointerValue(targetPoolResp.TargetPort), + "target_port": types.Int32PointerValue(targetPoolResp.TargetPort), } err := mapActiveHealthCheck(ctx, targetPoolResp.ActiveHealthCheck, targetPoolMap) @@ -2764,11 +2765,11 @@ func mapActiveHealthCheck(ctx context.Context, activeHealthCheckResp *albSdk.Act } activeHealthCheckMap := map[string]attr.Value{ - "healthy_threshold": types.Int64PointerValue(activeHealthCheckResp.HealthyThreshold), + "healthy_threshold": types.Int32PointerValue(activeHealthCheckResp.HealthyThreshold), "interval": types.StringPointerValue(activeHealthCheckResp.Interval), "interval_jitter": types.StringPointerValue(activeHealthCheckResp.IntervalJitter), "timeout": types.StringPointerValue(activeHealthCheckResp.Timeout), - "unhealthy_threshold": types.Int64PointerValue(activeHealthCheckResp.UnhealthyThreshold), + "unhealthy_threshold": types.Int32PointerValue(activeHealthCheckResp.UnhealthyThreshold), } err := mapHttpHealthChecks(ctx, activeHealthCheckResp.HttpHealthChecks, activeHealthCheckMap) @@ -2809,7 +2810,7 @@ func mapHttpHealthChecks(ctx context.Context, httpHealthChecksResp *albSdk.HttpH return nil } -func mapTLSConfig(ctx context.Context, targetPoolTLSConfigResp *albSdk.TargetPoolTlsConfig, tp map[string]attr.Value, tlsModel basetypes.ObjectValue) error { +func mapTLSConfig(ctx context.Context, targetPoolTLSConfigResp *albSdk.TlsConfig, tp map[string]attr.Value, tlsModel basetypes.ObjectValue) error { if targetPoolTLSConfigResp == nil { tp["tls_config"] = types.ObjectNull(tlsConfigTypes) return nil @@ -2857,14 +2858,14 @@ func mapTLSConfig(ctx context.Context, targetPoolTLSConfigResp *albSdk.TargetPoo return nil } -func mapTargets(targetsResp *[]albSdk.Target, tp map[string]attr.Value) error { - if targetsResp == nil || *targetsResp == nil { +func mapTargets(targetsResp []albSdk.Target, tp map[string]attr.Value) error { + if targetsResp == nil { tp["targets"] = types.SetNull(types.ObjectType{AttrTypes: targetTypes}) return nil } var targetsSet []attr.Value - for i, targetResp := range *targetsResp { + for i, targetResp := range targetsResp { targetMap := map[string]attr.Value{ "display_name": types.StringPointerValue(targetResp.DisplayName), "ip": types.StringPointerValue(targetResp.Ip), diff --git a/stackit/internal/services/alb/applicationloadbalancer/resource_test.go b/stackit/internal/services/alb/applicationloadbalancer/resource_test.go index ee33ce18e..60b784654 100644 --- a/stackit/internal/services/alb/applicationloadbalancer/resource_test.go +++ b/stackit/internal/services/alb/applicationloadbalancer/resource_test.go @@ -9,7 +9,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/stackitcloud/stackit-sdk-go/core/utils" - albSdk "github.com/stackitcloud/stackit-sdk-go/services/alb" + legacyAlb "github.com/stackitcloud/stackit-sdk-go/services/alb" + albSdk "github.com/stackitcloud/stackit-sdk-go/services/alb/v2api" ) const ( @@ -37,14 +38,14 @@ func fixtureModel(explicitBool *bool, mods ...func(m *Model)) *Model { errorsType, map[string]attr.Value{ "description": types.StringValue("quota test error"), - "type": types.StringValue(string(albSdk.LOADBALANCERERRORTYPE_QUOTA_SECGROUP_EXCEEDED)), + "type": types.StringValue(string(legacyAlb.LOADBALANCERERRORTYPE_QUOTA_SECGROUP_EXCEEDED)), }, ), types.ObjectValueMust( errorsType, map[string]attr.Value{ "description": types.StringValue("fip test error"), - "type": types.StringValue(string(albSdk.LOADBALANCERERRORTYPE_FIP_NOT_CONFIGURED)), + "type": types.StringValue(string(legacyAlb.LOADBALANCERERRORTYPE_FIP_NOT_CONFIGURED)), }, ), }, @@ -61,7 +62,7 @@ func fixtureModel(explicitBool *bool, mods ...func(m *Model)) *Model { listenerTypes, map[string]attr.Value{ "name": types.StringValue("http-80"), - "port": types.Int64Value(80), + "port": types.Int32Value(80), "protocol": types.StringValue("PROTOCOL_HTTP"), "waf_config_name": types.StringValue("my-waf-config"), "http": types.ObjectValueMust( @@ -216,7 +217,7 @@ func fixtureModel(explicitBool *bool, mods ...func(m *Model)) *Model { targetPoolTypes, map[string]attr.Value{ "name": types.StringValue(targetPoolName), - "target_port": types.Int64Value(80), + "target_port": types.Int32Value(80), "targets": types.SetValueMust( types.ObjectType{AttrTypes: targetTypes}, []attr.Value{ @@ -240,11 +241,11 @@ func fixtureModel(explicitBool *bool, mods ...func(m *Model)) *Model { "active_health_check": types.ObjectValueMust( activeHealthCheckTypes, map[string]attr.Value{ - "healthy_threshold": types.Int64Value(1), + "healthy_threshold": types.Int32Value(1), "interval": types.StringValue("2s"), "interval_jitter": types.StringValue("3s"), "timeout": types.StringValue("4s"), - "unhealthy_threshold": types.Int64Value(5), + "unhealthy_threshold": types.Int32Value(5), "http_health_checks": types.ObjectValueMust( httpHealthChecksTypes, map[string]attr.Value{ @@ -338,56 +339,56 @@ func fixtureApplicationLoadBalancer(explicitBool *bool, mods ...func(m *albSdk.L resp := &albSdk.LoadBalancer{ DisableTargetSecurityGroupAssignment: explicitBool, ExternalAddress: utils.Ptr(externalAddress), - Errors: utils.Ptr([]albSdk.LoadBalancerError{ + Errors: []albSdk.LoadBalancerError{ { Description: utils.Ptr("quota test error"), - Type: utils.Ptr(albSdk.LOADBALANCERERRORTYPE_QUOTA_SECGROUP_EXCEEDED), + Type: utils.Ptr(string(legacyAlb.LOADBALANCERERRORTYPE_QUOTA_SECGROUP_EXCEEDED)), }, { Description: utils.Ptr("fip test error"), - Type: utils.Ptr(albSdk.LOADBALANCERERRORTYPE_FIP_NOT_CONFIGURED), + Type: utils.Ptr(string(legacyAlb.LOADBALANCERERRORTYPE_FIP_NOT_CONFIGURED)), }, - }), + }, Name: utils.Ptr(lbName), PlanId: utils.Ptr("p10"), PrivateAddress: utils.Ptr("10.1.11.0"), Region: utils.Ptr(region), - Status: utils.Ptr(albSdk.LoadBalancerStatus("STATUS_READY")), + Status: utils.Ptr("STATUS_READY"), Version: utils.Ptr(lbVersion), Labels: &map[string]string{ "key": "value", "key2": "value2", }, - Networks: &[]albSdk.Network{ + Networks: []albSdk.Network{ { NetworkId: utils.Ptr("c7c92cc1-a6bd-4e15-a129-b6e2b9899bbc"), - Role: utils.Ptr(albSdk.NetworkRole("ROLE_LISTENERS")), + Role: utils.Ptr("ROLE_LISTENERS"), }, { NetworkId: utils.Ptr("ed3f1822-ca1c-4969-bea6-74c6b3e9aa40"), - Role: utils.Ptr(albSdk.NetworkRole("ROLE_TARGETS")), + Role: utils.Ptr("ROLE_TARGETS"), }, }, - Listeners: &[]albSdk.Listener{ + Listeners: []albSdk.Listener{ { Name: utils.Ptr("http-80"), - Port: utils.Ptr(int64(80)), - Protocol: utils.Ptr(albSdk.ListenerProtocol("PROTOCOL_HTTP")), + Port: utils.Ptr(int32(80)), + Protocol: utils.Ptr("PROTOCOL_HTTP"), Http: &albSdk.ProtocolOptionsHTTP{ - Hosts: &[]albSdk.HostConfig{ + Hosts: []albSdk.HostConfig{ { Host: utils.Ptr("*"), - Rules: &[]albSdk.Rule{ + Rules: []albSdk.Rule{ { TargetPool: utils.Ptr(targetPoolName), WebSocket: explicitBool, Path: &albSdk.Path{ Prefix: utils.Ptr("/"), }, - Headers: &[]albSdk.HttpHeader{ + Headers: []albSdk.HttpHeader{ {Name: utils.Ptr("a-header"), ExactMatch: utils.Ptr("value")}, }, - QueryParameters: &[]albSdk.QueryParameter{ + QueryParameters: []albSdk.QueryParameter{ {Name: utils.Ptr("a_query_parameter"), ExactMatch: utils.Ptr("value")}, }, CookiePersistence: &albSdk.CookiePersistence{ @@ -401,7 +402,7 @@ func fixtureApplicationLoadBalancer(explicitBool *bool, mods ...func(m *albSdk.L }, Https: &albSdk.ProtocolOptionsHTTPS{ CertificateConfig: utils.Ptr(albSdk.CertificateConfig{ - CertificateIds: &[]string{ + CertificateIds: []string{ credentialsRef, }, }), @@ -409,30 +410,30 @@ func fixtureApplicationLoadBalancer(explicitBool *bool, mods ...func(m *albSdk.L WafConfigName: utils.Ptr("my-waf-config"), }, }, - TargetPools: &[]albSdk.TargetPool{ + TargetPools: []albSdk.TargetPool{ { Name: utils.Ptr(targetPoolName), - TargetPort: utils.Ptr(int64(80)), - Targets: &[]albSdk.Target{ + TargetPort: utils.Ptr(int32(80)), + Targets: []albSdk.Target{ { DisplayName: utils.Ptr("test-backend-server"), Ip: utils.Ptr("192.168.0.218"), }, }, - TlsConfig: &albSdk.TargetPoolTlsConfig{ + TlsConfig: &albSdk.TlsConfig{ Enabled: explicitBool, SkipCertificateValidation: explicitBool, CustomCa: utils.Ptr("LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURDekNDQWZPZ0F3SUJBZ0lVVHlQc1RXQzlseTdvK3dORlltMHV1MStQOElFd0RRWUpLb1pJaHZjTkFRRUwKQlFBd0ZURVRNQkVHQTFVRUF3d0tUWGxEZFhOMGIyMURRVEFlRncweU5UQXlNVGt4T1RJME1qQmFGdzB5TmpBeQpNVGt4T1RJME1qQmFNQlV4RXpBUkJnTlZCQU1NQ2sxNVEzVnpkRzl0UTBFd2dnRWlNQTBHQ1NxR1NJYjNEUUVCCkFRVUFBNElCRHdBd2dnRUtBb0lCQVFDUU1FWUtiaU54VTM3ZkV3Qk94a3ZDc2hCUiswTXd4d0xXOE1pMy9wdm8KbjNodXhqY203RWFLVzlyN2tJYW9IWGJUUzF0bk82ckhBSEtCRHh6dW9ZRDdDMlNNU2lMeGRkcXVOUnZwa0xhUAo4cUFYbmVRWTJWUDdMenNBZ3NDMDRQS0cwWUMxTmdGNXNKR3NpV0lSR0ltK2NzWUxuUE1ud2FBR3g0SXZZNm1ICkFtTTY0YjZRUkNnMzZMSytQNk45S1R2U1FMdnZtRmRrQTJzRFRvQ21OL0FtcDZ4TkRGcSthUUdMd2RRUXFIRFAKVGFVcVBtRXlpRkhLdkZVYUZNTlFWazhCMU9tOEFTbzY5bThVM0VhdDRaT1ZXMXRpdEUzOTNRa09kQTZaeXBNQwpySkpwZU5OTExKcTNtSU9XT2Q3R0V5QXZqVWZtSndHaHFFRlM3bE1HNjdobkFnTUJBQUdqVXpCUk1CMEdBMVVkCkRnUVdCQlNrL0lNNWphT0FKTDMvS255cTNjVnZhMDRZWkRBZkJnTlZIU01FR0RBV2dCU2svSU01amFPQUpMMy8KS255cTNjVnZhMDRZWkRBUEJnTlZIUk1CQWY4RUJUQURBUUgvTUEwR0NTcUdTSWIzRFFFQkN3VUFBNElCQVFCZQpaL21FOHJOSWJOYkhRZXAvVnBwc2hhWlV6Z2R5NG5zbWgwd3Z4TXVISVFQMEtIcnhMQ2toT243QTlmdTRtWS9QClErOFFxbG5qVHNNNGNxaXVGY2Q1VjFOazlWRi9lNVgzSFhDREhoL2pCRncrTzVUR1ZBUi83REJ3MzFsWXYvTHQKSGFra2pRQ2Rhd3V2SDNvc08vVWtFbE0vaTJLQytpWUJhdlRlbm05N0FSN1dHZ1cxNS9NSXF4TmFZRStuSnRoLwpkY1ZEMGI1cVN1WVFhRW1aM0N6TVVpMTg4UitnbzVvekNmMmNPYWErMy9MRVlBYUkzdktpU0U4S1Rzc2h5b0ttCk82WVpxclZ4UUNXQ0RUT3NkMjhrN2xIdDh3SitqelljakN1NjBEVXBnMVpwWStabm1yRTh2UFBEYi96WGhCbjYKL2xsWFRXT1VqbXVUS25Hc0lEUDUKLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQ=="), }, ActiveHealthCheck: &albSdk.ActiveHealthCheck{ - HealthyThreshold: utils.Ptr(int64(1)), - UnhealthyThreshold: utils.Ptr(int64(5)), + HealthyThreshold: utils.Ptr(int32(1)), + UnhealthyThreshold: utils.Ptr(int32(5)), Interval: utils.Ptr("2s"), IntervalJitter: utils.Ptr("3s"), Timeout: utils.Ptr("4s"), HttpHealthChecks: &albSdk.HttpHealthChecks{ Path: utils.Ptr("/health"), - OkStatuses: &[]string{"200", "201"}, + OkStatuses: []string{"200", "201"}, }, }, }, @@ -451,14 +452,14 @@ func fixtureApplicationLoadBalancer(explicitBool *bool, mods ...func(m *albSdk.L }, }, AccessControl: &albSdk.LoadbalancerOptionAccessControl{ - AllowedSourceRanges: &[]string{"192.168.0.0", "192.168.0.1"}, + AllowedSourceRanges: []string{"192.168.0.0", "192.168.0.1"}, }, }), - LoadBalancerSecurityGroup: &albSdk.CreateLoadBalancerPayloadLoadBalancerSecurityGroup{ + LoadBalancerSecurityGroup: &albSdk.SecurityGroup{ Id: utils.Ptr(sgLBID), Name: utils.Ptr("loadbalancer/" + lbName + "/backend-port"), }, - TargetSecurityGroup: &albSdk.CreateLoadBalancerPayloadTargetSecurityGroup{ + TargetSecurityGroup: &albSdk.SecurityGroup{ Id: utils.Ptr(sgTargetID), Name: utils.Ptr("loadbalancer/" + lbName + "/backend"), }, @@ -678,7 +679,7 @@ func TestMapFields(t *testing.T) { { description: "mapTargets no response", input: fixtureApplicationLoadBalancer(nil, func(m *albSdk.LoadBalancer) { - m.TargetPools = &[]albSdk.TargetPool{ + m.TargetPools = []albSdk.TargetPool{ { // empty target pool ActiveHealthCheck: nil, Name: nil, @@ -700,7 +701,7 @@ func TestMapFields(t *testing.T) { targetPoolTypes, map[string]attr.Value{ "name": types.StringNull(), - "target_port": types.Int64Null(), + "target_port": types.Int32Null(), "targets": types.SetNull(types.ObjectType{AttrTypes: targetTypes}), "tls_config": types.ObjectNull(tlsConfigTypes), "active_health_check": types.ObjectNull(activeHealthCheckTypes), @@ -714,19 +715,19 @@ func TestMapFields(t *testing.T) { { description: "mapHttpHealthChecks no response", input: fixtureApplicationLoadBalancer(nil, func(m *albSdk.LoadBalancer) { - m.TargetPools = &[]albSdk.TargetPool{ + m.TargetPools = []albSdk.TargetPool{ { Name: utils.Ptr(targetPoolName), - TargetPort: utils.Ptr(int64(80)), - Targets: &[]albSdk.Target{ + TargetPort: utils.Ptr(int32(80)), + Targets: []albSdk.Target{ { DisplayName: utils.Ptr("test-backend-server"), Ip: utils.Ptr("192.168.0.218"), }, }, ActiveHealthCheck: &albSdk.ActiveHealthCheck{ - HealthyThreshold: utils.Ptr(int64(1)), - UnhealthyThreshold: utils.Ptr(int64(5)), + HealthyThreshold: utils.Ptr(int32(1)), + UnhealthyThreshold: utils.Ptr(int32(5)), Interval: utils.Ptr("2s"), IntervalJitter: utils.Ptr("3s"), Timeout: utils.Ptr("4s"), @@ -746,7 +747,7 @@ func TestMapFields(t *testing.T) { targetPoolTypes, map[string]attr.Value{ "name": types.StringValue(targetPoolName), - "target_port": types.Int64Value(80), + "target_port": types.Int32Value(80), "targets": types.SetValueMust( types.ObjectType{AttrTypes: targetTypes}, []attr.Value{ @@ -763,11 +764,11 @@ func TestMapFields(t *testing.T) { "active_health_check": types.ObjectValueMust( activeHealthCheckTypes, map[string]attr.Value{ - "healthy_threshold": types.Int64Value(1), + "healthy_threshold": types.Int32Value(1), "interval": types.StringValue("2s"), "interval_jitter": types.StringValue("3s"), "timeout": types.StringValue("4s"), - "unhealthy_threshold": types.Int64Value(5), + "unhealthy_threshold": types.Int32Value(5), "http_health_checks": types.ObjectNull(httpHealthChecksTypes), }, ), @@ -800,26 +801,26 @@ func TestMapFields(t *testing.T) { { description: "mapCertificates no response", input: fixtureApplicationLoadBalancer(nil, func(m *albSdk.LoadBalancer) { - m.Listeners = &[]albSdk.Listener{ + m.Listeners = []albSdk.Listener{ { Name: utils.Ptr("http-80"), - Port: utils.Ptr(int64(80)), - Protocol: utils.Ptr(albSdk.ListenerProtocol("PROTOCOL_HTTP")), + Port: utils.Ptr(int32(80)), + Protocol: utils.Ptr("PROTOCOL_HTTP"), Http: &albSdk.ProtocolOptionsHTTP{ - Hosts: &[]albSdk.HostConfig{ + Hosts: []albSdk.HostConfig{ { Host: utils.Ptr("*"), - Rules: &[]albSdk.Rule{ + Rules: []albSdk.Rule{ { TargetPool: utils.Ptr(targetPoolName), WebSocket: nil, Path: &albSdk.Path{ Prefix: utils.Ptr("/"), }, - Headers: &[]albSdk.HttpHeader{ + Headers: []albSdk.HttpHeader{ {Name: utils.Ptr("a-header"), ExactMatch: utils.Ptr("value")}, }, - QueryParameters: &[]albSdk.QueryParameter{ + QueryParameters: []albSdk.QueryParameter{ {Name: utils.Ptr("a_query_parameter"), ExactMatch: utils.Ptr("value")}, }, CookiePersistence: &albSdk.CookiePersistence{ @@ -850,7 +851,7 @@ func TestMapFields(t *testing.T) { listenerTypes, map[string]attr.Value{ "name": types.StringValue("http-80"), - "port": types.Int64Value(80), + "port": types.Int32Value(80), "protocol": types.StringValue("PROTOCOL_HTTP"), "waf_config_name": types.StringValue("my-waf-config"), "http": types.ObjectValueMust( @@ -926,26 +927,26 @@ func TestMapFields(t *testing.T) { { description: "mapHttps no response", input: fixtureApplicationLoadBalancer(nil, func(m *albSdk.LoadBalancer) { - m.Listeners = &[]albSdk.Listener{ + m.Listeners = []albSdk.Listener{ { Name: utils.Ptr("http-80"), - Port: utils.Ptr(int64(80)), - Protocol: utils.Ptr(albSdk.ListenerProtocol("PROTOCOL_HTTP")), + Port: utils.Ptr(int32(80)), + Protocol: utils.Ptr("PROTOCOL_HTTP"), Http: &albSdk.ProtocolOptionsHTTP{ - Hosts: &[]albSdk.HostConfig{ + Hosts: []albSdk.HostConfig{ { Host: utils.Ptr("*"), - Rules: &[]albSdk.Rule{ + Rules: []albSdk.Rule{ { TargetPool: utils.Ptr(targetPoolName), WebSocket: nil, Path: &albSdk.Path{ Prefix: utils.Ptr("/"), }, - Headers: &[]albSdk.HttpHeader{ + Headers: []albSdk.HttpHeader{ {Name: utils.Ptr("a-header"), ExactMatch: utils.Ptr("value")}, }, - QueryParameters: &[]albSdk.QueryParameter{ + QueryParameters: []albSdk.QueryParameter{ {Name: utils.Ptr("a_query_parameter"), ExactMatch: utils.Ptr("value")}, }, CookiePersistence: &albSdk.CookiePersistence{ @@ -974,7 +975,7 @@ func TestMapFields(t *testing.T) { listenerTypes, map[string]attr.Value{ "name": types.StringValue("http-80"), - "port": types.Int64Value(80), + "port": types.Int32Value(80), "protocol": types.StringValue("PROTOCOL_HTTP"), "waf_config_name": types.StringValue("my-waf-config"), "http": types.ObjectValueMust( @@ -1045,16 +1046,16 @@ func TestMapFields(t *testing.T) { { description: "mapRules contents no response", input: fixtureApplicationLoadBalancer(nil, func(m *albSdk.LoadBalancer) { - m.Listeners = &[]albSdk.Listener{ + m.Listeners = []albSdk.Listener{ { Name: utils.Ptr("http-80"), - Port: utils.Ptr(int64(80)), - Protocol: utils.Ptr(albSdk.ListenerProtocol("PROTOCOL_HTTP")), + Port: utils.Ptr(int32(80)), + Protocol: utils.Ptr("PROTOCOL_HTTP"), Http: &albSdk.ProtocolOptionsHTTP{ - Hosts: &[]albSdk.HostConfig{ + Hosts: []albSdk.HostConfig{ { Host: utils.Ptr("*"), - Rules: &[]albSdk.Rule{ + Rules: []albSdk.Rule{ { TargetPool: utils.Ptr(targetPoolName), WebSocket: nil, @@ -1069,7 +1070,7 @@ func TestMapFields(t *testing.T) { }, Https: &albSdk.ProtocolOptionsHTTPS{ CertificateConfig: utils.Ptr(albSdk.CertificateConfig{ - CertificateIds: &[]string{ + CertificateIds: []string{ credentialsRef, }, }), @@ -1090,7 +1091,7 @@ func TestMapFields(t *testing.T) { listenerTypes, map[string]attr.Value{ "name": types.StringValue("http-80"), - "port": types.Int64Value(80), + "port": types.Int32Value(80), "protocol": types.StringValue("PROTOCOL_HTTP"), "waf_config_name": types.StringValue("my-waf-config"), "http": types.ObjectValueMust( @@ -1147,13 +1148,13 @@ func TestMapFields(t *testing.T) { { description: "mapRules no response", input: fixtureApplicationLoadBalancer(nil, func(m *albSdk.LoadBalancer) { - m.Listeners = &[]albSdk.Listener{ + m.Listeners = []albSdk.Listener{ { Name: utils.Ptr("http-80"), - Port: utils.Ptr(int64(80)), - Protocol: utils.Ptr(albSdk.ListenerProtocol("PROTOCOL_HTTP")), + Port: utils.Ptr(int32(80)), + Protocol: utils.Ptr("PROTOCOL_HTTP"), Http: &albSdk.ProtocolOptionsHTTP{ - Hosts: &[]albSdk.HostConfig{ + Hosts: []albSdk.HostConfig{ { Host: utils.Ptr("*"), Rules: nil, @@ -1162,7 +1163,7 @@ func TestMapFields(t *testing.T) { }, Https: &albSdk.ProtocolOptionsHTTPS{ CertificateConfig: utils.Ptr(albSdk.CertificateConfig{ - CertificateIds: &[]string{ + CertificateIds: []string{ credentialsRef, }, }), @@ -1183,7 +1184,7 @@ func TestMapFields(t *testing.T) { listenerTypes, map[string]attr.Value{ "name": types.StringValue("http-80"), - "port": types.Int64Value(80), + "port": types.Int32Value(80), "protocol": types.StringValue("PROTOCOL_HTTP"), "waf_config_name": types.StringValue("my-waf-config"), "http": types.ObjectValueMust( @@ -1227,17 +1228,17 @@ func TestMapFields(t *testing.T) { { description: "mapHosts no response", input: fixtureApplicationLoadBalancer(nil, func(m *albSdk.LoadBalancer) { - m.Listeners = &[]albSdk.Listener{ + m.Listeners = []albSdk.Listener{ { Name: utils.Ptr("http-80"), - Port: utils.Ptr(int64(80)), - Protocol: utils.Ptr(albSdk.ListenerProtocol("PROTOCOL_HTTP")), + Port: utils.Ptr(int32(80)), + Protocol: utils.Ptr("PROTOCOL_HTTP"), Http: &albSdk.ProtocolOptionsHTTP{ Hosts: nil, }, Https: &albSdk.ProtocolOptionsHTTPS{ CertificateConfig: utils.Ptr(albSdk.CertificateConfig{ - CertificateIds: &[]string{ + CertificateIds: []string{ credentialsRef, }, }), @@ -1258,7 +1259,7 @@ func TestMapFields(t *testing.T) { listenerTypes, map[string]attr.Value{ "name": types.StringValue("http-80"), - "port": types.Int64Value(80), + "port": types.Int32Value(80), "protocol": types.StringValue("PROTOCOL_HTTP"), "waf_config_name": types.StringValue("my-waf-config"), "http": types.ObjectValueMust( @@ -1293,15 +1294,15 @@ func TestMapFields(t *testing.T) { { description: "mapHttp no response", input: fixtureApplicationLoadBalancer(nil, func(m *albSdk.LoadBalancer) { - m.Listeners = &[]albSdk.Listener{ + m.Listeners = []albSdk.Listener{ { Name: utils.Ptr("http-80"), - Port: utils.Ptr(int64(80)), - Protocol: utils.Ptr(albSdk.ListenerProtocol("PROTOCOL_HTTP")), + Port: utils.Ptr(int32(80)), + Protocol: utils.Ptr("PROTOCOL_HTTP"), Http: nil, Https: &albSdk.ProtocolOptionsHTTPS{ CertificateConfig: utils.Ptr(albSdk.CertificateConfig{ - CertificateIds: &[]string{ + CertificateIds: []string{ credentialsRef, }, }), @@ -1322,7 +1323,7 @@ func TestMapFields(t *testing.T) { listenerTypes, map[string]attr.Value{ "name": types.StringValue("http-80"), - "port": types.Int64Value(80), + "port": types.Int32Value(80), "protocol": types.StringValue("PROTOCOL_HTTP"), "waf_config_name": types.StringValue("my-waf-config"), "http": types.ObjectNull(httpTypes), @@ -1373,7 +1374,7 @@ func Test_toExternalAddress(t *testing.T) { tests := []struct { name string input *Model - expected albSdk.UpdateLoadBalancerPayloadGetExternalAddressAttributeType + expected *string isValid bool }{ { @@ -1513,7 +1514,7 @@ func Test_toPathPayload(t *testing.T) { tests := []struct { name string input *rule - expected albSdk.RuleGetPathAttributeType + expected *albSdk.Path isValid bool }{ { diff --git a/stackit/internal/services/alb/utils/util.go b/stackit/internal/services/alb/utils/util.go index a27abf294..e0d32e1f5 100644 --- a/stackit/internal/services/alb/utils/util.go +++ b/stackit/internal/services/alb/utils/util.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - albSdk "github.com/stackitcloud/stackit-sdk-go/services/alb" + albSdk "github.com/stackitcloud/stackit-sdk-go/services/alb/v2api" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/stackitcloud/stackit-sdk-go/core/config" diff --git a/stackit/internal/services/alb/utils/util_test.go b/stackit/internal/services/alb/utils/util_test.go index 7e66ecd52..ddd6e0393 100644 --- a/stackit/internal/services/alb/utils/util_test.go +++ b/stackit/internal/services/alb/utils/util_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" sdkClients "github.com/stackitcloud/stackit-sdk-go/core/clients" "github.com/stackitcloud/stackit-sdk-go/core/config" - albSdk "github.com/stackitcloud/stackit-sdk-go/services/alb" + albSdk "github.com/stackitcloud/stackit-sdk-go/services/alb/v2api" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils" ) From 3a1c33d9f77fa5b1e7fc41a611c9dfd46219d884 Mon Sep 17 00:00:00 2001 From: Carlo Goetz Date: Fri, 27 Mar 2026 14:00:09 +0100 Subject: [PATCH 2/2] fix(conversion) implement StringSetToPointer with StringSetToSlice --- stackit/internal/conversion/conversion.go | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/stackit/internal/conversion/conversion.go b/stackit/internal/conversion/conversion.go index 7dea0d14f..99fe06677 100644 --- a/stackit/internal/conversion/conversion.go +++ b/stackit/internal/conversion/conversion.go @@ -151,26 +151,8 @@ func StringListToPointer(list basetypes.ListValue) (*[]string, error) { // It returns nil if the value is null or unknown. // Note: It sorts the resulting slice to ensure deterministic behavior. func StringSetToPointer(set basetypes.SetValue) (*[]string, error) { - if set.IsNull() || set.IsUnknown() { - return nil, nil - } - - elements := set.Elements() - result := make([]string, 0, len(elements)) - - for i, el := range elements { - elStr, ok := el.(types.String) - if !ok { - return nil, fmt.Errorf("element %d in set is not a string (type: %T)", i, el) - } - result = append(result, elStr.ValueString()) - } - - // Because Sets are unordered in Terraform, we sort here to - // prevent non-deterministic behavior in the provider logic or API calls. - sort.Strings(result) - - return &result, nil + result, err := StringSetToSlice(set) + return &result, err } // StringSetToSlice converts basetypes.SetValue to a slice of strings.