diff --git a/stackit/internal/conversion/conversion.go b/stackit/internal/conversion/conversion.go index 2617a74f1..08c7a51a5 100644 --- a/stackit/internal/conversion/conversion.go +++ b/stackit/internal/conversion/conversion.go @@ -108,6 +108,16 @@ func Int64ValueToPointer(s basetypes.Int64Value) *int64 { return &value } +// Float32ValueToPointer converts basetypes.Float32Value to a pointer to float32. +// It returns nil if the value is null or unknown. +func Float32ValueToPointer(s basetypes.Float32Value) *float32 { + if s.IsNull() || s.IsUnknown() { + return nil + } + value := s.ValueFloat32() + return &value +} + // Float64ValueToPointer converts basetypes.Float64Value to a pointer to float64. // It returns nil if the value is null or unknown. func Float64ValueToPointer(s basetypes.Float64Value) *float64 { diff --git a/stackit/internal/services/logme/credential/datasource.go b/stackit/internal/services/logme/credential/datasource.go index 450845fe0..0d7c1c4c0 100644 --- a/stackit/internal/services/logme/credential/datasource.go +++ b/stackit/internal/services/logme/credential/datasource.go @@ -16,7 +16,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/logme" + logmeSdk "github.com/stackitcloud/stackit-sdk-go/services/logme/v1api" ) // Ensure the implementation satisfies the expected interfaces. @@ -31,7 +31,7 @@ func NewCredentialDataSource() datasource.DataSource { // credentialDataSource is the data source implementation. type credentialDataSource struct { - client *logme.APIClient + client *logmeSdk.APIClient } // Metadata returns the data source type name. @@ -102,7 +102,7 @@ func (r *credentialDataSource) Schema(_ context.Context, _ datasource.SchemaRequ Computed: true, Sensitive: true, }, - "port": schema.Int64Attribute{ + "port": schema.Int32Attribute{ Computed: true, }, "uri": schema.StringAttribute{ @@ -134,7 +134,7 @@ func (r *credentialDataSource) Read(ctx context.Context, req datasource.ReadRequ ctx = tflog.SetField(ctx, "instance_id", instanceId) ctx = tflog.SetField(ctx, "credential_id", credentialId) - recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialId).Execute() + recordSetResp, err := r.client.DefaultAPI.GetCredentials(ctx, projectId, instanceId, credentialId).Execute() if err != nil { utils.LogError( ctx, diff --git a/stackit/internal/services/logme/credential/resource.go b/stackit/internal/services/logme/credential/resource.go index a5b1372a3..56615ee52 100644 --- a/stackit/internal/services/logme/credential/resource.go +++ b/stackit/internal/services/logme/credential/resource.go @@ -22,8 +22,9 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/stackitcloud/stackit-sdk-go/core/oapierror" - "github.com/stackitcloud/stackit-sdk-go/services/logme" - "github.com/stackitcloud/stackit-sdk-go/services/logme/wait" + + logmeSdk "github.com/stackitcloud/stackit-sdk-go/services/logme/v1api" + "github.com/stackitcloud/stackit-sdk-go/services/logme/v1api/wait" ) // Ensure the implementation satisfies the expected interfaces. @@ -40,7 +41,7 @@ type Model struct { ProjectId types.String `tfsdk:"project_id"` Host types.String `tfsdk:"host"` Password types.String `tfsdk:"password"` - Port types.Int64 `tfsdk:"port"` + Port types.Int32 `tfsdk:"port"` Uri types.String `tfsdk:"uri"` Username types.String `tfsdk:"username"` } @@ -52,7 +53,7 @@ func NewCredentialResource() resource.Resource { // credentialResource is the resource implementation. type credentialResource struct { - client *logme.APIClient + client *logmeSdk.APIClient } // Metadata returns the resource type name. @@ -137,7 +138,7 @@ func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest, Computed: true, Sensitive: true, }, - "port": schema.Int64Attribute{ + "port": schema.Int32Attribute{ Computed: true, }, "uri": schema.StringAttribute{ @@ -168,7 +169,7 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ ctx = tflog.SetField(ctx, "instance_id", instanceId) // Create new recordset - credentialsResp, err := r.client.CreateCredentials(ctx, projectId, instanceId).Execute() + credentialsResp, err := r.client.DefaultAPI.CreateCredentials(ctx, projectId, instanceId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", fmt.Sprintf("Calling API: %v", err)) return @@ -176,11 +177,7 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ ctx = core.LogResponse(ctx) - if credentialsResp.Id == nil { - core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", "Got empty credential id") - return - } - credentialId := *credentialsResp.Id + credentialId := credentialsResp.Id // Write id attributes to state before polling via the wait handler - just in case anything goes wrong during the wait handler ctx = utils.SetAndLogStateFields(ctx, &resp.Diagnostics, &resp.State, map[string]any{ "project_id": projectId, @@ -191,7 +188,7 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ return } - waitResp, err := wait.CreateCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialId).WaitWithContext(ctx) + waitResp, err := wait.CreateCredentialsWaitHandler(ctx, r.client.DefaultAPI, projectId, instanceId, credentialId).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", fmt.Sprintf("Instance creation waiting: %v", err)) return @@ -229,7 +226,7 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest, ctx = tflog.SetField(ctx, "instance_id", instanceId) ctx = tflog.SetField(ctx, "credential_id", credentialId) - recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialId).Execute() + recordSetResp, err := r.client.DefaultAPI.GetCredentials(ctx, projectId, instanceId, credentialId).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 { @@ -283,14 +280,14 @@ func (r *credentialResource) Delete(ctx context.Context, req resource.DeleteRequ ctx = tflog.SetField(ctx, "credential_id", credentialId) // Delete existing record set - err := r.client.DeleteCredentials(ctx, projectId, instanceId, credentialId).Execute() + err := r.client.DefaultAPI.DeleteCredentials(ctx, projectId, instanceId, credentialId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting credential", fmt.Sprintf("Calling API: %v", err)) } ctx = core.LogResponse(ctx) - _, err = wait.DeleteCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialId).WaitWithContext(ctx) + _, err = wait.DeleteCredentialsWaitHandler(ctx, r.client.DefaultAPI, projectId, instanceId, credentialId).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting credential", fmt.Sprintf("Instance deletion waiting: %v", err)) return @@ -318,7 +315,7 @@ func (r *credentialResource) ImportState(ctx context.Context, req resource.Impor tflog.Info(ctx, "LogMe credential state imported") } -func mapFields(credentialsResp *logme.CredentialsResponse, model *Model) error { +func mapFields(credentialsResp *logmeSdk.CredentialsResponse, model *Model) error { if credentialsResp == nil { return fmt.Errorf("response input is nil") } @@ -333,20 +330,19 @@ func mapFields(credentialsResp *logme.CredentialsResponse, model *Model) error { var credentialId string if model.CredentialId.ValueString() != "" { credentialId = model.CredentialId.ValueString() - } else if credentialsResp.Id != nil { - credentialId = *credentialsResp.Id + } else if credentialsResp.Id != "" { + credentialId = credentialsResp.Id } else { return fmt.Errorf("credentials id not present") } model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), model.InstanceId.ValueString(), credentialId) model.CredentialId = types.StringValue(credentialId) - if credentials != nil { - model.Host = types.StringPointerValue(credentials.Host) - model.Password = types.StringPointerValue(credentials.Password) - model.Port = types.Int64PointerValue(credentials.Port) - model.Uri = types.StringPointerValue(credentials.Uri) - model.Username = types.StringPointerValue(credentials.Username) - } + model.Host = types.StringValue(credentials.Host) + model.Password = types.StringValue(credentials.Password) + model.Port = types.Int32PointerValue(credentials.Port) + model.Uri = types.StringPointerValue(credentials.Uri) + model.Username = types.StringValue(credentials.Username) + return nil } diff --git a/stackit/internal/services/logme/credential/resource_test.go b/stackit/internal/services/logme/credential/resource_test.go index e982d53a9..b8d6048d8 100644 --- a/stackit/internal/services/logme/credential/resource_test.go +++ b/stackit/internal/services/logme/credential/resource_test.go @@ -5,46 +5,46 @@ import ( "github.com/google/go-cmp/cmp" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/stackitcloud/stackit-sdk-go/services/logme" + logmeSdk "github.com/stackitcloud/stackit-sdk-go/services/logme/v1api" ) func TestMapFields(t *testing.T) { tests := []struct { description string - input *logme.CredentialsResponse + input *logmeSdk.CredentialsResponse expected Model isValid bool }{ { "default_values", - &logme.CredentialsResponse{ - Id: new("cid"), - Raw: &logme.RawCredentials{}, + &logmeSdk.CredentialsResponse{ + Id: "cid", + Raw: &logmeSdk.RawCredentials{}, }, Model{ Id: types.StringValue("pid,iid,cid"), CredentialId: types.StringValue("cid"), InstanceId: types.StringValue("iid"), ProjectId: types.StringValue("pid"), - Host: types.StringNull(), - Password: types.StringNull(), - Port: types.Int64Null(), + Host: types.StringValue(""), + Password: types.StringValue(""), + Port: types.Int32Null(), Uri: types.StringNull(), - Username: types.StringNull(), + Username: types.StringValue(""), }, true, }, { "simple_values", - &logme.CredentialsResponse{ - Id: new("cid"), - Raw: &logme.RawCredentials{ - Credentials: &logme.Credentials{ - Host: new("host"), - Password: new("password"), - Port: new(int64(1234)), + &logmeSdk.CredentialsResponse{ + Id: "cid", + Raw: &logmeSdk.RawCredentials{ + Credentials: logmeSdk.Credentials{ + Host: "host", + Password: "password", + Port: new(int32(1234)), Uri: new("uri"), - Username: new("username"), + Username: "username", }, }, }, @@ -55,7 +55,7 @@ func TestMapFields(t *testing.T) { ProjectId: types.StringValue("pid"), Host: types.StringValue("host"), Password: types.StringValue("password"), - Port: types.Int64Value(1234), + Port: types.Int32Value(1234), Uri: types.StringValue("uri"), Username: types.StringValue("username"), }, @@ -63,15 +63,15 @@ func TestMapFields(t *testing.T) { }, { "null_fields_and_int_conversions", - &logme.CredentialsResponse{ - Id: new("cid"), - Raw: &logme.RawCredentials{ - Credentials: &logme.Credentials{ - Host: new(""), - Password: new(""), - Port: new(int64(2123456789)), + &logmeSdk.CredentialsResponse{ + Id: "cid", + Raw: &logmeSdk.RawCredentials{ + Credentials: logmeSdk.Credentials{ + Host: "", + Password: "", + Port: new(int32(2123456789)), Uri: nil, - Username: new(""), + Username: "", }, }, }, @@ -82,7 +82,7 @@ func TestMapFields(t *testing.T) { ProjectId: types.StringValue("pid"), Host: types.StringValue(""), Password: types.StringValue(""), - Port: types.Int64Value(2123456789), + Port: types.Int32Value(2123456789), Uri: types.StringNull(), Username: types.StringValue(""), }, @@ -96,14 +96,14 @@ func TestMapFields(t *testing.T) { }, { "no_resource_id", - &logme.CredentialsResponse{}, + &logmeSdk.CredentialsResponse{}, Model{}, false, }, { "nil_raw_credential", - &logme.CredentialsResponse{ - Id: new("cid"), + &logmeSdk.CredentialsResponse{ + Id: "cid", }, Model{}, false, diff --git a/stackit/internal/services/logme/instance/datasource.go b/stackit/internal/services/logme/instance/datasource.go index 7ad2ef2b9..4615261aa 100644 --- a/stackit/internal/services/logme/instance/datasource.go +++ b/stackit/internal/services/logme/instance/datasource.go @@ -17,7 +17,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/logme" + logmeSdk "github.com/stackitcloud/stackit-sdk-go/services/logme/v1api" ) // Ensure the implementation satisfies the expected interfaces. @@ -32,7 +32,7 @@ func NewInstanceDataSource() datasource.DataSource { // instanceDataSource is the data source implementation. type instanceDataSource struct { - client *logme.APIClient + client *logmeSdk.APIClient } // Metadata returns the data source type name. @@ -133,11 +133,11 @@ func (r *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaReques Description: parametersDescriptions["enable_monitoring"], Computed: true, }, - "fluentd_tcp": schema.Int64Attribute{ + "fluentd_tcp": schema.Int32Attribute{ Description: parametersDescriptions["fluentd_tcp"], Computed: true, }, - "fluentd_tls": schema.Int64Attribute{ + "fluentd_tls": schema.Int32Attribute{ Description: parametersDescriptions["fluentd_tls"], Computed: true, }, @@ -157,7 +157,7 @@ func (r *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaReques Description: parametersDescriptions["fluentd_tls_version"], Computed: true, }, - "fluentd_udp": schema.Int64Attribute{ + "fluentd_udp": schema.Int32Attribute{ Description: parametersDescriptions["fluentd_udp"], Computed: true, }, @@ -169,27 +169,27 @@ func (r *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaReques Description: parametersDescriptions["ism_deletion_after"], Computed: true, }, - "ism_jitter": schema.Float64Attribute{ + "ism_jitter": schema.Float32Attribute{ Description: parametersDescriptions["ism_jitter"], Computed: true, }, - "ism_job_interval": schema.Int64Attribute{ + "ism_job_interval": schema.Int32Attribute{ Description: parametersDescriptions["ism_job_interval"], Computed: true, }, - "java_heapspace": schema.Int64Attribute{ + "java_heapspace": schema.Int32Attribute{ Description: parametersDescriptions["java_heapspace"], Computed: true, }, - "java_maxmetaspace": schema.Int64Attribute{ + "java_maxmetaspace": schema.Int32Attribute{ Description: parametersDescriptions["java_maxmetaspace"], Computed: true, }, - "max_disk_threshold": schema.Int64Attribute{ + "max_disk_threshold": schema.Int32Attribute{ Description: parametersDescriptions["max_disk_threshold"], Computed: true, }, - "metrics_frequency": schema.Int64Attribute{ + "metrics_frequency": schema.Int32Attribute{ Description: parametersDescriptions["metrics_frequency"], Computed: true, }, @@ -254,7 +254,7 @@ func (r *instanceDataSource) Read(ctx context.Context, req datasource.ReadReques ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "instance_id", instanceId) - instanceResp, err := r.client.GetInstance(ctx, projectId, instanceId).Execute() + instanceResp, err := r.client.DefaultAPI.GetInstance(ctx, projectId, instanceId).Execute() if err != nil { utils.LogError( ctx, diff --git a/stackit/internal/services/logme/instance/resource.go b/stackit/internal/services/logme/instance/resource.go index f4571f98f..f716c5f70 100644 --- a/stackit/internal/services/logme/instance/resource.go +++ b/stackit/internal/services/logme/instance/resource.go @@ -3,6 +3,7 @@ package logme import ( "context" "fmt" + "math" "net/http" "slices" "strings" @@ -27,8 +28,9 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/stackitcloud/stackit-sdk-go/core/oapierror" - "github.com/stackitcloud/stackit-sdk-go/services/logme" - "github.com/stackitcloud/stackit-sdk-go/services/logme/wait" + "github.com/stackitcloud/stackit-sdk-go/services/logme/v1api/wait" + + logmeSdk "github.com/stackitcloud/stackit-sdk-go/services/logme/v1api" ) // Ensure the implementation satisfies the expected interfaces. @@ -58,21 +60,21 @@ type Model struct { type parametersModel struct { SgwAcl types.String `tfsdk:"sgw_acl"` EnableMonitoring types.Bool `tfsdk:"enable_monitoring"` - FluentdTcp types.Int64 `tfsdk:"fluentd_tcp"` - FluentdTls types.Int64 `tfsdk:"fluentd_tls"` + FluentdTcp types.Int32 `tfsdk:"fluentd_tcp"` + FluentdTls types.Int32 `tfsdk:"fluentd_tls"` FluentdTlsCiphers types.String `tfsdk:"fluentd_tls_ciphers"` FluentdTlsMaxVersion types.String `tfsdk:"fluentd_tls_max_version"` FluentdTlsMinVersion types.String `tfsdk:"fluentd_tls_min_version"` FluentdTlsVersion types.String `tfsdk:"fluentd_tls_version"` - FluentdUdp types.Int64 `tfsdk:"fluentd_udp"` + FluentdUdp types.Int32 `tfsdk:"fluentd_udp"` Graphite types.String `tfsdk:"graphite"` IsmDeletionAfter types.String `tfsdk:"ism_deletion_after"` - IsmJitter types.Float64 `tfsdk:"ism_jitter"` - IsmJobInterval types.Int64 `tfsdk:"ism_job_interval"` - JavaHeapspace types.Int64 `tfsdk:"java_heapspace"` - JavaMaxmetaspace types.Int64 `tfsdk:"java_maxmetaspace"` - MaxDiskThreshold types.Int64 `tfsdk:"max_disk_threshold"` - MetricsFrequency types.Int64 `tfsdk:"metrics_frequency"` + IsmJitter types.Float32 `tfsdk:"ism_jitter"` + IsmJobInterval types.Int32 `tfsdk:"ism_job_interval"` + JavaHeapspace types.Int32 `tfsdk:"java_heapspace"` + JavaMaxmetaspace types.Int32 `tfsdk:"java_maxmetaspace"` + MaxDiskThreshold types.Int32 `tfsdk:"max_disk_threshold"` + MetricsFrequency types.Int32 `tfsdk:"metrics_frequency"` MetricsPrefix types.String `tfsdk:"metrics_prefix"` MonitoringInstanceId types.String `tfsdk:"monitoring_instance_id"` OpensearchTlsCiphers types.List `tfsdk:"opensearch_tls_ciphers"` @@ -84,21 +86,21 @@ type parametersModel struct { var parametersTypes = map[string]attr.Type{ "sgw_acl": basetypes.StringType{}, "enable_monitoring": basetypes.BoolType{}, - "fluentd_tcp": basetypes.Int64Type{}, - "fluentd_tls": basetypes.Int64Type{}, + "fluentd_tcp": basetypes.Int32Type{}, + "fluentd_tls": basetypes.Int32Type{}, "fluentd_tls_ciphers": basetypes.StringType{}, "fluentd_tls_max_version": basetypes.StringType{}, "fluentd_tls_min_version": basetypes.StringType{}, "fluentd_tls_version": basetypes.StringType{}, - "fluentd_udp": basetypes.Int64Type{}, + "fluentd_udp": basetypes.Int32Type{}, "graphite": basetypes.StringType{}, "ism_deletion_after": basetypes.StringType{}, - "ism_jitter": basetypes.Float64Type{}, - "ism_job_interval": basetypes.Int64Type{}, - "java_heapspace": basetypes.Int64Type{}, - "java_maxmetaspace": basetypes.Int64Type{}, - "max_disk_threshold": basetypes.Int64Type{}, - "metrics_frequency": basetypes.Int64Type{}, + "ism_jitter": basetypes.Float32Type{}, + "ism_job_interval": basetypes.Int32Type{}, + "java_heapspace": basetypes.Int32Type{}, + "java_maxmetaspace": basetypes.Int32Type{}, + "max_disk_threshold": basetypes.Int32Type{}, + "metrics_frequency": basetypes.Int32Type{}, "metrics_prefix": basetypes.StringType{}, "monitoring_instance_id": basetypes.StringType{}, "opensearch_tls_ciphers": basetypes.ListType{ElemType: types.StringType}, @@ -113,7 +115,7 @@ func NewInstanceResource() resource.Resource { // instanceResource is the resource implementation. type instanceResource struct { - client *logme.APIClient + client *logmeSdk.APIClient } // Metadata returns the resource type name. @@ -235,12 +237,12 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r Optional: true, Computed: true, }, - "fluentd_tcp": schema.Int64Attribute{ + "fluentd_tcp": schema.Int32Attribute{ Description: parametersDescriptions["fluentd_tcp"], Optional: true, Computed: true, }, - "fluentd_tls": schema.Int64Attribute{ + "fluentd_tls": schema.Int32Attribute{ Description: parametersDescriptions["fluentd_tls"], Optional: true, Computed: true, @@ -265,7 +267,7 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r Optional: true, Computed: true, }, - "fluentd_udp": schema.Int64Attribute{ + "fluentd_udp": schema.Int32Attribute{ Description: parametersDescriptions["fluentd_udp"], Optional: true, Computed: true, @@ -280,32 +282,32 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r Optional: true, Computed: true, }, - "ism_jitter": schema.Float64Attribute{ + "ism_jitter": schema.Float32Attribute{ Description: parametersDescriptions["ism_jitter"], Optional: true, Computed: true, }, - "ism_job_interval": schema.Int64Attribute{ + "ism_job_interval": schema.Int32Attribute{ Description: parametersDescriptions["ism_job_interval"], Optional: true, Computed: true, }, - "java_heapspace": schema.Int64Attribute{ + "java_heapspace": schema.Int32Attribute{ Description: parametersDescriptions["java_heapspace"], Optional: true, Computed: true, }, - "java_maxmetaspace": schema.Int64Attribute{ + "java_maxmetaspace": schema.Int32Attribute{ Description: parametersDescriptions["java_maxmetaspace"], Optional: true, Computed: true, }, - "max_disk_threshold": schema.Int64Attribute{ + "max_disk_threshold": schema.Int32Attribute{ Description: parametersDescriptions["max_disk_threshold"], Optional: true, Computed: true, }, - "metrics_frequency": schema.Int64Attribute{ + "metrics_frequency": schema.Int32Attribute{ Description: parametersDescriptions["metrics_frequency"], Optional: true, Computed: true, @@ -417,7 +419,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques return } // Create new instance - createResp, err := r.client.CreateInstance(ctx, projectId).CreateInstancePayload(*payload).Execute() + createResp, err := r.client.DefaultAPI.CreateInstance(ctx, projectId).CreateInstancePayload(*payload).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", fmt.Sprintf("Calling API: %v", err)) return @@ -425,7 +427,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques ctx = core.LogResponse(ctx) - instanceId := *createResp.InstanceId + instanceId := createResp.InstanceId // Write id attributes to state before polling via the wait handler - just in case anything goes wrong during the wait handler ctx = utils.SetAndLogStateFields(ctx, &resp.Diagnostics, &resp.State, map[string]any{ "project_id": projectId, @@ -435,7 +437,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques return } - waitResp, err := wait.CreateInstanceWaitHandler(ctx, r.client, projectId, instanceId).SetTimeout(90 * time.Minute).WaitWithContext(ctx) + waitResp, err := wait.CreateInstanceWaitHandler(ctx, r.client.DefaultAPI, projectId, instanceId).SetTimeout(90 * time.Minute).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", fmt.Sprintf("Instance creation waiting: %v", err)) return @@ -473,7 +475,7 @@ func (r *instanceResource) Read(ctx context.Context, req resource.ReadRequest, r ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "instance_id", instanceId) - instanceResp, err := r.client.GetInstance(ctx, projectId, instanceId).Execute() + instanceResp, err := r.client.DefaultAPI.GetInstance(ctx, projectId, instanceId).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 || oapiErr.StatusCode == http.StatusGone) { @@ -548,7 +550,7 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques return } // Update existing instance - err = r.client.PartialUpdateInstance(ctx, projectId, instanceId).PartialUpdateInstancePayload(*payload).Execute() + err = r.client.DefaultAPI.PartialUpdateInstance(ctx, projectId, instanceId).PartialUpdateInstancePayload(*payload).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", fmt.Sprintf("Calling API: %v", err)) return @@ -556,7 +558,7 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques ctx = core.LogResponse(ctx) - waitResp, err := wait.PartialUpdateInstanceWaitHandler(ctx, r.client, projectId, instanceId).WaitWithContext(ctx) + waitResp, err := wait.PartialUpdateInstanceWaitHandler(ctx, r.client.DefaultAPI, projectId, instanceId).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", fmt.Sprintf("Instance update waiting: %v", err)) return @@ -595,7 +597,7 @@ func (r *instanceResource) Delete(ctx context.Context, req resource.DeleteReques ctx = tflog.SetField(ctx, "instance_id", instanceId) // Delete existing instance - err := r.client.DeleteInstance(ctx, projectId, instanceId).Execute() + err := r.client.DefaultAPI.DeleteInstance(ctx, projectId, instanceId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting instance", fmt.Sprintf("Calling API: %v", err)) return @@ -603,7 +605,7 @@ func (r *instanceResource) Delete(ctx context.Context, req resource.DeleteReques ctx = core.LogResponse(ctx) - _, err = wait.DeleteInstanceWaitHandler(ctx, r.client, projectId, instanceId).WaitWithContext(ctx) + _, err = wait.DeleteInstanceWaitHandler(ctx, r.client.DefaultAPI, projectId, instanceId).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting instance", fmt.Sprintf("Instance deletion waiting: %v", err)) return @@ -631,7 +633,7 @@ func (r *instanceResource) ImportState(ctx context.Context, req resource.ImportS tflog.Info(ctx, "LogMe instance state imported") } -func mapFields(instance *logme.Instance, model *Model) error { +func mapFields(instance *logmeSdk.Instance, model *Model) error { if instance == nil { return fmt.Errorf("response input is nil") } @@ -650,18 +652,18 @@ func mapFields(instance *logme.Instance, model *Model) error { model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), instanceId) model.InstanceId = types.StringValue(instanceId) - model.PlanId = types.StringPointerValue(instance.PlanId) - model.CfGuid = types.StringPointerValue(instance.CfGuid) - model.CfSpaceGuid = types.StringPointerValue(instance.CfSpaceGuid) - model.DashboardUrl = types.StringPointerValue(instance.DashboardUrl) - model.ImageUrl = types.StringPointerValue(instance.ImageUrl) - model.Name = types.StringPointerValue(instance.Name) - model.CfOrganizationGuid = types.StringPointerValue(instance.CfOrganizationGuid) + model.PlanId = types.StringValue(instance.PlanId) + model.CfGuid = types.StringValue(instance.CfGuid) + model.CfSpaceGuid = types.StringValue(instance.CfSpaceGuid) + model.DashboardUrl = types.StringValue(instance.DashboardUrl) + model.ImageUrl = types.StringValue(instance.ImageUrl) + model.Name = types.StringValue(instance.Name) + model.CfOrganizationGuid = types.StringValue(instance.CfOrganizationGuid) if instance.Parameters == nil { model.Parameters = types.ObjectNull(parametersTypes) } else { - parameters, err := mapParameters(*instance.Parameters) + parameters, err := mapParameters(instance.Parameters) if err != nil { return fmt.Errorf("mapping parameters: %w", err) } @@ -726,26 +728,44 @@ func mapParameters(params map[string]any) (types.Object, error) { } value = types.BoolValue(valueBool) } - case basetypes.Int64Type: + case basetypes.Int32Type: if valueInterface == nil { - value = types.Int64Null() + value = types.Int32Null() } else { // This may be int64, int32, int or float64 // We try to assert all 4 - var valueInt64 int64 + var valueInt32 int32 switch temp := valueInterface.(type) { default: return types.ObjectNull(parametersTypes), fmt.Errorf("found attribute '%s' of type %T, failed to assert as int", attribute, valueInterface) - case int64: - valueInt64 = temp case int32: - valueInt64 = int64(temp) + valueInt32 = temp case int: - valueInt64 = int64(temp) + // check overflow + if temp > math.MaxInt32 || temp < math.MinInt32 { + return types.ObjectNull(parametersTypes), fmt.Errorf("found attribute '%s' of type %T, overflow detected", attribute, valueInterface) + } + valueInt32 = int32(temp) + case float64: + valueInt32 = int32(temp) + } + value = types.Int32Value(valueInt32) + } + + case basetypes.Float32Type: + if valueInterface == nil { + value = types.Float32Null() + } else { + var valueFloat32 float32 + switch temp := valueInterface.(type) { + default: + return types.ObjectNull(parametersTypes), fmt.Errorf("found attribute '%s' of type %T, failed to assert as int", attribute, valueInterface) + case float32: + valueFloat32 = temp case float64: - valueInt64 = int64(temp) + valueFloat32 = float32(temp) } - value = types.Int64Value(valueInt64) + value = types.Float32Value(valueFloat32) } case basetypes.Float64Type: if valueInterface == nil { @@ -755,6 +775,8 @@ func mapParameters(params map[string]any) (types.Object, error) { switch temp := valueInterface.(type) { default: return types.ObjectNull(parametersTypes), fmt.Errorf("found attribute '%s' of type %T, failed to assert as int", attribute, valueInterface) + case float32: + valueFloat64 = float64(temp) case float64: valueFloat64 = float64(temp) } @@ -800,7 +822,7 @@ func mapParameters(params map[string]any) (types.Object, error) { return output, nil } -func toCreatePayload(model *Model, parameters *parametersModel) (*logme.CreateInstancePayload, error) { +func toCreatePayload(model *Model, parameters *parametersModel) (*logmeSdk.CreateInstancePayload, error) { if model == nil { return nil, fmt.Errorf("nil model") } @@ -810,14 +832,14 @@ func toCreatePayload(model *Model, parameters *parametersModel) (*logme.CreateIn return nil, fmt.Errorf("convert parameters: %w", err) } - return &logme.CreateInstancePayload{ - InstanceName: conversion.StringValueToPointer(model.Name), + return &logmeSdk.CreateInstancePayload{ + InstanceName: model.Name.ValueString(), Parameters: payloadParams, - PlanId: conversion.StringValueToPointer(model.PlanId), + PlanId: model.PlanId.ValueString(), }, nil } -func toUpdatePayload(model *Model, parameters *parametersModel) (*logme.PartialUpdateInstancePayload, error) { +func toUpdatePayload(model *Model, parameters *parametersModel) (*logmeSdk.PartialUpdateInstancePayload, error) { if model == nil { return nil, fmt.Errorf("nil model") } @@ -827,50 +849,50 @@ func toUpdatePayload(model *Model, parameters *parametersModel) (*logme.PartialU return nil, fmt.Errorf("convert parameters: %w", err) } - return &logme.PartialUpdateInstancePayload{ + return &logmeSdk.PartialUpdateInstancePayload{ Parameters: payloadParams, PlanId: conversion.StringValueToPointer(model.PlanId), }, nil } -func toInstanceParams(parameters *parametersModel) (*logme.InstanceParameters, error) { +func toInstanceParams(parameters *parametersModel) (*logmeSdk.InstanceParameters, error) { if parameters == nil { return nil, nil } - payloadParams := &logme.InstanceParameters{} + payloadParams := &logmeSdk.InstanceParameters{} payloadParams.SgwAcl = conversion.StringValueToPointer(parameters.SgwAcl) payloadParams.EnableMonitoring = conversion.BoolValueToPointer(parameters.EnableMonitoring) - payloadParams.FluentdTcp = conversion.Int64ValueToPointer(parameters.FluentdTcp) - payloadParams.FluentdTls = conversion.Int64ValueToPointer(parameters.FluentdTls) + payloadParams.FluentdTcp = conversion.Int32ValueToPointer(parameters.FluentdTcp) + payloadParams.FluentdTls = conversion.Int32ValueToPointer(parameters.FluentdTls) payloadParams.FluentdTlsCiphers = conversion.StringValueToPointer(parameters.FluentdTlsCiphers) payloadParams.FluentdTlsMaxVersion = conversion.StringValueToPointer(parameters.FluentdTlsMaxVersion) payloadParams.FluentdTlsMinVersion = conversion.StringValueToPointer(parameters.FluentdTlsMinVersion) payloadParams.FluentdTlsVersion = conversion.StringValueToPointer(parameters.FluentdTlsVersion) - payloadParams.FluentdUdp = conversion.Int64ValueToPointer(parameters.FluentdUdp) + payloadParams.FluentdUdp = conversion.Int32ValueToPointer(parameters.FluentdUdp) payloadParams.Graphite = conversion.StringValueToPointer(parameters.Graphite) payloadParams.IsmDeletionAfter = conversion.StringValueToPointer(parameters.IsmDeletionAfter) - payloadParams.IsmJitter = conversion.Float64ValueToPointer(parameters.IsmJitter) - payloadParams.IsmJobInterval = conversion.Int64ValueToPointer(parameters.IsmJobInterval) - payloadParams.JavaHeapspace = conversion.Int64ValueToPointer(parameters.JavaHeapspace) - payloadParams.JavaMaxmetaspace = conversion.Int64ValueToPointer(parameters.JavaMaxmetaspace) - payloadParams.MaxDiskThreshold = conversion.Int64ValueToPointer(parameters.MaxDiskThreshold) - payloadParams.MetricsFrequency = conversion.Int64ValueToPointer(parameters.MetricsFrequency) + payloadParams.IsmJitter = conversion.Float32ValueToPointer(parameters.IsmJitter) + payloadParams.IsmJobInterval = conversion.Int32ValueToPointer(parameters.IsmJobInterval) + payloadParams.JavaHeapspace = conversion.Int32ValueToPointer(parameters.JavaHeapspace) + payloadParams.JavaMaxmetaspace = conversion.Int32ValueToPointer(parameters.JavaMaxmetaspace) + payloadParams.MaxDiskThreshold = conversion.Int32ValueToPointer(parameters.MaxDiskThreshold) + payloadParams.MetricsFrequency = conversion.Int32ValueToPointer(parameters.MetricsFrequency) payloadParams.MetricsPrefix = conversion.StringValueToPointer(parameters.MetricsPrefix) payloadParams.MonitoringInstanceId = conversion.StringValueToPointer(parameters.MonitoringInstanceId) var err error - payloadParams.OpensearchTlsCiphers, err = conversion.StringListToPointer(parameters.OpensearchTlsCiphers) + payloadParams.OpensearchTlsCiphers, err = conversion.StringListToSlice(parameters.OpensearchTlsCiphers) if err != nil { return nil, fmt.Errorf("convert opensearch_tls_ciphers: %w", err) } - payloadParams.OpensearchTlsProtocols, err = conversion.StringListToPointer(parameters.OpensearchTlsProtocols) + payloadParams.OpensearchTlsProtocols, err = conversion.StringListToSlice(parameters.OpensearchTlsProtocols) if err != nil { return nil, fmt.Errorf("convert opensearch_tls_protocols: %w", err) } - payloadParams.Syslog, err = conversion.StringListToPointer(parameters.Syslog) + payloadParams.Syslog, err = conversion.StringListToSlice(parameters.Syslog) if err != nil { return nil, fmt.Errorf("convert syslog: %w", err) } @@ -880,7 +902,7 @@ func toInstanceParams(parameters *parametersModel) (*logme.InstanceParameters, e func (r *instanceResource) loadPlanId(ctx context.Context, model *Model) error { projectId := model.ProjectId.ValueString() - res, err := r.client.ListOfferings(ctx, projectId).Execute() + res, err := r.client.DefaultAPI.ListOfferings(ctx, projectId).Execute() if err != nil { return fmt.Errorf("getting LogMe offerings: %w", err) } @@ -890,22 +912,22 @@ func (r *instanceResource) loadPlanId(ctx context.Context, model *Model) error { availableVersions := "" availablePlanNames := "" isValidVersion := false - for _, offer := range *res.Offerings { - if !strings.EqualFold(*offer.Version, version) { - availableVersions = fmt.Sprintf("%s\n- %s", availableVersions, *offer.Version) + for _, offer := range res.Offerings { + if !strings.EqualFold(offer.Version, version) { + availableVersions = fmt.Sprintf("%s\n- %s", availableVersions, offer.Version) continue } isValidVersion = true - for _, plan := range *offer.Plans { - if plan.Name == nil { + for _, plan := range offer.Plans { + if plan.Name == "" { continue } - if strings.EqualFold(*plan.Name, planName) && plan.Id != nil { - model.PlanId = types.StringPointerValue(plan.Id) + if strings.EqualFold(plan.Name, planName) && plan.Id != "" { + model.PlanId = types.StringValue(plan.Id) return nil } - availablePlanNames = fmt.Sprintf("%s\n- %s", availablePlanNames, *plan.Name) + availablePlanNames = fmt.Sprintf("%s\n- %s", availablePlanNames, plan.Name) } } @@ -915,19 +937,19 @@ func (r *instanceResource) loadPlanId(ctx context.Context, model *Model) error { return fmt.Errorf("couldn't find plan_name '%s' for version %s, available names are: %s", planName, version, availablePlanNames) } -func loadPlanNameAndVersion(ctx context.Context, client *logme.APIClient, model *Model) error { +func loadPlanNameAndVersion(ctx context.Context, client *logmeSdk.APIClient, model *Model) error { projectId := model.ProjectId.ValueString() planId := model.PlanId.ValueString() - res, err := client.ListOfferings(ctx, projectId).Execute() + res, err := client.DefaultAPI.ListOfferings(ctx, projectId).Execute() if err != nil { return fmt.Errorf("getting LogMe offerings: %w", err) } - for _, offer := range *res.Offerings { - for _, plan := range *offer.Plans { - if strings.EqualFold(*plan.Id, planId) && plan.Id != nil { - model.PlanName = types.StringPointerValue(plan.Name) - model.Version = types.StringPointerValue(offer.Version) + for _, offer := range res.Offerings { + for _, plan := range offer.Plans { + if strings.EqualFold(plan.Id, planId) && plan.Id != "" { + model.PlanName = types.StringValue(plan.Name) + model.Version = types.StringValue(offer.Version) return nil } } diff --git a/stackit/internal/services/logme/instance/resource_test.go b/stackit/internal/services/logme/instance/resource_test.go index dce893f7b..770011fc3 100644 --- a/stackit/internal/services/logme/instance/resource_test.go +++ b/stackit/internal/services/logme/instance/resource_test.go @@ -8,27 +8,27 @@ import ( "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - "github.com/stackitcloud/stackit-sdk-go/services/logme" + logmeSdk "github.com/stackitcloud/stackit-sdk-go/services/logme/v1api" ) var fixtureModelParameters = types.ObjectValueMust(parametersTypes, map[string]attr.Value{ "sgw_acl": types.StringValue("acl"), "enable_monitoring": types.BoolValue(true), - "fluentd_tcp": types.Int64Value(10), - "fluentd_tls": types.Int64Value(10), + "fluentd_tcp": types.Int32Value(10), + "fluentd_tls": types.Int32Value(10), "fluentd_tls_ciphers": types.StringValue("ciphers"), "fluentd_tls_max_version": types.StringValue("max_version"), "fluentd_tls_min_version": types.StringValue("min_version"), "fluentd_tls_version": types.StringValue("version"), - "fluentd_udp": types.Int64Value(10), + "fluentd_udp": types.Int32Value(10), "graphite": types.StringValue("graphite"), "ism_deletion_after": types.StringValue("deletion_after"), - "ism_jitter": types.Float64Value(10.1), - "ism_job_interval": types.Int64Value(10), - "java_heapspace": types.Int64Value(10), - "java_maxmetaspace": types.Int64Value(10), - "max_disk_threshold": types.Int64Value(10), - "metrics_frequency": types.Int64Value(10), + "ism_jitter": types.Float32Value(10.1), + "ism_job_interval": types.Int32Value(10), + "java_heapspace": types.Int32Value(10), + "java_maxmetaspace": types.Int32Value(10), + "max_disk_threshold": types.Int32Value(10), + "metrics_frequency": types.Int32Value(10), "metrics_prefix": types.StringValue("prefix"), "monitoring_instance_id": types.StringValue("mid"), "opensearch_tls_ciphers": types.ListValueMust(types.StringType, []attr.Value{ @@ -48,21 +48,21 @@ var fixtureModelParameters = types.ObjectValueMust(parametersTypes, map[string]a var fixtureNullModelParameters = types.ObjectValueMust(parametersTypes, map[string]attr.Value{ "sgw_acl": types.StringNull(), "enable_monitoring": types.BoolNull(), - "fluentd_tcp": types.Int64Null(), - "fluentd_tls": types.Int64Null(), + "fluentd_tcp": types.Int32Null(), + "fluentd_tls": types.Int32Null(), "fluentd_tls_ciphers": types.StringNull(), "fluentd_tls_max_version": types.StringNull(), "fluentd_tls_min_version": types.StringNull(), "fluentd_tls_version": types.StringNull(), - "fluentd_udp": types.Int64Null(), + "fluentd_udp": types.Int32Null(), "graphite": types.StringNull(), "ism_deletion_after": types.StringNull(), - "ism_jitter": types.Float64Null(), - "ism_job_interval": types.Int64Null(), - "java_heapspace": types.Int64Null(), - "java_maxmetaspace": types.Int64Null(), - "max_disk_threshold": types.Int64Null(), - "metrics_frequency": types.Int64Null(), + "ism_jitter": types.Float32Null(), + "ism_job_interval": types.Int32Null(), + "java_heapspace": types.Int32Null(), + "java_maxmetaspace": types.Int32Null(), + "max_disk_threshold": types.Int32Null(), + "metrics_frequency": types.Int32Null(), "metrics_prefix": types.StringNull(), "monitoring_instance_id": types.StringNull(), "opensearch_tls_ciphers": types.ListNull(types.StringType), @@ -70,68 +70,69 @@ var fixtureNullModelParameters = types.ObjectValueMust(parametersTypes, map[stri "syslog": types.ListNull(types.StringType), }) -var fixtureInstanceParameters = logme.InstanceParameters{ +var fixtureInstanceParameters = logmeSdk.InstanceParameters{ SgwAcl: new("acl"), EnableMonitoring: new(true), - FluentdTcp: new(int64(10)), - FluentdTls: new(int64(10)), + FluentdTcp: new(int32(10)), + FluentdTls: new(int32(10)), FluentdTlsCiphers: new("ciphers"), FluentdTlsMaxVersion: new("max_version"), FluentdTlsMinVersion: new("min_version"), FluentdTlsVersion: new("version"), - FluentdUdp: new(int64(10)), + FluentdUdp: new(int32(10)), Graphite: new("graphite"), IsmDeletionAfter: new("deletion_after"), - IsmJitter: new(10.1), - IsmJobInterval: new(int64(10)), - JavaHeapspace: new(int64(10)), - JavaMaxmetaspace: new(int64(10)), - MaxDiskThreshold: new(int64(10)), - MetricsFrequency: new(int64(10)), + IsmJitter: new(float32(10.1)), + IsmJobInterval: new(int32(10)), + JavaHeapspace: new(int32(10)), + JavaMaxmetaspace: new(int32(10)), + MaxDiskThreshold: new(int32(10)), + MetricsFrequency: new(int32(10)), MetricsPrefix: new("prefix"), MonitoringInstanceId: new("mid"), - OpensearchTlsCiphers: &[]string{"ciphers", "ciphers2"}, - OpensearchTlsProtocols: &[]string{"protocols", "protocols2"}, - Syslog: &[]string{"syslog", "syslog2"}, + OpensearchTlsCiphers: []string{"ciphers", "ciphers2"}, + OpensearchTlsProtocols: []string{"protocols", "protocols2"}, + Syslog: []string{"syslog", "syslog2"}, } func TestMapFields(t *testing.T) { tests := []struct { description string - input *logme.Instance + input *logmeSdk.Instance expected Model isValid bool }{ { "default_values", - &logme.Instance{}, + &logmeSdk.Instance{}, Model{ Id: types.StringValue("pid,iid"), InstanceId: types.StringValue("iid"), ProjectId: types.StringValue("pid"), - PlanId: types.StringNull(), - Name: types.StringNull(), - CfGuid: types.StringNull(), - CfSpaceGuid: types.StringNull(), - DashboardUrl: types.StringNull(), - ImageUrl: types.StringNull(), - CfOrganizationGuid: types.StringNull(), + PlanId: types.StringValue(""), + Name: types.StringValue(""), + CfGuid: types.StringValue(""), + CfSpaceGuid: types.StringValue(""), + DashboardUrl: types.StringValue(""), + ImageUrl: types.StringValue(""), + CfOrganizationGuid: types.StringValue(""), Parameters: types.ObjectNull(parametersTypes), }, true, }, + { "simple_values", - &logme.Instance{ - PlanId: new("plan"), - CfGuid: new("cf"), - CfSpaceGuid: new("space"), - DashboardUrl: new("dashboard"), - ImageUrl: new("image"), + &logmeSdk.Instance{ + PlanId: "plan", + CfGuid: "cf", + CfSpaceGuid: "space", + DashboardUrl: "dashboard", + ImageUrl: "image", InstanceId: new("iid"), - Name: new("name"), - CfOrganizationGuid: new("org"), - Parameters: &map[string]any{ + Name: "name", + CfOrganizationGuid: "org", + Parameters: map[string]any{ // Using "-" on purpose on some fields because that is the API response "sgw_acl": "acl", "enable_monitoring": true, @@ -180,14 +181,14 @@ func TestMapFields(t *testing.T) { }, { "no_resource_id", - &logme.Instance{}, + &logmeSdk.Instance{}, Model{}, false, }, { "wrong_param_types_1", - &logme.Instance{ - Parameters: &map[string]any{ + &logmeSdk.Instance{ + Parameters: map[string]any{ "sgw_acl": true, }, }, @@ -196,8 +197,8 @@ func TestMapFields(t *testing.T) { }, { "wrong_param_types_2", - &logme.Instance{ - Parameters: &map[string]any{ + &logmeSdk.Instance{ + Parameters: map[string]any{ "sgw_acl": 1, }, }, @@ -232,13 +233,13 @@ func TestToCreatePayload(t *testing.T) { tests := []struct { description string input *Model - expected *logme.CreateInstancePayload + expected *logmeSdk.CreateInstancePayload isValid bool }{ { "default_values", &Model{}, - &logme.CreateInstancePayload{}, + &logmeSdk.CreateInstancePayload{}, true, }, { @@ -248,9 +249,9 @@ func TestToCreatePayload(t *testing.T) { PlanId: types.StringValue("plan"), Parameters: fixtureModelParameters, }, - &logme.CreateInstancePayload{ - InstanceName: new("name"), - PlanId: new("plan"), + &logmeSdk.CreateInstancePayload{ + InstanceName: "name", + PlanId: "plan", Parameters: &fixtureInstanceParameters, }, true, @@ -262,10 +263,10 @@ func TestToCreatePayload(t *testing.T) { PlanId: types.StringValue(""), Parameters: fixtureNullModelParameters, }, - &logme.CreateInstancePayload{ - InstanceName: new(""), - PlanId: new(""), - Parameters: &logme.InstanceParameters{}, + &logmeSdk.CreateInstancePayload{ + InstanceName: "", + PlanId: "", + Parameters: &logmeSdk.InstanceParameters{}, }, true, }, @@ -281,9 +282,9 @@ func TestToCreatePayload(t *testing.T) { Name: types.StringValue("name"), PlanId: types.StringValue("plan"), }, - &logme.CreateInstancePayload{ - InstanceName: new("name"), - PlanId: new("plan"), + &logmeSdk.CreateInstancePayload{ + InstanceName: "name", + PlanId: "plan", }, true, }, @@ -321,13 +322,13 @@ func TestToUpdatePayload(t *testing.T) { tests := []struct { description string input *Model - expected *logme.PartialUpdateInstancePayload + expected *logmeSdk.PartialUpdateInstancePayload isValid bool }{ { "default_values", &Model{}, - &logme.PartialUpdateInstancePayload{}, + &logmeSdk.PartialUpdateInstancePayload{}, true, }, { @@ -336,7 +337,7 @@ func TestToUpdatePayload(t *testing.T) { PlanId: types.StringValue("plan"), Parameters: fixtureModelParameters, }, - &logme.PartialUpdateInstancePayload{ + &logmeSdk.PartialUpdateInstancePayload{ Parameters: &fixtureInstanceParameters, PlanId: new("plan"), }, @@ -348,8 +349,8 @@ func TestToUpdatePayload(t *testing.T) { PlanId: types.StringValue(""), Parameters: fixtureNullModelParameters, }, - &logme.PartialUpdateInstancePayload{ - Parameters: &logme.InstanceParameters{}, + &logmeSdk.PartialUpdateInstancePayload{ + Parameters: &logmeSdk.InstanceParameters{}, PlanId: new(""), }, true, @@ -365,7 +366,7 @@ func TestToUpdatePayload(t *testing.T) { &Model{ PlanId: types.StringValue("plan"), }, - &logme.PartialUpdateInstancePayload{ + &logmeSdk.PartialUpdateInstancePayload{ PlanId: new("plan"), }, true, diff --git a/stackit/internal/services/logme/logme_acc_test.go b/stackit/internal/services/logme/logme_acc_test.go index 491c09273..53312bdb8 100644 --- a/stackit/internal/services/logme/logme_acc_test.go +++ b/stackit/internal/services/logme/logme_acc_test.go @@ -13,10 +13,11 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/stackitcloud/stackit-sdk-go/core/utils" - "github.com/stackitcloud/stackit-sdk-go/services/logme" - "github.com/stackitcloud/stackit-sdk-go/services/logme/wait" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/testutil" + + logmeSdk "github.com/stackitcloud/stackit-sdk-go/services/logme/v1api" + "github.com/stackitcloud/stackit-sdk-go/services/logme/v1api/wait" ) var ( @@ -421,7 +422,7 @@ func TestAccLogMeMaxResource(t *testing.T) { func testAccCheckLogMeDestroy(s *terraform.State) error { ctx := context.Background() - client, err := logme.NewAPIClient(testutil.NewConfigBuilder().BuildClientOptions(testutil.LogMeCustomEndpoint, true)...) + client, err := logmeSdk.NewAPIClient(testutil.NewConfigBuilder().BuildClientOptions(testutil.LogMeCustomEndpoint, true)...) if err != nil { return fmt.Errorf("creating client: %w", err) } @@ -436,23 +437,23 @@ func testAccCheckLogMeDestroy(s *terraform.State) error { instancesToDestroy = append(instancesToDestroy, instanceId) } - instancesResp, err := client.ListInstances(ctx, testutil.ProjectId).Execute() + instancesResp, err := client.DefaultAPI.ListInstances(ctx, testutil.ProjectId).Execute() if err != nil { return fmt.Errorf("getting instancesResp: %w", err) } - instances := *instancesResp.Instances + instances := instancesResp.Instances for i := range instances { if instances[i].InstanceId == nil { continue } if utils.Contains(instancesToDestroy, *instances[i].InstanceId) { if !checkInstanceDeleteSuccess(&instances[i]) { - err := client.DeleteInstanceExecute(ctx, testutil.ProjectId, *instances[i].InstanceId) + err := client.DefaultAPI.DeleteInstance(ctx, testutil.ProjectId, *instances[i].InstanceId).Execute() if err != nil { return fmt.Errorf("destroying instance %s during CheckDestroy: %w", *instances[i].InstanceId, err) } - _, err = wait.DeleteInstanceWaitHandler(ctx, client, testutil.ProjectId, *instances[i].InstanceId).WaitWithContext(ctx) + _, err = wait.DeleteInstanceWaitHandler(ctx, client.DefaultAPI, testutil.ProjectId, *instances[i].InstanceId).WaitWithContext(ctx) if err != nil { return fmt.Errorf("destroying instance %s during CheckDestroy: waiting for deletion %w", *instances[i].InstanceId, err) } @@ -462,15 +463,13 @@ func testAccCheckLogMeDestroy(s *terraform.State) error { return nil } -func checkInstanceDeleteSuccess(i *logme.Instance) bool { - if *i.LastOperation.Type != logme.INSTANCELASTOPERATIONTYPE_DELETE { +func checkInstanceDeleteSuccess(i *logmeSdk.Instance) bool { + if i.LastOperation.Type != wait.INSTANCESTATUS_DELETING { return false } - if *i.LastOperation.Type == logme.INSTANCELASTOPERATIONTYPE_DELETE { - if *i.LastOperation.State != logme.INSTANCELASTOPERATIONSTATE_SUCCEEDED { - return false - } else if strings.Contains(*i.LastOperation.Description, "DeleteFailed") || strings.Contains(*i.LastOperation.Description, "failed") { + if i.LastOperation.Type == wait.INSTANCESTATUS_DELETING { + if strings.Contains(i.LastOperation.Description, "DeleteFailed") || strings.Contains(i.LastOperation.Description, "failed") { return false } } diff --git a/stackit/internal/services/logme/utils/util.go b/stackit/internal/services/logme/utils/util.go index 6da59478a..488e101cc 100644 --- a/stackit/internal/services/logme/utils/util.go +++ b/stackit/internal/services/logme/utils/util.go @@ -6,12 +6,12 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/stackitcloud/stackit-sdk-go/core/config" - "github.com/stackitcloud/stackit-sdk-go/services/logme" + logmeSdk "github.com/stackitcloud/stackit-sdk-go/services/logme/v1api" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils" ) -func ConfigureClient(ctx context.Context, providerData *core.ProviderData, diags *diag.Diagnostics) *logme.APIClient { +func ConfigureClient(ctx context.Context, providerData *core.ProviderData, diags *diag.Diagnostics) *logmeSdk.APIClient { apiClientConfigOptions := []config.ConfigurationOption{ config.WithCustomAuth(providerData.RoundTripper), utils.UserAgentConfigOption(providerData.Version), @@ -21,7 +21,7 @@ func ConfigureClient(ctx context.Context, providerData *core.ProviderData, diags } else { apiClientConfigOptions = append(apiClientConfigOptions, config.WithRegion(providerData.GetRegion())) } - apiClient, err := logme.NewAPIClient(apiClientConfigOptions...) + apiClient, err := logmeSdk.NewAPIClient(apiClientConfigOptions...) if err != nil { core.LogAndAddError(ctx, diags, "Error configuring API client", fmt.Sprintf("Configuring client: %v. This is an error related to the provider configuration, not to the resource configuration", err)) return nil diff --git a/stackit/internal/services/logme/utils/util_test.go b/stackit/internal/services/logme/utils/util_test.go index 9fa901993..76e0ab053 100644 --- a/stackit/internal/services/logme/utils/util_test.go +++ b/stackit/internal/services/logme/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/logme" + logmeSdk "github.com/stackitcloud/stackit-sdk-go/services/logme/v1api" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils" ) @@ -34,7 +34,7 @@ func TestConfigureClient(t *testing.T) { name string args args wantErr bool - expected *logme.APIClient + expected *logmeSdk.APIClient }{ { name: "default endpoint", @@ -43,8 +43,8 @@ func TestConfigureClient(t *testing.T) { Version: testVersion, }, }, - expected: func() *logme.APIClient { - apiClient, err := logme.NewAPIClient( + expected: func() *logmeSdk.APIClient { + apiClient, err := logmeSdk.NewAPIClient( config.WithRegion("eu01"), utils.UserAgentConfigOption(testVersion), ) @@ -63,8 +63,8 @@ func TestConfigureClient(t *testing.T) { LogMeCustomEndpoint: testCustomEndpoint, }, }, - expected: func() *logme.APIClient { - apiClient, err := logme.NewAPIClient( + expected: func() *logmeSdk.APIClient { + apiClient, err := logmeSdk.NewAPIClient( utils.UserAgentConfigOption(testVersion), config.WithEndpoint(testCustomEndpoint), )