Skip to content

Commit

Permalink
fix: ensure we always have an ID
Browse files Browse the repository at this point in the history
Signed-off-by: Jesús Fernández <[email protected]>
  • Loading branch information
fernandezcuesta committed Oct 27, 2024
1 parent 3a24671 commit 8457617
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions config/team/config.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,46 @@
package team

import "github.com/crossplane/upjet/pkg/config"
import (
"context"

"github.com/crossplane/upjet/pkg/config"
"github.com/pkg/errors"
)

const (
ErrFmtNoAttribute = `"attribute not found: %s`
ErrFmtUnexpectedType = `unexpected type for attribute %s: Expecting a string`
ErrFmtEmptyAttribute = `empty attribute %s`
)

func getExternalName(tfstate map[string]any) (string, error) {
id, ok := tfstate["id"]
if !ok {
return "", errors.Errorf(ErrFmtNoAttribute, "id")
}
idStr, ok := id.(string)
if !ok {
return "", errors.Errorf(ErrFmtUnexpectedType, "id")
}
if idStr == "" {
return "PENDING", nil
}
return idStr, nil
}

func getID(ctx context.Context, externalName string, parameters map[string]any, providerConfig map[string]any) (string, error) {
if externalName == "" {
return "PENDING", nil
}
return externalName, nil
}

// Configure configures individual resources by adding custom ResourceConfigurators.
func Configure(p *config.Provider) {
p.AddResourceConfigurator("pagerduty_team", func(r *config.Resource) {

r.ExternalName = config.IdentifierFromProvider
r.ExternalName.GetExternalNameFn = getExternalName
r.ExternalName.GetIDFn = getID
r.ShortGroup = "team"
})

Expand Down

0 comments on commit 8457617

Please sign in to comment.