diff --git a/docs/data-sources/loadbalancer.md b/docs/data-sources/loadbalancer.md index e6b9f411c..8f61ae65d 100644 --- a/docs/data-sources/loadbalancer.md +++ b/docs/data-sources/loadbalancer.md @@ -49,7 +49,7 @@ data "stackit_loadbalancer" "example" { Optional: -- `server_name_indicators` (Attributes List) A list of domain names to match in order to pass TLS traffic to the target pool in the current listener (see [below for nested schema](#nestedatt--listeners--server_name_indicators)) +- `server_name_indicators` (Attributes List, Deprecated) A list of domain names to match in order to pass TLS traffic to the target pool in the current listener (see [below for nested schema](#nestedatt--listeners--server_name_indicators)) Read-Only: diff --git a/docs/resources/loadbalancer.md b/docs/resources/loadbalancer.md index 2d527baf0..391423fe7 100644 --- a/docs/resources/loadbalancer.md +++ b/docs/resources/loadbalancer.md @@ -260,7 +260,7 @@ Required: Optional: - `display_name` (String) -- `server_name_indicators` (Attributes List) A list of domain names to match in order to pass TLS traffic to the target pool in the current listener (see [below for nested schema](#nestedatt--listeners--server_name_indicators)) +- `server_name_indicators` (Attributes List, Deprecated) A list of domain names to match in order to pass TLS traffic to the target pool in the current listener (see [below for nested schema](#nestedatt--listeners--server_name_indicators)) - `tcp` (Attributes) Options that are specific to the TCP protocol. (see [below for nested schema](#nestedatt--listeners--tcp)) - `udp` (Attributes) Options that are specific to the UDP protocol. (see [below for nested schema](#nestedatt--listeners--udp)) diff --git a/go.mod b/go.mod index 64fc40a54..dcd1bc28a 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/stackitcloud/stackit-sdk-go/services/git v0.11.0 github.com/stackitcloud/stackit-sdk-go/services/iaas v1.3.5 github.com/stackitcloud/stackit-sdk-go/services/kms v1.6.0 - github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.8.0 + github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.11.1 github.com/stackitcloud/stackit-sdk-go/services/logme v0.27.1 github.com/stackitcloud/stackit-sdk-go/services/logs v0.7.1 github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.27.1 diff --git a/go.sum b/go.sum index 2b4b8674a..33b90f01a 100644 --- a/go.sum +++ b/go.sum @@ -153,8 +153,6 @@ github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= github.com/skeema/knownhosts v1.3.1 h1:X2osQ+RAjK76shCbvhHHHVl3ZlgDm8apHEHFqRjnBY8= github.com/skeema/knownhosts v1.3.1/go.mod h1:r7KTdC8l4uxWRyK2TpQZ/1o5HaSzh06ePQNxPwTcfiY= -github.com/stackitcloud/stackit-sdk-go/core v0.23.0 h1:zPrOhf3Xe47rKRs1fg/AqKYUiJJRYjdcv+3qsS50mEs= -github.com/stackitcloud/stackit-sdk-go/core v0.23.0/go.mod h1:osMglDby4csGZ5sIfhNyYq1bS1TxIdPY88+skE/kkmI= github.com/stackitcloud/stackit-sdk-go/core v0.24.0 h1:kHCcezCJ5OGSP7RRuGOxD5rF2wejpkEiRr/OdvNcuPQ= github.com/stackitcloud/stackit-sdk-go/core v0.24.0/go.mod h1:osMglDby4csGZ5sIfhNyYq1bS1TxIdPY88+skE/kkmI= github.com/stackitcloud/stackit-sdk-go/services/alb v0.12.1 h1:RKaxAymxlyxxE0Gta3yRuQWf07LnlcX+mfGnVB96NHA= @@ -175,6 +173,8 @@ github.com/stackitcloud/stackit-sdk-go/services/kms v1.6.0 h1:WWU2LpqmazsPDgoRAV github.com/stackitcloud/stackit-sdk-go/services/kms v1.6.0/go.mod h1:FuyCm3s/Ihw+tkpVLGMXwgTtlhrijd31cUCUBWpn1p8= github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.8.0 h1:DxrN85V738CRLynu6MULQHO+OXyYnkhVPgoZKULfFIs= github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.8.0/go.mod h1:ClPE4TOM1FeaJiwTXvApq4gWaSgTLq6nU3PPHAIQDN4= +github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.11.1 h1:8hLLCP4n9w3K3dqJaKF1PnMpX4qjR8UQL3gDr80hgDI= +github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.11.1/go.mod h1:vqTjmecQ4+oVWzeo9tCOUZ3TrpIIzM+C0apC7cdAD0Y= github.com/stackitcloud/stackit-sdk-go/services/logme v0.27.1 h1:6AaWxQNtOEvIvbtyySi5KIrNzxGbKgOayUnA3fpuqns= github.com/stackitcloud/stackit-sdk-go/services/logme v0.27.1/go.mod h1:qwpGNPgF7LmfodGPXcgv9uldeSSuFMNJkyD6QPqfiCI= github.com/stackitcloud/stackit-sdk-go/services/logs v0.7.1 h1:cuQA5dO8WSM0LBHR2FBpf+RgKH7/DE7+5NUPLxDpgPg= diff --git a/stackit/internal/services/loadbalancer/loadbalancer/datasource.go b/stackit/internal/services/loadbalancer/loadbalancer/datasource.go index 8a6884de2..df1bb978b 100644 --- a/stackit/internal/services/loadbalancer/loadbalancer/datasource.go +++ b/stackit/internal/services/loadbalancer/loadbalancer/datasource.go @@ -20,7 +20,7 @@ import ( "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" - "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer" + loadbalancer "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/v2api" ) // Ensure the implementation satisfies the expected interfaces. @@ -151,7 +151,7 @@ func (r *loadBalancerDataSource) Schema(_ context.Context, _ datasource.SchemaRe Description: descriptions["listeners.display_name"], Computed: true, }, - "port": schema.Int64Attribute{ + "port": schema.Int32Attribute{ Description: descriptions["port"], Computed: true, }, @@ -160,8 +160,9 @@ func (r *loadBalancerDataSource) Schema(_ context.Context, _ datasource.SchemaRe Computed: true, }, "server_name_indicators": schema.ListNestedAttribute{ - Description: descriptions["server_name_indicators"], - Optional: true, + Description: descriptions["server_name_indicators"], + DeprecationMessage: "`server_name_indicators` is deprecated and will be removed after October 2026", + Optional: true, NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "name": schema.StringAttribute{ @@ -326,7 +327,7 @@ func (r *loadBalancerDataSource) Schema(_ context.Context, _ datasource.SchemaRe Description: descriptions["target_pools.name"], Computed: true, }, - "target_port": schema.Int64Attribute{ + "target_port": schema.Int32Attribute{ Description: descriptions["target_port"], Computed: true, }, @@ -395,7 +396,7 @@ func (r *loadBalancerDataSource) Read(ctx context.Context, req datasource.ReadRe 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 { utils.LogError( ctx, diff --git a/stackit/internal/services/loadbalancer/loadbalancer/resource.go b/stackit/internal/services/loadbalancer/loadbalancer/resource.go index 7e6ad45c6..00523019b 100644 --- a/stackit/internal/services/loadbalancer/loadbalancer/resource.go +++ b/stackit/internal/services/loadbalancer/loadbalancer/resource.go @@ -8,6 +8,7 @@ import ( "time" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/int32planmodifier" loadbalancerUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/loadbalancer/utils" "github.com/google/uuid" @@ -19,7 +20,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" @@ -30,8 +30,8 @@ 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/services/loadbalancer" - "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/wait" + loadbalancer "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/v2api" + "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/v2api/wait" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils" @@ -65,7 +65,7 @@ type Model struct { // Struct corresponding to Model.Listeners[i] type listener struct { DisplayName types.String `tfsdk:"display_name"` - Port types.Int64 `tfsdk:"port"` + Port types.Int32 `tfsdk:"port"` Protocol types.String `tfsdk:"protocol"` ServerNameIndicators types.List `tfsdk:"server_name_indicators"` TargetPool types.String `tfsdk:"target_pool"` @@ -76,7 +76,7 @@ type listener struct { // Types corresponding to listener var listenerTypes = map[string]attr.Type{ "display_name": types.StringType, - "port": types.Int64Type, + "port": types.Int32Type, "protocol": types.StringType, "server_name_indicators": types.ListType{ElemType: types.ObjectType{AttrTypes: serverNameIndicatorTypes}}, "target_pool": types.StringType, @@ -160,7 +160,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.List `tfsdk:"targets"` SessionPersistence types.Object `tfsdk:"session_persistence"` } @@ -169,27 +169,27 @@ 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.ListType{ElemType: types.ObjectType{AttrTypes: targetTypes}}, "session_persistence": types.ObjectType{AttrTypes: sessionPersistenceTypes}, } // Struct corresponding to targetPool.ActiveHealthCheck type activeHealthCheck struct { - HealthyThreshold types.Int64 `tfsdk:"healthy_threshold"` + HealthyThreshold types.Int32 `tfsdk:"healthy_threshold"` 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, "interval": types.StringType, "interval_jitter": types.StringType, "timeout": types.StringType, - "unhealthy_threshold": types.Int64Type, + "unhealthy_threshold": types.Int32Type, } // Struct corresponding to targetPool.Targets[i] @@ -438,12 +438,12 @@ The example below creates the supporting infrastructure using the STACKIT Terraf stringplanmodifier.UseStateForUnknown(), }, }, - "port": schema.Int64Attribute{ + "port": schema.Int32Attribute{ Description: descriptions["port"], Required: true, - PlanModifiers: []planmodifier.Int64{ - int64planmodifier.RequiresReplace(), - int64planmodifier.UseStateForUnknown(), + PlanModifiers: []planmodifier.Int32{ + int32planmodifier.RequiresReplace(), + int32planmodifier.UseStateForUnknown(), }, }, "protocol": schema.StringAttribute{ @@ -458,8 +458,9 @@ The example below creates the supporting infrastructure using the STACKIT Terraf }, }, "server_name_indicators": schema.ListNestedAttribute{ - Description: descriptions["server_name_indicators"], - Optional: true, + Description: descriptions["server_name_indicators"], + DeprecationMessage: "`server_name_indicators` is deprecated and will be removed after October 2026", + Optional: true, NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "name": schema.StringAttribute{ @@ -649,7 +650,7 @@ The example below creates the supporting infrastructure using the STACKIT Terraf Optional: true, Computed: true, Attributes: map[string]schema.Attribute{ - "healthy_threshold": schema.Int64Attribute{ + "healthy_threshold": schema.Int32Attribute{ Description: descriptions["healthy_threshold"], Optional: true, Computed: true, @@ -669,7 +670,7 @@ The example below creates the supporting infrastructure using the STACKIT Terraf Optional: true, Computed: true, }, - "unhealthy_threshold": schema.Int64Attribute{ + "unhealthy_threshold": schema.Int32Attribute{ Description: descriptions["unhealthy_threshold"], Optional: true, Computed: true, @@ -680,7 +681,7 @@ The example below creates the supporting infrastructure using the STACKIT Terraf Description: descriptions["target_pools.name"], Required: true, }, - "target_port": schema.Int64Attribute{ + "target_port": schema.Int32Attribute{ Description: descriptions["target_port"], Required: true, }, @@ -763,7 +764,7 @@ func (r *loadBalancerResource) Create(ctx context.Context, req resource.CreateRe } // Create a new load balancer - createResp, err := r.client.CreateLoadBalancer(ctx, projectId, region).CreateLoadBalancerPayload(*payload).XRequestID(uuid.NewString()).Execute() + createResp, err := r.client.DefaultAPI.CreateLoadBalancer(ctx, projectId, region).CreateLoadBalancerPayload(*payload).XRequestID(uuid.NewString()).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating load balancer", fmt.Sprintf("Calling API: %v", err)) return @@ -786,7 +787,7 @@ func (r *loadBalancerResource) Create(ctx context.Context, req resource.CreateRe return } - waitResp, err := wait.CreateLoadBalancerWaitHandler(ctx, r.client, projectId, region, *createResp.Name).SetTimeout(90 * time.Minute).WaitWithContext(ctx) + waitResp, err := wait.CreateLoadBalancerWaitHandler(ctx, r.client.DefaultAPI, projectId, region, *createResp.Name).SetTimeout(90 * time.Minute).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating load balancer", fmt.Sprintf("Load balancer creation waiting: %v", err)) return @@ -828,7 +829,7 @@ func (r *loadBalancerResource) Read(ctx context.Context, req resource.ReadReques 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 { oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped if ok && oapiErr.StatusCode == http.StatusNotFound { @@ -895,7 +896,7 @@ func (r *loadBalancerResource) Update(ctx context.Context, req resource.UpdateRe } // Update target pool - _, err = r.client.UpdateTargetPool(ctx, projectId, region, name, targetPoolName).UpdateTargetPoolPayload(*payload).Execute() + _, err = r.client.DefaultAPI.UpdateTargetPool(ctx, projectId, region, name, targetPoolName).UpdateTargetPoolPayload(*payload).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating load balancer", fmt.Sprintf("Calling API for target pool: %v", err)) return @@ -906,7 +907,7 @@ func (r *loadBalancerResource) Update(ctx context.Context, req resource.UpdateRe ctx = tflog.SetField(ctx, "target_pool_name", nil) // Get updated load balancer - getResp, err := r.client.GetLoadBalancer(ctx, projectId, region, name).Execute() + getResp, err := r.client.DefaultAPI.GetLoadBalancer(ctx, projectId, region, name).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating load balancer", fmt.Sprintf("Calling API after update: %v", err)) return @@ -948,7 +949,7 @@ func (r *loadBalancerResource) Delete(ctx context.Context, req resource.DeleteRe ctx = tflog.SetField(ctx, "region", region) // Delete load balancer - _, err := r.client.DeleteLoadBalancer(ctx, projectId, region, name).Execute() + _, err := r.client.DefaultAPI.DeleteLoadBalancer(ctx, projectId, region, name).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting load balancer", fmt.Sprintf("Calling API: %v", err)) return @@ -956,7 +957,7 @@ func (r *loadBalancerResource) Delete(ctx context.Context, req resource.DeleteRe 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 load balancer", fmt.Sprintf("Load balancer deleting waiting: %v", err)) return @@ -1021,7 +1022,7 @@ func toCreatePayload(ctx context.Context, model *Model) (*loadbalancer.CreateLoa }, nil } -func toListenersPayload(ctx context.Context, model *Model) (*[]loadbalancer.Listener, error) { +func toListenersPayload(ctx context.Context, model *Model) ([]loadbalancer.Listener, error) { if model.Listeners.IsNull() || model.Listeners.IsUnknown() { return nil, nil } @@ -1053,8 +1054,8 @@ func toListenersPayload(ctx context.Context, model *Model) (*[]loadbalancer.List } payload = append(payload, loadbalancer.Listener{ DisplayName: conversion.StringValueToPointer(listenerModel.DisplayName), - Port: conversion.Int64ValueToPointer(listenerModel.Port), - Protocol: loadbalancer.ListenerGetProtocolAttributeType(conversion.StringValueToPointer(listenerModel.Protocol)), + Port: conversion.Int32ValueToPointer(listenerModel.Port), + Protocol: conversion.StringValueToPointer(listenerModel.Protocol), ServerNameIndicators: serverNameIndicatorsPayload, TargetPool: conversion.StringValueToPointer(listenerModel.TargetPool), Tcp: tcp, @@ -1062,10 +1063,10 @@ func toListenersPayload(ctx context.Context, model *Model) (*[]loadbalancer.List }) } - return &payload, nil + return payload, nil } -func toServerNameIndicatorsPayload(ctx context.Context, l *listener) (*[]loadbalancer.ServerNameIndicator, error) { +func toServerNameIndicatorsPayload(ctx context.Context, l *listener) ([]loadbalancer.ServerNameIndicator, error) { if l.ServerNameIndicators.IsNull() || l.ServerNameIndicators.IsUnknown() { return nil, nil } @@ -1084,7 +1085,7 @@ func toServerNameIndicatorsPayload(ctx context.Context, l *listener) (*[]loadbal }) } - return &payload, nil + return payload, nil } func toTCP(ctx context.Context, listener *listener) (*loadbalancer.OptionsTCP, error) { @@ -1125,7 +1126,7 @@ func toUDP(ctx context.Context, listener *listener) (*loadbalancer.OptionsUDP, e }, nil } -func toNetworksPayload(ctx context.Context, model *Model) (*[]loadbalancer.Network, error) { +func toNetworksPayload(ctx context.Context, model *Model) ([]loadbalancer.Network, error) { if model.Networks.IsNull() || model.Networks.IsUnknown() { return nil, nil } @@ -1145,11 +1146,11 @@ func toNetworksPayload(ctx context.Context, model *Model) (*[]loadbalancer.Netwo networkModel := networksModel[i] payload = append(payload, loadbalancer.Network{ NetworkId: conversion.StringValueToPointer(networkModel.NetworkId), - Role: loadbalancer.NetworkGetRoleAttributeType(conversion.StringValueToPointer(networkModel.Role)), + Role: conversion.StringValueToPointer(networkModel.Role), }) } - return &payload, nil + return payload, nil } func toOptionsPayload(ctx context.Context, model *Model) (*loadbalancer.LoadBalancerOptions, error) { @@ -1173,7 +1174,7 @@ func toOptionsPayload(ctx context.Context, model *Model) (*loadbalancer.LoadBala if diags.HasError() { return nil, fmt.Errorf("converting acl: %w", core.DiagsToError(diags)) } - accessControlPayload.AllowedSourceRanges = &aclModel + accessControlPayload.AllowedSourceRanges = aclModel } observabilityPayload := &loadbalancer.LoadbalancerOptionObservability{} @@ -1216,7 +1217,7 @@ func toOptionsPayload(ctx context.Context, model *Model) (*loadbalancer.LoadBala return &payload, nil } -func toTargetPoolsPayload(ctx context.Context, model *Model) (*[]loadbalancer.TargetPool, error) { +func toTargetPoolsPayload(ctx context.Context, model *Model) ([]loadbalancer.TargetPool, error) { if model.TargetPools.IsNull() || model.TargetPools.IsUnknown() { return nil, nil } @@ -1252,12 +1253,12 @@ func toTargetPoolsPayload(ctx context.Context, model *Model) (*[]loadbalancer.Ta ActiveHealthCheck: activeHealthCheckPayload, Name: conversion.StringValueToPointer(targetPoolModel.Name), SessionPersistence: sessionPersistencePayload, - TargetPort: conversion.Int64ValueToPointer(targetPoolModel.TargetPort), + TargetPort: conversion.Int32ValueToPointer(targetPoolModel.TargetPort), Targets: targetsPayload, }) } - return &payload, nil + return payload, nil } func toTargetPoolUpdatePayload(ctx context.Context, tp *targetPool) (*loadbalancer.UpdateTargetPoolPayload, error) { @@ -1282,7 +1283,7 @@ func toTargetPoolUpdatePayload(ctx context.Context, tp *targetPool) (*loadbalanc ActiveHealthCheck: activeHealthCheckPayload, Name: conversion.StringValueToPointer(tp.Name), SessionPersistence: sessionPersistencePayload, - TargetPort: conversion.Int64ValueToPointer(tp.TargetPort), + TargetPort: conversion.Int32ValueToPointer(tp.TargetPort), Targets: targetsPayload, }, nil } @@ -1315,15 +1316,15 @@ func toActiveHealthCheckPayload(ctx context.Context, tp *targetPool) (*loadbalan } return &loadbalancer.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), }, nil } -func toTargetsPayload(ctx context.Context, tp *targetPool) (*[]loadbalancer.Target, error) { +func toTargetsPayload(ctx context.Context, tp *targetPool) ([]loadbalancer.Target, error) { if tp.Targets.IsNull() || tp.Targets.IsUnknown() { return nil, nil } @@ -1347,7 +1348,7 @@ func toTargetsPayload(ctx context.Context, tp *targetPool) (*[]loadbalancer.Targ }) } - return &payload, nil + return payload, nil } // mapFields and all other map functions in this file translate an API resource into a Terraform model. @@ -1408,11 +1409,11 @@ func mapListeners(loadBalancerResp *loadbalancer.LoadBalancer, m *Model) error { } listenersList := []attr.Value{} - for i, listenerResp := range *loadBalancerResp.Listeners { + for i, listenerResp := range loadBalancerResp.Listeners { listenerMap := map[string]attr.Value{ "display_name": types.StringPointerValue(listenerResp.DisplayName), - "port": types.Int64PointerValue(listenerResp.Port), - "protocol": types.StringValue(string(listenerResp.GetProtocol())), + "port": types.Int32PointerValue(listenerResp.Port), + "protocol": types.StringPointerValue(listenerResp.Protocol), "target_pool": types.StringPointerValue(listenerResp.TargetPool), } @@ -1451,14 +1452,14 @@ func mapListeners(loadBalancerResp *loadbalancer.LoadBalancer, m *Model) error { return nil } -func mapServerNameIndicators(serverNameIndicatorsResp *[]loadbalancer.ServerNameIndicator, l map[string]attr.Value) error { - if serverNameIndicatorsResp == nil || *serverNameIndicatorsResp == nil { +func mapServerNameIndicators(serverNameIndicatorsResp []loadbalancer.ServerNameIndicator, l map[string]attr.Value) error { + if serverNameIndicatorsResp == nil { l["server_name_indicators"] = types.ListNull(types.ObjectType{AttrTypes: serverNameIndicatorTypes}) return nil } serverNameIndicatorsList := []attr.Value{} - for i, serverNameIndicatorResp := range *serverNameIndicatorsResp { + for i, serverNameIndicatorResp := range serverNameIndicatorsResp { serverNameIndicatorMap := map[string]attr.Value{ "name": types.StringPointerValue(serverNameIndicatorResp.Name), } @@ -1524,10 +1525,10 @@ func mapNetworks(loadBalancerResp *loadbalancer.LoadBalancer, m *Model) error { } networksList := []attr.Value{} - for i, networkResp := range *loadBalancerResp.Networks { + for i, networkResp := range loadBalancerResp.Networks { networkMap := map[string]attr.Value{ "network_id": types.StringPointerValue(networkResp.NetworkId), - "role": types.StringValue(string(networkResp.GetRole())), + "role": types.StringPointerValue(networkResp.Role), } networkTF, diags := types.ObjectValue(networkTypes, networkMap) @@ -1632,7 +1633,7 @@ func mapACL(accessControlResp *loadbalancer.LoadbalancerOptionAccessControl, o m } aclList := []attr.Value{} - for _, rangeResp := range *accessControlResp.AllowedSourceRanges { + for _, rangeResp := range accessControlResp.AllowedSourceRanges { rangeTF := types.StringValue(rangeResp) aclList = append(aclList, rangeTF) } @@ -1653,10 +1654,10 @@ func mapTargetPools(loadBalancerResp *loadbalancer.LoadBalancer, m *Model) error } targetPoolsList := []attr.Value{} - for i, targetPoolResp := range *loadBalancerResp.TargetPools { + for i, targetPoolResp := range loadBalancerResp.TargetPools { targetPoolMap := map[string]attr.Value{ "name": types.StringPointerValue(targetPoolResp.Name), - "target_port": types.Int64PointerValue(targetPoolResp.TargetPort), + "target_port": types.Int32PointerValue(targetPoolResp.TargetPort), } err := mapActiveHealthCheck(targetPoolResp.ActiveHealthCheck, targetPoolMap) @@ -1701,11 +1702,11 @@ func mapActiveHealthCheck(activeHealthCheckResp *loadbalancer.ActiveHealthCheck, } 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), } activeHealthCheckTF, diags := types.ObjectValue(activeHealthCheckTypes, activeHealthCheckMap) @@ -1717,14 +1718,14 @@ func mapActiveHealthCheck(activeHealthCheckResp *loadbalancer.ActiveHealthCheck, return nil } -func mapTargets(targetsResp *[]loadbalancer.Target, tp map[string]attr.Value) error { - if targetsResp == nil || *targetsResp == nil { +func mapTargets(targetsResp []loadbalancer.Target, tp map[string]attr.Value) error { + if targetsResp == nil { tp["targets"] = types.ListNull(types.ObjectType{AttrTypes: targetTypes}) return nil } targetsList := []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/loadbalancer/loadbalancer/resource_test.go b/stackit/internal/services/loadbalancer/loadbalancer/resource_test.go index 0212712f8..b3846d51c 100644 --- a/stackit/internal/services/loadbalancer/loadbalancer/resource_test.go +++ b/stackit/internal/services/loadbalancer/loadbalancer/resource_test.go @@ -9,7 +9,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer" + legacyLoadbalancer "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer" + loadbalancer "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/v2api" ) const ( @@ -49,8 +50,8 @@ func TestToCreatePayload(t *testing.T) { Listeners: types.ListValueMust(types.ObjectType{AttrTypes: listenerTypes}, []attr.Value{ types.ObjectValueMust(listenerTypes, map[string]attr.Value{ "display_name": types.StringValue("display_name"), - "port": types.Int64Value(80), - "protocol": types.StringValue(string(loadbalancer.LISTENERPROTOCOL_TCP)), + "port": types.Int32Value(80), + "protocol": types.StringValue(string(legacyLoadbalancer.LISTENERPROTOCOL_TCP)), "server_name_indicators": types.ListValueMust(types.ObjectType{AttrTypes: serverNameIndicatorTypes}, []attr.Value{ types.ObjectValueMust( serverNameIndicatorTypes, @@ -73,11 +74,11 @@ func TestToCreatePayload(t *testing.T) { Networks: types.ListValueMust(types.ObjectType{AttrTypes: networkTypes}, []attr.Value{ types.ObjectValueMust(networkTypes, map[string]attr.Value{ "network_id": types.StringValue("network_id"), - "role": types.StringValue(string(loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS)), + "role": types.StringValue(string(legacyLoadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS)), }), types.ObjectValueMust(networkTypes, map[string]attr.Value{ "network_id": types.StringValue("network_id_2"), - "role": types.StringValue(string(loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS)), + "role": types.StringValue(string(legacyLoadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS)), }), }), Options: types.ObjectValueMust( @@ -102,14 +103,14 @@ func TestToCreatePayload(t *testing.T) { TargetPools: types.ListValueMust(types.ObjectType{AttrTypes: targetPoolTypes}, []attr.Value{ types.ObjectValueMust(targetPoolTypes, map[string]attr.Value{ "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), }), "name": types.StringValue("name"), - "target_port": types.Int64Value(80), + "target_port": types.Int32Value(80), "targets": types.ListValueMust(types.ObjectType{AttrTypes: targetTypes}, []attr.Value{ types.ObjectValueMust(targetTypes, map[string]attr.Value{ "display_name": types.StringValue("display_name"), @@ -124,39 +125,39 @@ func TestToCreatePayload(t *testing.T) { }, &loadbalancer.CreateLoadBalancerPayload{ ExternalAddress: new("external_address"), - Listeners: &[]loadbalancer.Listener{ + Listeners: []loadbalancer.Listener{ { DisplayName: new("display_name"), - Port: new(int64(80)), - Protocol: loadbalancer.LISTENERPROTOCOL_TCP.Ptr(), - ServerNameIndicators: &[]loadbalancer.ServerNameIndicator{ + Port: new(int32(80)), + Protocol: new(string(legacyLoadbalancer.LISTENERPROTOCOL_TCP)), + ServerNameIndicators: []loadbalancer.ServerNameIndicator{ { Name: new("domain.com"), }, }, TargetPool: new("target_pool"), - Tcp: &loadbalancer.OptionsTCP{ + Tcp: new(loadbalancer.OptionsTCP{ IdleTimeout: new("50s"), - }, - Udp: &loadbalancer.OptionsUDP{ + }), + Udp: new(loadbalancer.OptionsUDP{ IdleTimeout: new("50s"), - }, + }), }, }, Name: new("name"), - Networks: &[]loadbalancer.Network{ + Networks: []loadbalancer.Network{ { NetworkId: new("network_id"), - Role: loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS.Ptr(), + Role: new(string(legacyLoadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS)), }, { NetworkId: new("network_id_2"), - Role: loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS.Ptr(), + Role: new(string(legacyLoadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS)), }, }, Options: &loadbalancer.LoadBalancerOptions{ AccessControl: &loadbalancer.LoadbalancerOptionAccessControl{ - AllowedSourceRanges: &[]string{"cidr"}, + AllowedSourceRanges: []string{"cidr"}, }, PrivateNetworkOnly: new(true), Observability: &loadbalancer.LoadbalancerOptionObservability{ @@ -170,18 +171,18 @@ func TestToCreatePayload(t *testing.T) { }, }, }, - TargetPools: &[]loadbalancer.TargetPool{ + TargetPools: []loadbalancer.TargetPool{ { ActiveHealthCheck: &loadbalancer.ActiveHealthCheck{ - HealthyThreshold: new(int64(1)), + HealthyThreshold: new(int32(1)), Interval: new("2s"), IntervalJitter: new("3s"), Timeout: new("4s"), - UnhealthyThreshold: new(int64(5)), + UnhealthyThreshold: new(int32(5)), }, Name: new("name"), - TargetPort: new(int64(80)), - Targets: &[]loadbalancer.Target{ + TargetPort: new(int32(80)), + Targets: []loadbalancer.Target{ { DisplayName: new("display_name"), Ip: new("ip"), @@ -203,8 +204,8 @@ func TestToCreatePayload(t *testing.T) { Listeners: types.ListValueMust(types.ObjectType{AttrTypes: listenerTypes}, []attr.Value{ types.ObjectValueMust(listenerTypes, map[string]attr.Value{ "display_name": types.StringValue("display_name"), - "port": types.Int64Value(80), - "protocol": types.StringValue(string(loadbalancer.LISTENERPROTOCOL_TCP)), + "port": types.Int32Value(80), + "protocol": types.StringValue(string(legacyLoadbalancer.LISTENERPROTOCOL_TCP)), "server_name_indicators": types.ListValueMust(types.ObjectType{AttrTypes: serverNameIndicatorTypes}, []attr.Value{ types.ObjectValueMust( serverNameIndicatorTypes, @@ -223,11 +224,11 @@ func TestToCreatePayload(t *testing.T) { Networks: types.ListValueMust(types.ObjectType{AttrTypes: networkTypes}, []attr.Value{ types.ObjectValueMust(networkTypes, map[string]attr.Value{ "network_id": types.StringValue("network_id"), - "role": types.StringValue(string(loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS)), + "role": types.StringValue(string(legacyLoadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS)), }), types.ObjectValueMust(networkTypes, map[string]attr.Value{ "network_id": types.StringValue("network_id_2"), - "role": types.StringValue(string(loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS)), + "role": types.StringValue(string(legacyLoadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS)), }), }), Options: types.ObjectValueMust( @@ -252,14 +253,14 @@ func TestToCreatePayload(t *testing.T) { TargetPools: types.ListValueMust(types.ObjectType{AttrTypes: targetPoolTypes}, []attr.Value{ types.ObjectValueMust(targetPoolTypes, map[string]attr.Value{ "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), }), "name": types.StringValue("name"), - "target_port": types.Int64Value(80), + "target_port": types.Int32Value(80), "targets": types.ListValueMust(types.ObjectType{AttrTypes: targetTypes}, []attr.Value{ types.ObjectValueMust(targetTypes, map[string]attr.Value{ "display_name": types.StringValue("display_name"), @@ -275,12 +276,12 @@ func TestToCreatePayload(t *testing.T) { &loadbalancer.CreateLoadBalancerPayload{ PlanId: new("p10"), ExternalAddress: new("external_address"), - Listeners: &[]loadbalancer.Listener{ + Listeners: []loadbalancer.Listener{ { DisplayName: new("display_name"), - Port: new(int64(80)), - Protocol: loadbalancer.LISTENERPROTOCOL_TCP.Ptr(), - ServerNameIndicators: &[]loadbalancer.ServerNameIndicator{ + Port: new(int32(80)), + Protocol: new(string(legacyLoadbalancer.LISTENERPROTOCOL_TCP)), + ServerNameIndicators: []loadbalancer.ServerNameIndicator{ { Name: new("domain.com"), }, @@ -289,19 +290,19 @@ func TestToCreatePayload(t *testing.T) { }, }, Name: new("name"), - Networks: &[]loadbalancer.Network{ + Networks: []loadbalancer.Network{ { NetworkId: new("network_id"), - Role: loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS.Ptr(), + Role: new(string(legacyLoadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS)), }, { NetworkId: new("network_id_2"), - Role: loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS.Ptr(), + Role: new(string(legacyLoadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS)), }, }, Options: &loadbalancer.LoadBalancerOptions{ AccessControl: &loadbalancer.LoadbalancerOptionAccessControl{ - AllowedSourceRanges: &[]string{"cidr"}, + AllowedSourceRanges: []string{"cidr"}, }, PrivateNetworkOnly: new(true), Observability: &loadbalancer.LoadbalancerOptionObservability{ @@ -315,18 +316,18 @@ func TestToCreatePayload(t *testing.T) { }, }, }, - TargetPools: &[]loadbalancer.TargetPool{ + TargetPools: []loadbalancer.TargetPool{ { ActiveHealthCheck: &loadbalancer.ActiveHealthCheck{ - HealthyThreshold: new(int64(1)), + HealthyThreshold: new(int32(1)), Interval: new("2s"), IntervalJitter: new("3s"), Timeout: new("4s"), - UnhealthyThreshold: new(int64(5)), + UnhealthyThreshold: new(int32(5)), }, Name: new("name"), - TargetPort: new(int64(80)), - Targets: &[]loadbalancer.Target{ + TargetPort: new(int32(80)), + Targets: []loadbalancer.Target{ { DisplayName: new("display_name"), Ip: new("ip"), @@ -383,14 +384,14 @@ func TestToTargetPoolUpdatePayload(t *testing.T) { "simple_values_ok", &targetPool{ ActiveHealthCheck: 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), }), Name: types.StringValue("name"), - TargetPort: types.Int64Value(80), + TargetPort: types.Int32Value(80), Targets: types.ListValueMust(types.ObjectType{AttrTypes: targetTypes}, []attr.Value{ types.ObjectValueMust(targetTypes, map[string]attr.Value{ "display_name": types.StringValue("display_name"), @@ -403,15 +404,15 @@ func TestToTargetPoolUpdatePayload(t *testing.T) { }, &loadbalancer.UpdateTargetPoolPayload{ ActiveHealthCheck: &loadbalancer.ActiveHealthCheck{ - HealthyThreshold: new(int64(1)), + HealthyThreshold: new(int32(1)), Interval: new("2s"), IntervalJitter: new("3s"), Timeout: new("4s"), - UnhealthyThreshold: new(int64(5)), + UnhealthyThreshold: new(int32(5)), }, Name: new("name"), - TargetPort: new(int64(80)), - Targets: &[]loadbalancer.Target{ + TargetPort: new(int32(80)), + Targets: []loadbalancer.Target{ { DisplayName: new("display_name"), Ip: new("ip"), @@ -513,12 +514,12 @@ func TestMapFields(t *testing.T) { "simple_values_ok", &loadbalancer.LoadBalancer{ ExternalAddress: new("external_address"), - Listeners: new([]loadbalancer.Listener{ + Listeners: []loadbalancer.Listener{ { DisplayName: new("display_name"), - Port: new(int64(80)), - Protocol: loadbalancer.LISTENERPROTOCOL_TCP.Ptr(), - ServerNameIndicators: &[]loadbalancer.ServerNameIndicator{ + Port: new(int32(80)), + Protocol: new(string(legacyLoadbalancer.LISTENERPROTOCOL_TCP)), + ServerNameIndicators: []loadbalancer.ServerNameIndicator{ { Name: new("domain.com"), }, @@ -531,18 +532,18 @@ func TestMapFields(t *testing.T) { IdleTimeout: new("50s"), }, }, - }), + }, Name: new("name"), - Networks: new([]loadbalancer.Network{ + Networks: []loadbalancer.Network{ { NetworkId: new("network_id"), - Role: loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS.Ptr(), + Role: new(string(legacyLoadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS)), }, { NetworkId: new("network_id_2"), - Role: loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS.Ptr(), + Role: new(string(legacyLoadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS)), }, - }), + }, Options: new(loadbalancer.LoadBalancerOptions{ PrivateNetworkOnly: new(true), Observability: &loadbalancer.LoadbalancerOptionObservability{ @@ -556,32 +557,32 @@ func TestMapFields(t *testing.T) { }, }, }), - TargetSecurityGroup: loadbalancer.LoadBalancerGetTargetSecurityGroupAttributeType(&loadbalancer.SecurityGroup{ + TargetSecurityGroup: new(loadbalancer.SecurityGroup{ Id: new("sg-id-12345"), Name: new("sg-name-abcde"), }), - TargetPools: new([]loadbalancer.TargetPool{ + TargetPools: []loadbalancer.TargetPool{ { ActiveHealthCheck: new(loadbalancer.ActiveHealthCheck{ - HealthyThreshold: new(int64(1)), + HealthyThreshold: new(int32(1)), Interval: new("2s"), IntervalJitter: new("3s"), Timeout: new("4s"), - UnhealthyThreshold: new(int64(5)), + UnhealthyThreshold: new(int32(5)), }), Name: new("name"), - TargetPort: new(int64(80)), - Targets: new([]loadbalancer.Target{ + TargetPort: new(int32(80)), + Targets: []loadbalancer.Target{ { DisplayName: new("display_name"), Ip: new("ip"), }, - }), + }, SessionPersistence: new(loadbalancer.SessionPersistence{ UseSourceIpAddress: new(true), }), }, - }), + }, }, nil, testRegion, @@ -593,8 +594,8 @@ func TestMapFields(t *testing.T) { Listeners: types.ListValueMust(types.ObjectType{AttrTypes: listenerTypes}, []attr.Value{ types.ObjectValueMust(listenerTypes, map[string]attr.Value{ "display_name": types.StringValue("display_name"), - "port": types.Int64Value(80), - "protocol": types.StringValue(string(loadbalancer.LISTENERPROTOCOL_TCP)), + "port": types.Int32Value(80), + "protocol": types.StringValue(string(legacyLoadbalancer.LISTENERPROTOCOL_TCP)), "server_name_indicators": types.ListValueMust(types.ObjectType{AttrTypes: serverNameIndicatorTypes}, []attr.Value{ types.ObjectValueMust( serverNameIndicatorTypes, @@ -617,11 +618,11 @@ func TestMapFields(t *testing.T) { Networks: types.ListValueMust(types.ObjectType{AttrTypes: networkTypes}, []attr.Value{ types.ObjectValueMust(networkTypes, map[string]attr.Value{ "network_id": types.StringValue("network_id"), - "role": types.StringValue(string(loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS)), + "role": types.StringValue(string(legacyLoadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS)), }), types.ObjectValueMust(networkTypes, map[string]attr.Value{ "network_id": types.StringValue("network_id_2"), - "role": types.StringValue(string(loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS)), + "role": types.StringValue(string(legacyLoadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS)), }), }), Options: types.ObjectValueMust( @@ -644,14 +645,14 @@ func TestMapFields(t *testing.T) { TargetPools: types.ListValueMust(types.ObjectType{AttrTypes: targetPoolTypes}, []attr.Value{ types.ObjectValueMust(targetPoolTypes, map[string]attr.Value{ "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), }), "name": types.StringValue("name"), - "target_port": types.Int64Value(80), + "target_port": types.Int32Value(80), "targets": types.ListValueMust(types.ObjectType{AttrTypes: targetTypes}, []attr.Value{ types.ObjectValueMust(targetTypes, map[string]attr.Value{ "display_name": types.StringValue("display_name"), @@ -671,33 +672,33 @@ func TestMapFields(t *testing.T) { "simple_values_ok_with_null_private_network_only_response", &loadbalancer.LoadBalancer{ ExternalAddress: new("external_address"), - Listeners: new([]loadbalancer.Listener{ + Listeners: []loadbalancer.Listener{ { DisplayName: new("display_name"), - Port: new(int64(80)), - Protocol: loadbalancer.LISTENERPROTOCOL_TCP.Ptr(), - ServerNameIndicators: &[]loadbalancer.ServerNameIndicator{ + Port: new(int32(80)), + Protocol: new(string(legacyLoadbalancer.LISTENERPROTOCOL_TCP)), + ServerNameIndicators: []loadbalancer.ServerNameIndicator{ { Name: new("domain.com"), }, }, TargetPool: new("target_pool"), }, - }), + }, Name: new("name"), - Networks: new([]loadbalancer.Network{ + Networks: []loadbalancer.Network{ { NetworkId: new("network_id"), - Role: loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS.Ptr(), + Role: new(string(legacyLoadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS)), }, { NetworkId: new("network_id_2"), - Role: loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS.Ptr(), + Role: new(string(legacyLoadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS)), }, - }), + }, Options: new(loadbalancer.LoadBalancerOptions{ AccessControl: &loadbalancer.LoadbalancerOptionAccessControl{ - AllowedSourceRanges: new([]string{"cidr"}), + AllowedSourceRanges: []string{"cidr"}, }, PrivateNetworkOnly: nil, // API sets this to nil if it's false in the request Observability: &loadbalancer.LoadbalancerOptionObservability{ @@ -711,28 +712,28 @@ func TestMapFields(t *testing.T) { }, }, }), - TargetPools: new([]loadbalancer.TargetPool{ + TargetPools: []loadbalancer.TargetPool{ { ActiveHealthCheck: new(loadbalancer.ActiveHealthCheck{ - HealthyThreshold: new(int64(1)), + HealthyThreshold: new(int32(1)), Interval: new("2s"), IntervalJitter: new("3s"), Timeout: new("4s"), - UnhealthyThreshold: new(int64(5)), + UnhealthyThreshold: new(int32(5)), }), Name: new("name"), - TargetPort: new(int64(80)), - Targets: new([]loadbalancer.Target{ + TargetPort: new(int32(80)), + Targets: []loadbalancer.Target{ { DisplayName: new("display_name"), Ip: new("ip"), }, - }), + }, SessionPersistence: new(loadbalancer.SessionPersistence{ UseSourceIpAddress: new(true), }), }, - }), + }, }, new(false), testRegion, @@ -743,8 +744,8 @@ func TestMapFields(t *testing.T) { Listeners: types.ListValueMust(types.ObjectType{AttrTypes: listenerTypes}, []attr.Value{ types.ObjectValueMust(listenerTypes, map[string]attr.Value{ "display_name": types.StringValue("display_name"), - "port": types.Int64Value(80), - "protocol": types.StringValue(string(loadbalancer.LISTENERPROTOCOL_TCP)), + "port": types.Int32Value(80), + "protocol": types.StringValue(string(legacyLoadbalancer.LISTENERPROTOCOL_TCP)), "server_name_indicators": types.ListValueMust(types.ObjectType{AttrTypes: serverNameIndicatorTypes}, []attr.Value{ types.ObjectValueMust( serverNameIndicatorTypes, @@ -763,11 +764,11 @@ func TestMapFields(t *testing.T) { Networks: types.ListValueMust(types.ObjectType{AttrTypes: networkTypes}, []attr.Value{ types.ObjectValueMust(networkTypes, map[string]attr.Value{ "network_id": types.StringValue("network_id"), - "role": types.StringValue(string(loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS)), + "role": types.StringValue(string(legacyLoadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS)), }), types.ObjectValueMust(networkTypes, map[string]attr.Value{ "network_id": types.StringValue("network_id_2"), - "role": types.StringValue(string(loadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS)), + "role": types.StringValue(string(legacyLoadbalancer.NETWORKROLE_LISTENERS_AND_TARGETS)), }), }), Options: types.ObjectValueMust( @@ -792,14 +793,14 @@ func TestMapFields(t *testing.T) { TargetPools: types.ListValueMust(types.ObjectType{AttrTypes: targetPoolTypes}, []attr.Value{ types.ObjectValueMust(targetPoolTypes, map[string]attr.Value{ "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), }), "name": types.StringValue("name"), - "target_port": types.Int64Value(80), + "target_port": types.Int32Value(80), "targets": types.ListValueMust(types.ObjectType{AttrTypes: targetTypes}, []attr.Value{ types.ObjectValueMust(targetTypes, map[string]attr.Value{ "display_name": types.StringValue("display_name"), diff --git a/stackit/internal/services/loadbalancer/loadbalancer_acc_test.go b/stackit/internal/services/loadbalancer/loadbalancer_acc_test.go index 4e8bcd9fd..20e366732 100644 --- a/stackit/internal/services/loadbalancer/loadbalancer_acc_test.go +++ b/stackit/internal/services/loadbalancer/loadbalancer_acc_test.go @@ -4,6 +4,7 @@ import ( "context" _ "embed" "fmt" + "maps" "strings" "testing" @@ -11,13 +12,11 @@ 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/loadbalancer/wait" + "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/v2api/wait" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" - "maps" - "github.com/stackitcloud/stackit-sdk-go/core/utils" - "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer" + loadbalancer "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/v2api" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/testutil" ) @@ -427,27 +426,27 @@ func testAccCheckLoadBalancerDestroy(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 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/loadbalancer/observability-credential/resource.go b/stackit/internal/services/loadbalancer/observability-credential/resource.go index e4613c062..5d4b84523 100644 --- a/stackit/internal/services/loadbalancer/observability-credential/resource.go +++ b/stackit/internal/services/loadbalancer/observability-credential/resource.go @@ -18,7 +18,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/services/loadbalancer" + loadbalancer "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/v2api" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils" @@ -204,7 +204,7 @@ func (r *observabilityCredentialResource) Create(ctx context.Context, req resour } // Create new observability credentials - createResp, err := r.client.CreateCredentials(ctx, projectId, region).CreateCredentialsPayload(*payload).XRequestID(uuid.NewString()).Execute() + createResp, err := r.client.DefaultAPI.CreateCredentials(ctx, projectId, region).CreateCredentialsPayload(*payload).XRequestID(uuid.NewString()).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating observability credential", fmt.Sprintf("Calling API: %v", err)) return @@ -250,7 +250,7 @@ func (r *observabilityCredentialResource) Read(ctx context.Context, req resource ctx = tflog.SetField(ctx, "region", region) // Get credentials - credResp, err := r.client.GetCredentials(ctx, projectId, region, credentialsRef).Execute() + credResp, err := r.client.DefaultAPI.GetCredentials(ctx, projectId, region, credentialsRef).Execute() if err != nil { oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped if ok && oapiErr.StatusCode == http.StatusNotFound { @@ -303,7 +303,7 @@ func (r *observabilityCredentialResource) Delete(ctx context.Context, req resour ctx = tflog.SetField(ctx, "region", region) // Delete credentials - _, err := r.client.DeleteCredentials(ctx, projectId, region, credentialsRef).Execute() + _, err := r.client.DefaultAPI.DeleteCredentials(ctx, projectId, region, credentialsRef).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting observability credential", fmt.Sprintf("Calling API: %v", err)) return diff --git a/stackit/internal/services/loadbalancer/observability-credential/resource_test.go b/stackit/internal/services/loadbalancer/observability-credential/resource_test.go index 6f8a6c0ba..726725b3a 100644 --- a/stackit/internal/services/loadbalancer/observability-credential/resource_test.go +++ b/stackit/internal/services/loadbalancer/observability-credential/resource_test.go @@ -6,7 +6,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer" + loadbalancer "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/v2api" ) func TestToCreatePayload(t *testing.T) { diff --git a/stackit/internal/services/loadbalancer/testfiles/resource-max.tf b/stackit/internal/services/loadbalancer/testfiles/resource-max.tf index d870cb62a..6e5edc60e 100644 --- a/stackit/internal/services/loadbalancer/testfiles/resource-max.tf +++ b/stackit/internal/services/loadbalancer/testfiles/resource-max.tf @@ -80,7 +80,7 @@ resource "stackit_server" "server" { boot_volume = { size = 32 source_type = "image" - source_id = "59838a89-51b1-4892-b57f-b3caf598ee2f" + source_id = "7b10e105-295b-4369-b6e0-567ec940a02b" delete_on_termination = "true" } network_interfaces = [stackit_network_interface.network_interface.network_interface_id] diff --git a/stackit/internal/services/loadbalancer/testfiles/resource-min.tf b/stackit/internal/services/loadbalancer/testfiles/resource-min.tf index f2692c35d..229961eed 100644 --- a/stackit/internal/services/loadbalancer/testfiles/resource-min.tf +++ b/stackit/internal/services/loadbalancer/testfiles/resource-min.tf @@ -52,7 +52,7 @@ resource "stackit_server" "server" { boot_volume = { size = 32 source_type = "image" - source_id = "59838a89-51b1-4892-b57f-b3caf598ee2f" + source_id = "7b10e105-295b-4369-b6e0-567ec940a02b" delete_on_termination = "true" } network_interfaces = [stackit_network_interface.network_interface.network_interface_id] diff --git a/stackit/internal/services/loadbalancer/utils/util.go b/stackit/internal/services/loadbalancer/utils/util.go index 2b84c5667..6a6d6da41 100644 --- a/stackit/internal/services/loadbalancer/utils/util.go +++ b/stackit/internal/services/loadbalancer/utils/util.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer" + loadbalancer "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/v2api" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/stackitcloud/stackit-sdk-go/core/config" diff --git a/stackit/internal/services/loadbalancer/utils/util_test.go b/stackit/internal/services/loadbalancer/utils/util_test.go index b7e118f3b..49d647a64 100644 --- a/stackit/internal/services/loadbalancer/utils/util_test.go +++ b/stackit/internal/services/loadbalancer/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" - "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer" + loadbalancer "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/v2api" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils" )