From 3c33859ceadebc2b6dbd80bc451b4320e41f23fd Mon Sep 17 00:00:00 2001 From: GokceGK Date: Tue, 14 Apr 2026 09:28:24 +0200 Subject: [PATCH 1/3] chore(rabbitmq): use new multi API version support SDK --- go.mod | 2 +- go.sum | 2 + .../rabbitmq/credential/datasource.go | 6 +- .../services/rabbitmq/credential/resource.go | 91 +++++++------ .../rabbitmq/credential/resource_test.go | 74 +++++------ .../services/rabbitmq/instance/datasource.go | 10 +- .../services/rabbitmq/instance/resource.go | 122 +++++++++--------- .../rabbitmq/instance/resource_test.go | 76 +++++------ .../services/rabbitmq/rabbitmq_acc_test.go | 26 ++-- .../services/rabbitmq/rabbitmq_test.go | 24 ++-- .../internal/services/rabbitmq/utils/util.go | 2 +- .../services/rabbitmq/utils/util_test.go | 2 +- 12 files changed, 214 insertions(+), 223 deletions(-) diff --git a/go.mod b/go.mod index e8642e903..520bd5cb6 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,7 @@ require ( github.com/stackitcloud/stackit-sdk-go/services/observability v0.17.0 github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.26.1 github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.3.5 - github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.26.0 + github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.29.0 github.com/stackitcloud/stackit-sdk-go/services/redis v0.25.6 github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.20.0 github.com/stackitcloud/stackit-sdk-go/services/scf v0.6.1 diff --git a/go.sum b/go.sum index fd9cc7534..5a6094b40 100644 --- a/go.sum +++ b/go.sum @@ -193,6 +193,8 @@ github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.3.5 h1:H67e3KnHQ github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.3.5/go.mod h1:xmAWk9eom8wznvLuLfm0F4xyeiBX8LaggXsKFmos+dw= github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.26.0 h1:/8lmviszgrB+0Cz7HdhFELyTiTeqIs7LfnI6sNX4rW8= github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.26.0/go.mod h1:hnhvlLX1Y71R8KIQqLBeoSZqkU5ZJOG0J4wz0LeUdaw= +github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.29.0 h1:I8NF8Q5nRj7/7qDI8Qm4oI0KCNQcOjE6kqyBdWcUoxk= +github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.29.0/go.mod h1:wk2Oz+7pxT9YF1h6elWzdlhU6V7GSQXcGixxlXxNe+U= github.com/stackitcloud/stackit-sdk-go/services/redis v0.25.6 h1:CXM9cZ9WeTyJd+Aw/hnJnDsKRVAQi4qgtd0RJ3zoPwo= github.com/stackitcloud/stackit-sdk-go/services/redis v0.25.6/go.mod h1:KJNceOHRefjku1oVBoHG7idCS/SeW42WJ+55bN3AxrQ= github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.20.0 h1:bT/qoghsdKvLomCay9Wj4Fu63lx0cD2zr23Fjqzgotc= diff --git a/stackit/internal/services/rabbitmq/credential/datasource.go b/stackit/internal/services/rabbitmq/credential/datasource.go index be84cf0ff..9876364ad 100644 --- a/stackit/internal/services/rabbitmq/credential/datasource.go +++ b/stackit/internal/services/rabbitmq/credential/datasource.go @@ -17,7 +17,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq" + rabbitmq "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq/v1api" ) // Ensure the implementation satisfies the expected interfaces. @@ -117,7 +117,7 @@ func (r *credentialDataSource) Schema(_ context.Context, _ datasource.SchemaRequ Computed: true, Sensitive: true, }, - "port": schema.Int64Attribute{ + "port": schema.Int32Attribute{ Computed: true, }, "uri": schema.StringAttribute{ @@ -153,7 +153,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/rabbitmq/credential/resource.go b/stackit/internal/services/rabbitmq/credential/resource.go index 50b5fecaa..6d6862d49 100644 --- a/stackit/internal/services/rabbitmq/credential/resource.go +++ b/stackit/internal/services/rabbitmq/credential/resource.go @@ -21,8 +21,8 @@ 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/rabbitmq" - "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq/wait" + rabbitmq "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq/v1api" + "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq/v1api/wait" ) // Ensure the implementation satisfies the expected interfaces. @@ -43,7 +43,7 @@ type Model struct { HttpAPIURIs types.List `tfsdk:"http_api_uris"` Management types.String `tfsdk:"management"` Password types.String `tfsdk:"password"` - Port types.Int64 `tfsdk:"port"` + Port types.Int32 `tfsdk:"port"` Uri types.String `tfsdk:"uri"` Uris types.List `tfsdk:"uris"` Username types.String `tfsdk:"username"` @@ -155,7 +155,7 @@ func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest, Computed: true, Sensitive: true, }, - "port": schema.Int64Attribute{ + "port": schema.Int32Attribute{ Computed: true, }, "uri": schema.StringAttribute{ @@ -190,7 +190,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 @@ -198,11 +198,11 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ ctx = core.LogResponse(ctx) - if credentialsResp.Id == nil { + if credentialsResp.Id == "" { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", "Got empty credential id") return } - credentialId := *credentialsResp.Id + credentialId := credentialsResp.Id ctx = utils.SetAndLogStateFields(ctx, &resp.Diagnostics, &resp.State, map[string]any{ "project_id": projectId, "instance_id": instanceId, @@ -212,7 +212,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 @@ -250,7 +250,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 { @@ -304,14 +304,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 @@ -357,8 +357,8 @@ func mapFields(ctx context.Context, credentialsResp *rabbitmq.CredentialsRespons 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") } @@ -384,51 +384,50 @@ func mapFields(ctx context.Context, credentialsResp *rabbitmq.CredentialsRespons model.Hosts = types.ListNull(types.StringType) model.Uris = types.ListNull(types.StringType) model.HttpAPIURIs = types.ListNull(types.StringType) - if credentials != nil { - if credentials.Hosts != nil { - respHosts := *credentials.Hosts - reconciledHosts := utils.ReconcileStringSlices(modelHosts, respHosts) + if credentials.Hosts != nil { + respHosts := credentials.Hosts + reconciledHosts := utils.ReconcileStringSlices(modelHosts, respHosts) - hostsTF, diags := types.ListValueFrom(ctx, types.StringType, reconciledHosts) - if diags.HasError() { - return fmt.Errorf("failed to map hosts: %w", core.DiagsToError(diags)) - } - - model.Hosts = hostsTF + hostsTF, diags := types.ListValueFrom(ctx, types.StringType, reconciledHosts) + if diags.HasError() { + return fmt.Errorf("failed to map hosts: %w", core.DiagsToError(diags)) } - model.Host = types.StringPointerValue(credentials.Host) - if credentials.HttpApiUris != nil { - respHttpApiUris := *credentials.HttpApiUris - reconciledHttpApiUris := utils.ReconcileStringSlices(modelHttpApiUris, respHttpApiUris) + model.Hosts = hostsTF + } + model.Host = types.StringValue(credentials.Host) + if credentials.HttpApiUris != nil { + respHttpApiUris := credentials.HttpApiUris - httpApiUrisTF, diags := types.ListValueFrom(ctx, types.StringType, reconciledHttpApiUris) - if diags.HasError() { - return fmt.Errorf("failed to map httpApiUris: %w", core.DiagsToError(diags)) - } + reconciledHttpApiUris := utils.ReconcileStringSlices(modelHttpApiUris, respHttpApiUris) - model.HttpAPIURIs = httpApiUrisTF + httpApiUrisTF, diags := types.ListValueFrom(ctx, types.StringType, reconciledHttpApiUris) + if diags.HasError() { + return fmt.Errorf("failed to map httpApiUris: %w", core.DiagsToError(diags)) } - if credentials.Uris != nil { - respUris := *credentials.Uris + model.HttpAPIURIs = httpApiUrisTF + } - reconciledUris := utils.ReconcileStringSlices(modelUris, respUris) + if credentials.Uris != nil { + respUris := credentials.Uris - urisTF, diags := types.ListValueFrom(ctx, types.StringType, reconciledUris) - if diags.HasError() { - return fmt.Errorf("failed to map uris: %w", core.DiagsToError(diags)) - } + reconciledUris := utils.ReconcileStringSlices(modelUris, respUris) - model.Uris = urisTF + urisTF, diags := types.ListValueFrom(ctx, types.StringType, reconciledUris) + if diags.HasError() { + return fmt.Errorf("failed to map uris: %w", core.DiagsToError(diags)) } - model.HttpAPIURI = types.StringPointerValue(credentials.HttpApiUri) - model.Management = types.StringPointerValue(credentials.Management) - 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.Uris = urisTF } + + model.HttpAPIURI = types.StringPointerValue(credentials.HttpApiUri) + model.Management = types.StringPointerValue(credentials.Management) + 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/rabbitmq/credential/resource_test.go b/stackit/internal/services/rabbitmq/credential/resource_test.go index 06f5639a7..597b2ed64 100644 --- a/stackit/internal/services/rabbitmq/credential/resource_test.go +++ b/stackit/internal/services/rabbitmq/credential/resource_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq" + rabbitmq "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq/v1api" ) func TestMapFields(t *testing.T) { @@ -25,7 +25,7 @@ func TestMapFields(t *testing.T) { ProjectId: types.StringValue("pid"), }, &rabbitmq.CredentialsResponse{ - Id: new("cid"), + Id: "cid", Raw: &rabbitmq.RawCredentials{}, }, Model{ @@ -33,16 +33,16 @@ func TestMapFields(t *testing.T) { CredentialId: types.StringValue("cid"), InstanceId: types.StringValue("iid"), ProjectId: types.StringValue("pid"), - Host: types.StringNull(), + Host: types.StringValue(""), Hosts: types.ListNull(types.StringType), HttpAPIURI: types.StringNull(), HttpAPIURIs: types.ListNull(types.StringType), Management: types.StringNull(), - Password: types.StringNull(), - Port: types.Int64Null(), + Password: types.StringValue(""), + Port: types.Int32Null(), Uri: types.StringNull(), Uris: types.ListNull(types.StringType), - Username: types.StringNull(), + Username: types.StringValue(""), }, true, }, @@ -53,28 +53,28 @@ func TestMapFields(t *testing.T) { ProjectId: types.StringValue("pid"), }, &rabbitmq.CredentialsResponse{ - Id: new("cid"), + Id: "cid", Raw: &rabbitmq.RawCredentials{ - Credentials: &rabbitmq.Credentials{ - Host: new("host"), - Hosts: &[]string{ + Credentials: rabbitmq.Credentials{ + Host: "host", + Hosts: []string{ "host_1", "", }, HttpApiUri: new("http"), - HttpApiUris: &[]string{ + HttpApiUris: []string{ "http_api_uri_1", "", }, Management: new("management"), - Password: new("password"), - Port: new(int64(1234)), + Password: "password", + Port: new(int32(1234)), Uri: new("uri"), - Uris: &[]string{ + Uris: []string{ "uri_1", "", }, - Username: new("username"), + Username: "username", }, }, }, @@ -95,7 +95,7 @@ func TestMapFields(t *testing.T) { }), Management: types.StringValue("management"), Password: types.StringValue("password"), - Port: types.Int64Value(1234), + Port: types.Int32Value(1234), Uri: types.StringValue("uri"), Uris: types.ListValueMust(types.StringType, []attr.Value{ types.StringValue("uri_1"), @@ -127,31 +127,31 @@ func TestMapFields(t *testing.T) { }), }, &rabbitmq.CredentialsResponse{ - Id: new("cid"), + Id: "cid", Raw: &rabbitmq.RawCredentials{ - Credentials: &rabbitmq.Credentials{ - Host: new("host"), - Hosts: &[]string{ + Credentials: rabbitmq.Credentials{ + Host: "host", + Hosts: []string{ "", "host_1", "host_2", }, HttpApiUri: new("http"), - HttpApiUris: &[]string{ + HttpApiUris: []string{ "", "http_api_uri_1", "http_api_uri_2", }, Management: new("management"), - Password: new("password"), - Port: new(int64(1234)), + Password: "password", + Port: new(int32(1234)), Uri: new("uri"), - Uris: &[]string{ + Uris: []string{ "", "uri_1", "uri_2", }, - Username: new("username"), + Username: "username", }, }, }, @@ -174,7 +174,7 @@ func TestMapFields(t *testing.T) { }), Management: types.StringValue("management"), Password: types.StringValue("password"), - Port: types.Int64Value(1234), + Port: types.Int32Value(1234), Uri: types.StringValue("uri"), Uris: types.ListValueMust(types.StringType, []attr.Value{ types.StringValue("uri_2"), @@ -192,19 +192,19 @@ func TestMapFields(t *testing.T) { ProjectId: types.StringValue("pid"), }, &rabbitmq.CredentialsResponse{ - Id: new("cid"), + Id: "cid", Raw: &rabbitmq.RawCredentials{ - Credentials: &rabbitmq.Credentials{ - Host: new(""), - Hosts: &[]string{}, + Credentials: rabbitmq.Credentials{ + Host: "", + Hosts: []string{}, HttpApiUri: nil, - HttpApiUris: &[]string{}, + HttpApiUris: []string{}, Management: nil, - Password: new(""), - Port: new(int64(2123456789)), + Password: "", + Port: new(int32(2123456789)), Uri: nil, - Uris: &[]string{}, - Username: new(""), + Uris: []string{}, + Username: "", }, }, }, @@ -219,7 +219,7 @@ func TestMapFields(t *testing.T) { HttpAPIURIs: types.ListValueMust(types.StringType, []attr.Value{}), Management: types.StringNull(), Password: types.StringValue(""), - Port: types.Int64Value(2123456789), + Port: types.Int32Value(2123456789), Uri: types.StringNull(), Uris: types.ListValueMust(types.StringType, []attr.Value{}), Username: types.StringValue(""), @@ -253,7 +253,7 @@ func TestMapFields(t *testing.T) { ProjectId: types.StringValue("pid"), }, &rabbitmq.CredentialsResponse{ - Id: new("cid"), + Id: "cid", }, Model{}, false, diff --git a/stackit/internal/services/rabbitmq/instance/datasource.go b/stackit/internal/services/rabbitmq/instance/datasource.go index e7a7eded5..6332f6c5b 100644 --- a/stackit/internal/services/rabbitmq/instance/datasource.go +++ b/stackit/internal/services/rabbitmq/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/rabbitmq" + rabbitmq "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq/v1api" ) // Ensure the implementation satisfies the expected interfaces. @@ -129,7 +129,7 @@ func (r *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaReques Description: parametersDescriptions["sgw_acl"], Computed: true, }, - "consumer_timeout": schema.Int64Attribute{ + "consumer_timeout": schema.Int32Attribute{ Description: parametersDescriptions["consumer_timeout"], Computed: true, }, @@ -141,11 +141,11 @@ func (r *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaReques Description: parametersDescriptions["graphite"], 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, }, @@ -220,7 +220,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/rabbitmq/instance/resource.go b/stackit/internal/services/rabbitmq/instance/resource.go index 19f1c2e9c..93ad65cd1 100644 --- a/stackit/internal/services/rabbitmq/instance/resource.go +++ b/stackit/internal/services/rabbitmq/instance/resource.go @@ -25,8 +25,8 @@ 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/rabbitmq" - "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq/wait" + rabbitmq "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq/v1api" + "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq/v1api/wait" ) // Ensure the implementation satisfies the expected interfaces. @@ -55,11 +55,11 @@ type Model struct { // Struct corresponding to DataSourceModel.Parameters type parametersModel struct { SgwAcl types.String `tfsdk:"sgw_acl"` - ConsumerTimeout types.Int64 `tfsdk:"consumer_timeout"` + ConsumerTimeout types.Int32 `tfsdk:"consumer_timeout"` EnableMonitoring types.Bool `tfsdk:"enable_monitoring"` Graphite types.String `tfsdk:"graphite"` - MaxDiskThreshold types.Int64 `tfsdk:"max_disk_threshold"` - MetricsFrequency types.Int64 `tfsdk:"metrics_frequency"` + 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"` Plugins types.List `tfsdk:"plugins"` @@ -72,11 +72,11 @@ type parametersModel struct { // Types corresponding to parametersModel var parametersTypes = map[string]attr.Type{ "sgw_acl": basetypes.StringType{}, - "consumer_timeout": basetypes.Int64Type{}, + "consumer_timeout": basetypes.Int32Type{}, "enable_monitoring": basetypes.BoolType{}, "graphite": basetypes.StringType{}, - "max_disk_threshold": basetypes.Int64Type{}, - "metrics_frequency": basetypes.Int64Type{}, + "max_disk_threshold": basetypes.Int32Type{}, + "metrics_frequency": basetypes.Int32Type{}, "metrics_prefix": basetypes.StringType{}, "monitoring_instance_id": basetypes.StringType{}, "plugins": basetypes.ListType{ElemType: types.StringType}, @@ -210,7 +210,7 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r Optional: true, Computed: true, }, - "consumer_timeout": schema.Int64Attribute{ + "consumer_timeout": schema.Int32Attribute{ Description: parametersDescriptions["consumer_timeout"], Optional: true, Computed: true, @@ -225,12 +225,12 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r 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, @@ -354,7 +354,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 @@ -362,12 +362,12 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques ctx = core.LogResponse(ctx) - if createResp.InstanceId == nil { + if createResp.InstanceId == "" { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", "API response did not include instance ID") return } - instanceId := *createResp.InstanceId + instanceId := createResp.InstanceId ctx = utils.SetAndLogStateFields(ctx, &resp.Diagnostics, &resp.State, map[string]any{ "project_id": projectId, "instance_id": instanceId, @@ -376,7 +376,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques return } - waitResp, err := wait.CreateInstanceWaitHandler(ctx, r.client, projectId, instanceId).WaitWithContext(ctx) + waitResp, err := wait.CreateInstanceWaitHandler(ctx, r.client.DefaultAPI, projectId, instanceId).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", fmt.Sprintf("Instance creation waiting: %v", err)) return @@ -414,7 +414,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) { @@ -489,7 +489,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 @@ -497,7 +497,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 @@ -536,7 +536,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 @@ -544,7 +544,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 @@ -594,18 +594,18 @@ func mapFields(instance *rabbitmq.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) } @@ -658,26 +658,22 @@ 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) - case int: - valueInt64 = int64(temp) + valueInt32 = temp case float64: - valueInt64 = int64(temp) + valueInt32 = int32(temp) } - value = types.Int64Value(valueInt64) + value = types.Int32Value(valueInt32) } case basetypes.ListType: // Assumed to be a list of strings if valueInterface == nil { @@ -730,9 +726,9 @@ func toCreatePayload(model *Model, parameters *parametersModel) (*rabbitmq.Creat } return &rabbitmq.CreateInstancePayload{ - InstanceName: conversion.StringValueToPointer(model.Name), + InstanceName: model.Name.ValueString(), Parameters: payloadParams, - PlanId: conversion.StringValueToPointer(model.PlanId), + PlanId: model.PlanId.ValueString(), }, nil } @@ -759,36 +755,36 @@ func toInstanceParams(parameters *parametersModel) (*rabbitmq.InstanceParameters payloadParams := &rabbitmq.InstanceParameters{} payloadParams.SgwAcl = conversion.StringValueToPointer(parameters.SgwAcl) - payloadParams.ConsumerTimeout = conversion.Int64ValueToPointer(parameters.ConsumerTimeout) + payloadParams.ConsumerTimeout = conversion.Int32ValueToPointer(parameters.ConsumerTimeout) payloadParams.EnableMonitoring = conversion.BoolValueToPointer(parameters.EnableMonitoring) payloadParams.Graphite = conversion.StringValueToPointer(parameters.Graphite) - payloadParams.MaxDiskThreshold = conversion.Int64ValueToPointer(parameters.MaxDiskThreshold) - payloadParams.MetricsFrequency = conversion.Int64ValueToPointer(parameters.MetricsFrequency) + 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.Plugins, err = conversion.StringListToPointer(parameters.Plugins) + payloadParams.Plugins, err = conversion.StringListToSlice(parameters.Plugins) if err != nil { return nil, fmt.Errorf("converting plugins: %w", err) } - payloadParams.Roles, err = conversion.StringListToPointer(parameters.Roles) + payloadParams.Roles, err = conversion.StringListToSlice(parameters.Roles) if err != nil { return nil, fmt.Errorf("converting roles: %w", err) } - payloadParams.Syslog, err = conversion.StringListToPointer(parameters.Syslog) + payloadParams.Syslog, err = conversion.StringListToSlice(parameters.Syslog) if err != nil { return nil, fmt.Errorf("converting syslog: %w", err) } - payloadParams.TlsCiphers, err = conversion.StringListToPointer(parameters.TlsCiphers) + payloadParams.TlsCiphers, err = conversion.StringListToSlice(parameters.TlsCiphers) if err != nil { return nil, fmt.Errorf("converting tls_ciphers: %w", err) } - payloadParams.TlsProtocols, err = conversion.StringListToPointer(parameters.TlsProtocols) + payloadParams.TlsProtocols, err = conversion.StringListToSlice(parameters.TlsProtocols) if err != nil { return nil, fmt.Errorf("converting tls_protocol_versions: %w", err) } @@ -798,7 +794,7 @@ func toInstanceParams(parameters *parametersModel) (*rabbitmq.InstanceParameters 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 RabbitMQ offerings: %w", err) } @@ -808,22 +804,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) } } @@ -836,16 +832,16 @@ func (r *instanceResource) loadPlanId(ctx context.Context, model *Model) error { func loadPlanNameAndVersion(ctx context.Context, client *rabbitmq.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 RabbitMQ 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/rabbitmq/instance/resource_test.go b/stackit/internal/services/rabbitmq/instance/resource_test.go index a71cdf1f3..8c7a41b3d 100644 --- a/stackit/internal/services/rabbitmq/instance/resource_test.go +++ b/stackit/internal/services/rabbitmq/instance/resource_test.go @@ -8,16 +8,16 @@ 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/rabbitmq" + rabbitmq "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq/v1api" ) var fixtureModelParameters = types.ObjectValueMust(parametersTypes, map[string]attr.Value{ "sgw_acl": types.StringValue("acl"), - "consumer_timeout": types.Int64Value(10), + "consumer_timeout": types.Int32Value(10), "enable_monitoring": types.BoolValue(true), "graphite": types.StringValue("1.1.1.1:91"), - "max_disk_threshold": types.Int64Value(100), - "metrics_frequency": types.Int64Value(10), + "max_disk_threshold": types.Int32Value(100), + "metrics_frequency": types.Int32Value(10), "metrics_prefix": types.StringValue("prefix"), "monitoring_instance_id": types.StringValue("mid"), "plugins": types.ListValueMust(types.StringType, []attr.Value{ @@ -44,18 +44,18 @@ var fixtureModelParameters = types.ObjectValueMust(parametersTypes, map[string]a var fixtureInstanceParameters = rabbitmq.InstanceParameters{ SgwAcl: new("acl"), - ConsumerTimeout: new(int64(10)), + ConsumerTimeout: new(int32(10)), EnableMonitoring: new(true), Graphite: new("1.1.1.1:91"), - MaxDiskThreshold: new(int64(100)), - MetricsFrequency: new(int64(10)), + MaxDiskThreshold: new(int32(100)), + MetricsFrequency: new(int32(10)), MetricsPrefix: new("prefix"), MonitoringInstanceId: new("mid"), - Plugins: &[]string{"plugin1", "plugin2"}, - Roles: &[]string{"role1", "role2"}, - Syslog: &[]string{"syslog", "syslog2"}, - TlsCiphers: &[]string{"ciphers1", "ciphers2"}, - TlsProtocols: &[]string{"tlsv1.2", "tlsv1.3"}, + Plugins: []string{"plugin1", "plugin2"}, + Roles: []string{"role1", "role2"}, + Syslog: []string{"syslog", "syslog2"}, + TlsCiphers: []string{"ciphers1", "ciphers2"}, + TlsProtocols: []string{"tlsv1.2", "tlsv1.3"}, } func TestMapFields(t *testing.T) { @@ -72,13 +72,13 @@ func TestMapFields(t *testing.T) { 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, @@ -86,21 +86,21 @@ func TestMapFields(t *testing.T) { { "simple_values", &rabbitmq.Instance{ - PlanId: new("plan"), - CfGuid: new("cf"), - CfSpaceGuid: new("space"), - DashboardUrl: new("dashboard"), - ImageUrl: new("image"), + 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{ "sgw_acl": "acl", - "consumer_timeout": 10, + "consumer_timeout": int32(10), "enable_monitoring": true, "graphite": "1.1.1.1:91", - "max_disk_threshold": 100, - "metrics_frequency": 10, + "max_disk_threshold": int32(100), + "metrics_frequency": int32(10), "metrics_prefix": "prefix", "monitoring_instance_id": "mid", "plugins": []string{"plugin1", "plugin2"}, @@ -141,7 +141,7 @@ func TestMapFields(t *testing.T) { { "wrong_param_types_1", &rabbitmq.Instance{ - Parameters: &map[string]any{ + Parameters: map[string]any{ "sgw_acl": true, }, }, @@ -151,7 +151,7 @@ func TestMapFields(t *testing.T) { { "wrong_param_types_2", &rabbitmq.Instance{ - Parameters: &map[string]any{ + Parameters: map[string]any{ "sgw_acl": 1, }, }, @@ -203,9 +203,9 @@ func TestToCreatePayload(t *testing.T) { Parameters: fixtureModelParameters, }, &rabbitmq.CreateInstancePayload{ - InstanceName: new("name"), + InstanceName: "name", Parameters: &fixtureInstanceParameters, - PlanId: new("plan"), + PlanId: "plan", }, true, }, @@ -217,8 +217,8 @@ func TestToCreatePayload(t *testing.T) { Parameters: fixtureModelParameters, }, &rabbitmq.CreateInstancePayload{ - InstanceName: new(""), - PlanId: new(""), + InstanceName: "", + PlanId: "", Parameters: &fixtureInstanceParameters, }, true, @@ -236,8 +236,8 @@ func TestToCreatePayload(t *testing.T) { PlanId: types.StringValue("plan"), }, &rabbitmq.CreateInstancePayload{ - InstanceName: new("name"), - PlanId: new("plan"), + InstanceName: "name", + PlanId: "plan", }, true, }, diff --git a/stackit/internal/services/rabbitmq/rabbitmq_acc_test.go b/stackit/internal/services/rabbitmq/rabbitmq_acc_test.go index 66346a1ba..9b7ee7e35 100644 --- a/stackit/internal/services/rabbitmq/rabbitmq_acc_test.go +++ b/stackit/internal/services/rabbitmq/rabbitmq_acc_test.go @@ -10,8 +10,8 @@ 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/rabbitmq" - "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq/wait" + rabbitmq "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq/v1api" + "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq/v1api/wait" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/testutil" ) @@ -20,11 +20,11 @@ import ( var instanceResource = map[string]string{ "project_id": testutil.ProjectId, "name": testutil.ResourceNameWithDateTime("rabbitmq"), - "plan_id": "6af42a95-8b68-436d-907b-8ae37dfec52b", + "plan_id": "d5da0d91-6854-4670-802f-8a874dabfd58", "plan_name": "stackit-rabbitmq-2.4.10-single", - "version": "3.13", + "version": "4.1", "sgw_acl_invalid": "1.2.3.4/4", - "sgw_acl_valid": "192.168.0.0/16", + "sgw_acl_valid": "193.148.160.0/19", } func parametersConfig(params map[string]string) string { @@ -260,23 +260,23 @@ func testAccCheckRabbitMQDestroy(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) } @@ -287,14 +287,14 @@ func testAccCheckRabbitMQDestroy(s *terraform.State) error { } func checkInstanceDeleteSuccess(i *rabbitmq.Instance) bool { - if *i.LastOperation.Type != rabbitmq.INSTANCELASTOPERATIONTYPE_DELETE { + if i.LastOperation.Type != wait.INSTANCELASTOPERATIONTYPE_DELETE { return false } - if *i.LastOperation.Type == rabbitmq.INSTANCELASTOPERATIONTYPE_DELETE { - if *i.LastOperation.State != rabbitmq.INSTANCELASTOPERATIONSTATE_SUCCEEDED { + if i.LastOperation.Type == wait.INSTANCELASTOPERATIONTYPE_DELETE { + if i.LastOperation.State != "succeeded" { return false - } else if strings.Contains(*i.LastOperation.Description, "DeleteFailed") || strings.Contains(*i.LastOperation.Description, "failed") { + } else if strings.Contains(i.LastOperation.Description, "DeleteFailed") || strings.Contains(i.LastOperation.Description, "failed") { return false } } diff --git a/stackit/internal/services/rabbitmq/rabbitmq_test.go b/stackit/internal/services/rabbitmq/rabbitmq_test.go index 48201e308..6cfde17a0 100644 --- a/stackit/internal/services/rabbitmq/rabbitmq_test.go +++ b/stackit/internal/services/rabbitmq/rabbitmq_test.go @@ -8,8 +8,7 @@ import ( "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-testing/helper/resource" - "github.com/stackitcloud/stackit-sdk-go/core/utils" - "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq" + rabbitmq "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq/v1api" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/testutil" ) @@ -39,13 +38,13 @@ resource "stackit_rabbitmq_instance" "instance" { `, s.Server.URL, projectId, name, planName, version) offerings := testutil.MockResponse{ ToJsonBody: &rabbitmq.ListOfferingsResponse{ - Offerings: &[]rabbitmq.Offering{ + Offerings: []rabbitmq.Offering{ { - Version: utils.Ptr(version), - Plans: &[]rabbitmq.Plan{ + Version: version, + Plans: []rabbitmq.Plan{ { - Name: utils.Ptr(planName), - Id: utils.Ptr(planId), + Name: planName, + Id: planId, }, }, }, @@ -62,15 +61,10 @@ resource "stackit_rabbitmq_instance" "instance" { testutil.MockResponse{ Description: "create", ToJsonBody: rabbitmq.CreateInstanceResponse{ - InstanceId: new(instanceId), - }, - }, - testutil.MockResponse{ - Description: "create waiter", - ToJsonBody: rabbitmq.Instance{ - Status: utils.Ptr(rabbitmq.INSTANCESTATUS_FAILED), + InstanceId: instanceId, }, }, + testutil.MockResponse{Description: "create waiter", StatusCode: http.StatusInternalServerError}, ) }, Config: tfConfig, @@ -128,7 +122,7 @@ resource "stackit_rabbitmq_credential" "credential" { // initial post response testutil.MockResponse{ ToJsonBody: rabbitmq.CredentialsResponse{ - Id: new(credentialId), + Id: credentialId, }, }, // failing waiter diff --git a/stackit/internal/services/rabbitmq/utils/util.go b/stackit/internal/services/rabbitmq/utils/util.go index 1f7a1c099..da0d1abdd 100644 --- a/stackit/internal/services/rabbitmq/utils/util.go +++ b/stackit/internal/services/rabbitmq/utils/util.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/stackitcloud/stackit-sdk-go/core/config" - "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq" + rabbitmq "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq/v1api" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils" ) diff --git a/stackit/internal/services/rabbitmq/utils/util_test.go b/stackit/internal/services/rabbitmq/utils/util_test.go index 105f71d92..e299e74eb 100644 --- a/stackit/internal/services/rabbitmq/utils/util_test.go +++ b/stackit/internal/services/rabbitmq/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/rabbitmq" + rabbitmq "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq/v1api" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils" ) From 4d74c6abc971c8d4f756bf453afd2fa72c330ecc Mon Sep 17 00:00:00 2001 From: GokceGK Date: Tue, 14 Apr 2026 09:29:25 +0200 Subject: [PATCH 2/3] remove tls from instance parameters --- stackit/internal/services/rabbitmq/rabbitmq_acc_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/stackit/internal/services/rabbitmq/rabbitmq_acc_test.go b/stackit/internal/services/rabbitmq/rabbitmq_acc_test.go index 9b7ee7e35..ae22724da 100644 --- a/stackit/internal/services/rabbitmq/rabbitmq_acc_test.go +++ b/stackit/internal/services/rabbitmq/rabbitmq_acc_test.go @@ -36,7 +36,6 @@ func parametersConfig(params map[string]string) string { "plugins", "roles", "syslog", - "tls_ciphers", } var parameters strings.Builder parameters.WriteString("parameters = {") @@ -108,7 +107,6 @@ func TestAccRabbitMQResource(t *testing.T) { "plugins": `["rabbitmq_federation"]`, "roles": `["administrator"]`, "syslog": `["syslog.example.com:514"]`, - "tls_ciphers": `["TLS_AES_128_GCM_SHA256"]`, }), Check: resource.ComposeAggregateTestCheckFunc( // Instance data @@ -133,8 +131,6 @@ func TestAccRabbitMQResource(t *testing.T) { resource.TestCheckResourceAttr("stackit_rabbitmq_instance.instance", "parameters.roles.0", "administrator"), resource.TestCheckResourceAttr("stackit_rabbitmq_instance.instance", "parameters.syslog.#", "1"), resource.TestCheckResourceAttr("stackit_rabbitmq_instance.instance", "parameters.syslog.0", "syslog.example.com:514"), - resource.TestCheckResourceAttr("stackit_rabbitmq_instance.instance", "parameters.tls_ciphers.#", "1"), - resource.TestCheckResourceAttr("stackit_rabbitmq_instance.instance", "parameters.tls_ciphers.0", "TLS_AES_128_GCM_SHA256"), // Credential data resource.TestCheckResourceAttrPair( From 11baed0344bb77f7f9a7a3d0b31cb0556acfc27d Mon Sep 17 00:00:00 2001 From: GokceGK Date: Tue, 14 Apr 2026 11:33:56 +0200 Subject: [PATCH 3/3] Revert "remove tls from instance parameters" This reverts commit 4d74c6abc971c8d4f756bf453afd2fa72c330ecc. --- stackit/internal/services/rabbitmq/rabbitmq_acc_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stackit/internal/services/rabbitmq/rabbitmq_acc_test.go b/stackit/internal/services/rabbitmq/rabbitmq_acc_test.go index ae22724da..9b7ee7e35 100644 --- a/stackit/internal/services/rabbitmq/rabbitmq_acc_test.go +++ b/stackit/internal/services/rabbitmq/rabbitmq_acc_test.go @@ -36,6 +36,7 @@ func parametersConfig(params map[string]string) string { "plugins", "roles", "syslog", + "tls_ciphers", } var parameters strings.Builder parameters.WriteString("parameters = {") @@ -107,6 +108,7 @@ func TestAccRabbitMQResource(t *testing.T) { "plugins": `["rabbitmq_federation"]`, "roles": `["administrator"]`, "syslog": `["syslog.example.com:514"]`, + "tls_ciphers": `["TLS_AES_128_GCM_SHA256"]`, }), Check: resource.ComposeAggregateTestCheckFunc( // Instance data @@ -131,6 +133,8 @@ func TestAccRabbitMQResource(t *testing.T) { resource.TestCheckResourceAttr("stackit_rabbitmq_instance.instance", "parameters.roles.0", "administrator"), resource.TestCheckResourceAttr("stackit_rabbitmq_instance.instance", "parameters.syslog.#", "1"), resource.TestCheckResourceAttr("stackit_rabbitmq_instance.instance", "parameters.syslog.0", "syslog.example.com:514"), + resource.TestCheckResourceAttr("stackit_rabbitmq_instance.instance", "parameters.tls_ciphers.#", "1"), + resource.TestCheckResourceAttr("stackit_rabbitmq_instance.instance", "parameters.tls_ciphers.0", "TLS_AES_128_GCM_SHA256"), // Credential data resource.TestCheckResourceAttrPair(