Skip to content

Commit

Permalink
fix(cloud/stack): default to Slug for external-name
Browse files Browse the repository at this point in the history
  • Loading branch information
Duologic committed Dec 23, 2024
1 parent dd733a0 commit 2ccb136
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions config/grafana/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package grafana

import (
"encoding/json"
"errors"
"fmt"

ujconfig "github.com/crossplane/upjet/pkg/config"
Expand Down Expand Up @@ -206,6 +207,24 @@ func Configure(p *ujconfig.Provider) {
})
p.AddResourceConfigurator("grafana_cloud_stack", func(r *ujconfig.Resource) {
r.UseAsync = true

// Cloud Stacks can either be imported by ID or by Slug
// We'll default to slug instead of ID as the ID can't be known upfront
// This'll allow us to import existing instances consistently
// Also see: https://registry.terraform.io/providers/grafana/grafana/latest/docs/resources/cloud_stack#import
r.ExternalName = ujconfig.ExternalName{
SetIdentifierArgumentFn: ujconfig.NopSetIdentifierArgument,
GetExternalNameFn: func(tfstate map[string]any) (string, error) {
slug, ok := tfstate["slug"].(string)
if !ok {
return "", errors.New("cannot get slug attribute")
}
return slug, nil
},
GetIDFn: ujconfig.ExternalNameAsID,
DisableNameInitializer: true,
}

})
p.AddResourceConfigurator("grafana_cloud_stack_service_account", func(r *ujconfig.Resource) {
r.References["stack_slug"] = ujconfig.Reference{
Expand Down

0 comments on commit 2ccb136

Please sign in to comment.