Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/cluster/cloud/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@ func Configure(p *config.Provider) {
p.AddResourceConfigurator("ovh_cloud_project_region", func(r *config.Resource) {
r.ShortGroup = shortGroup
})
p.AddResourceConfigurator("ovh_cloud_project_storage", func(r *config.Resource) {
r.ShortGroup = shortGroup
})
}
39 changes: 38 additions & 1 deletion config/external_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package config
import (
"context"
"fmt"
"strings"

"github.com/crossplane/crossplane-runtime/v2/pkg/errors"
"github.com/crossplane/upjet/v2/pkg/config"
Expand Down Expand Up @@ -68,6 +69,42 @@ var kubeIdentifierFromProvider = config.ExternalName{
DisableNameInitializer: true,
}

var storageIdentifierFromProvider = config.ExternalName{
SetIdentifierArgumentFn: config.NopSetIdentifierArgument,
// ID is in format: service_name/region_name/name
// Extract just the name (last component) as external name
GetExternalNameFn: func(tfstate map[string]any) (string, error) {
id, ok := tfstate["id"].(string)
if !ok {
return "", errors.New("id field not found in tfstate")
}
// Split by "/" and return the last part (the bucket name)
parts := strings.Split(id, "/")
if len(parts) != 3 {
return "", errors.Errorf("unexpected id format: %s, expected format: service_name/region_name/name", id)
}
return parts[2], nil
},
GetIDFn: func(ctx context.Context, externalName string, parameters map[string]any, providerConfig map[string]any) (string, error) {
serviceName, err := serviceName(parameters)
if err != nil {
return serviceName, err
}

regionName, ok := parameters["region_name"]
if !ok {
return "", errors.Errorf(ErrFmtNoAttribute, "region_name")
}
regionNameStr, ok := regionName.(string)
if !ok {
return "", errors.Errorf(ErrFmtUnexpectedType, "region_name")
}

return fmt.Sprintf("%s/%s/%s", serviceName, regionNameStr, externalName), nil
},
DisableNameInitializer: true,
}

// ExternalNameConfigs contains all external name configurations for this
// provider.
var ExternalNameConfigs = map[string]config.ExternalName{
Expand Down Expand Up @@ -195,7 +232,7 @@ var ExternalNameConfigs = map[string]config.ExternalName{
"ovh_domain_name": config.IdentifierFromProvider,
"ovh_domain_name_servers": config.IdentifierFromProvider,
"ovh_domain_ds_records": config.IdentifierFromProvider,
"ovh_cloud_project_storage": config.IdentifierFromProvider,
"ovh_cloud_project_storage": storageIdentifierFromProvider,
"ovh_cloud_project_loadbalancer": config.IdentifierFromProvider,
"ovh_cloud_project_volume_backup": config.IdentifierFromProvider,
"ovh_cloud_project_rancher": config.IdentifierFromProvider,
Expand Down
3 changes: 3 additions & 0 deletions config/namespaced/cloud/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@ func Configure(p *config.Provider) {
p.AddResourceConfigurator("ovh_cloud_project_region", func(r *config.Resource) {
r.ShortGroup = shortGroup
})
p.AddResourceConfigurator("ovh_cloud_project_storage", func(r *config.Resource) {
r.ShortGroup = shortGroup
})
}
Loading