Skip to content

Commit

Permalink
Don't strip the prefix from a token when the token is just the prefix
Browse files Browse the repository at this point in the history
This fixes the `TestTokensCornerCases/no_suffix` test case.

Fixes pulumi/pulumi-terraform-provider#27
  • Loading branch information
iwahbe committed Aug 29, 2024
1 parent e9df3b5 commit 195387c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/tfbridge/tokens/known_modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,21 @@ func knownModules[T info.Resource | info.DataSource](
moduleTransform func(string) string,
) info.ElementStrategy[T] {
return func(tfToken string, elem *T) error {
tk := strings.TrimPrefix(tfToken, prefix)
if len(tk) == len(tfToken) {

var tk string
if t, foundPrefix := strings.CutPrefix(tfToken, prefix); foundPrefix {
if t == "" {
// If the entire tfToken is the prefix, then we don't strip the prefix. It
// will act as both prefix, module and name.
tk = tfToken
} else {
tk = t
}
} else {
return apply("", upperCamelCase(tk), elem,
fmt.Errorf("token '%s' missing package prefix '%s'", tfToken, prefix))
}

mod := defaultModule
for _, m := range modules {
if strings.HasPrefix(tk, m) {
Expand Down

0 comments on commit 195387c

Please sign in to comment.