From 54b2aebffb51e01ee7f1b432ee99965f26f4e774 Mon Sep 17 00:00:00 2001 From: Radu Mocanu Date: Fri, 9 Aug 2024 17:46:22 +0300 Subject: [PATCH 1/2] fix: check if no registies are found because none exist, wrong user agent for vm autoscaling --- ionoscloud/data_source_container_registry.go | 9 +++++---- services/autoscaling/client.go | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ionoscloud/data_source_container_registry.go b/ionoscloud/data_source_container_registry.go index 255a7cd14..bd3e24cdc 100644 --- a/ionoscloud/data_source_container_registry.go +++ b/ionoscloud/data_source_container_registry.go @@ -194,12 +194,13 @@ func dataSourceContainerRegistryRead(ctx context.Context, d *schema.ResourceData } } - if len(results) > 1 { + if len(results) == 0 { + return diag.FromErr(fmt.Errorf("no registry found with the specified criteria: name = %s location = %s", name, location)) + } else if len(results) > 1 { return diag.FromErr(fmt.Errorf("more than one registry found with the specified criteria: name = %s location = %s", name, location)) + } else { + registry = results[0] } - - registry = results[0] - } if err := crService.SetRegistryData(d, registry); err != nil { diff --git a/services/autoscaling/client.go b/services/autoscaling/client.go index d1c8e6b22..6b7c110de 100644 --- a/services/autoscaling/client.go +++ b/services/autoscaling/client.go @@ -27,7 +27,7 @@ func NewClient(username, password, token, url, version, terraformVersion string) newAutoscalingConfig.MaxWaitTime = constant.MaxWaitTime newAutoscalingConfig.HTTPClient = &http.Client{Transport: utils.CreateTransport()} newAutoscalingConfig.UserAgent = fmt.Sprintf( - "terraform-provider/%s_ionos-cloud-sdk-go-logging/%s_hashicorp-terraform/%s_terraform-plugin-sdk/%s_os/%s_arch/%s", + "terraform-provider/%s_ionos-cloud-sdk-go-vm-autoscaling/%s_hashicorp-terraform/%s_terraform-plugin-sdk/%s_os/%s_arch/%s", version, autoscaling.Version, terraformVersion, meta.SDKVersionString(), runtime.GOOS, runtime.GOARCH) //nolint:staticcheck return &Client{sdkClient: autoscaling.NewAPIClient(newAutoscalingConfig)} From 507bed1c5857cbc7040bbb89fd165c337b8680e9 Mon Sep 17 00:00:00 2001 From: Radu Mocanu Date: Tue, 13 Aug 2024 12:51:05 +0300 Subject: [PATCH 2/2] fix: linter error switch case --- ionoscloud/data_source_container_registry.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ionoscloud/data_source_container_registry.go b/ionoscloud/data_source_container_registry.go index bd3e24cdc..9b8610178 100644 --- a/ionoscloud/data_source_container_registry.go +++ b/ionoscloud/data_source_container_registry.go @@ -194,11 +194,12 @@ func dataSourceContainerRegistryRead(ctx context.Context, d *schema.ResourceData } } - if len(results) == 0 { + switch { + case len(results) == 0: return diag.FromErr(fmt.Errorf("no registry found with the specified criteria: name = %s location = %s", name, location)) - } else if len(results) > 1 { + case len(results) > 1: return diag.FromErr(fmt.Errorf("more than one registry found with the specified criteria: name = %s location = %s", name, location)) - } else { + default: registry = results[0] } }