Skip to content

Commit 4d8dd23

Browse files
committed
Reverting the changes for helm import
1 parent b8b15e7 commit 4d8dd23

File tree

1 file changed

+20
-41
lines changed

1 file changed

+20
-41
lines changed

spectrocloud/resource_registry_helm_import.go

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import (
55
"fmt"
66

77
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8-
"github.com/spectrocloud/palette-sdk-go/api/models"
98
"github.com/spectrocloud/palette-sdk-go/client"
10-
"github.com/spectrocloud/palette-sdk-go/client/herr"
119
)
1210

1311
func resourceRegistryHelmImport(ctx context.Context, d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {
@@ -29,61 +27,42 @@ func GetCommonRegistryHelm(d *schema.ResourceData, m interface{}) (*client.V1Cli
2927
// Helm registries are tenant-level resources only
3028
c := getV1ClientWithResourceContext(m, "tenant")
3129

32-
// The import ID can be either a registry UID or a registry name
33-
importID := d.Id()
34-
if importID == "" {
35-
return nil, fmt.Errorf("helm registry import ID or name is required")
30+
// The import ID should be the registry UID
31+
registryUID := d.Id()
32+
if registryUID == "" {
33+
return nil, fmt.Errorf("helm registry import ID is required")
3634
}
3735

38-
// Try to get by UID first
39-
registry, err := c.GetHelmRegistry(importID)
36+
// Validate that the registry exists and we can access it
37+
registry, err := c.GetHelmRegistry(registryUID)
4038
if err != nil {
41-
// If not found by UID, try by name
42-
if !herr.IsNotFound(err) {
43-
return nil, fmt.Errorf("unable to retrieve Helm registry '%s': %s", importID, err)
44-
}
45-
} else if registry != nil {
46-
// Found by UID
47-
if err := setHelmRegistryState(d, registry, importID); err != nil {
48-
return nil, err
49-
}
50-
return c, nil
51-
}
52-
53-
// Try to get by name
54-
registry, nameErr := c.GetHelmRegistryByName(importID)
55-
if nameErr != nil {
56-
return nil, fmt.Errorf("unable to retrieve Helm registry by name or id '%s': %s", importID, nameErr)
57-
}
58-
if registry == nil || registry.Metadata == nil {
59-
return nil, fmt.Errorf("helm registry '%s' not found", importID)
39+
return nil, fmt.Errorf("unable to retrieve Helm registry: %s", err)
6040
}
61-
registryUID := registry.Metadata.UID
62-
if registryUID == "" {
63-
return nil, fmt.Errorf("helm registry with name '%s' found but has no UID", importID)
41+
if registry == nil {
42+
return nil, fmt.Errorf("helm registry with ID %s not found", registryUID)
6443
}
6544

66-
if err := setHelmRegistryState(d, registry, registryUID); err != nil {
45+
// Set the required fields for the resource
46+
if err := d.Set("name", registry.Metadata.Name); err != nil {
6747
return nil, err
6848
}
69-
return c, nil
70-
}
7149

72-
// setHelmRegistryState sets resource state from a Helm registry and the resolved UID.
73-
func setHelmRegistryState(d *schema.ResourceData, registry *models.V1HelmRegistry, registryUID string) error {
74-
if err := d.Set("name", registry.Metadata.Name); err != nil {
75-
return err
76-
}
50+
// Set the endpoint URL
7751
if registry.Spec != nil && registry.Spec.Endpoint != nil && *registry.Spec.Endpoint != "" {
7852
if err := d.Set("endpoint", *registry.Spec.Endpoint); err != nil {
79-
return err
53+
return nil, err
8054
}
8155
}
56+
57+
// Set the is_private field from the registry specification
8258
if registry.Spec != nil {
8359
if err := d.Set("is_private", registry.Spec.IsPrivate); err != nil {
84-
return err
60+
return nil, err
8561
}
8662
}
63+
64+
// Set the ID to the registry ID
8765
d.SetId(registryUID)
88-
return nil
66+
67+
return c, nil
8968
}

0 commit comments

Comments
 (0)