Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly map pkg_index tokens #2334

Merged
merged 2 commits into from
Aug 21, 2024
Merged

Correctly map pkg_index tokens #2334

merged 2 commits into from
Aug 21, 2024

Conversation

iwahbe
Copy link
Member

@iwahbe iwahbe commented Aug 21, 2024

This PR improves the error message when it fails to map tokens (first commit), then removes the "_" appended to the end of the prefix so tokens that are of the form <pkg>_index can be correctly mapped.

Fixes pulumi/pulumi-terraform-provider#13

The old error message starts with:

```
panic: runtime error: index out of range [0] with length 0

goroutine 113 [running]:

main.providerInfo.MakeStandard.func3({0x10203f705?, 0x1?}, {0x0?, 0x1400074dd40?})

	/home/runner/work/pulumi-terraform-provider/pulumi-terraform-provider/bridge/pkg/tfbridge/tokens/tokens.go:51 +0x15c

github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/tokens.KnownModules.knownResource.func1({0x10203f705?, 0x5?}, {0x0?, 0x5?}, 0x1400074dd40, {0x0?, 0x0?})
```

The new message looks like this:

```
error: parameterize: rpc error: code = Unknown desc = 1 error occurred:
        * resources:
1 error occurred:
        * "materialize_index": empty name for module "index"
```
@iwahbe iwahbe requested review from guineveresaenger, VenelinMartinov and a team August 21, 2024 15:12
@iwahbe iwahbe self-assigned this Aug 21, 2024
Copy link

codecov bot commented Aug 21, 2024

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Project coverage is 57.00%. Comparing base (4415436) to head (610224f).
Report is 3 commits behind head on master.

Files Patch % Lines
pkg/tfbridge/tokens/tokens.go 0.00% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2334   +/-   ##
=======================================
  Coverage   57.00%   57.00%           
=======================================
  Files         366      366           
  Lines       50096    50108   +12     
=======================================
+ Hits        28556    28565    +9     
- Misses      19973    19975    +2     
- Partials     1567     1568    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@mjeffryes mjeffryes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I trust your familiarity with the naming code to get this correct, but would feel better if there were more testcases checked for the exact strategy used by the dynamic provider.

Comment on lines +87 to +88
err := prov.ComputeTokens(tokens.SingleModule(
prov.GetResourcePrefix(), "index", tokens.MakeStandard(p.Name())))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see how this fixes this specific error, and I can see that specific case tested in the new test, but I'm not sure I follow why we don't need the "_" for other resources?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basically an instance of "we were calling tokens.SingleModule wrong. It already knows to split on "_".

Name: "foo",
P: (&schema.Provider{
ResourcesMap: schema.ResourceMap{
"foo_index": nil,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we be testing some other names against this strategy eg. maybe the list fromt he previous test:

"foo_fizz_buzz":       {Tok: "foo:index:FizzBuzz"},
"foo_bar_hello_world": {Tok: "foo:index:BarHelloPulumi"},
"foo_bar":             {Tok: "foo:index:Bar"},

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This strategy is pretty well tested in:

func TestTokensSingleModule(t *testing.T) {

@iwahbe iwahbe force-pushed the iwahbe/map-confusing-tokens branch from fe74f59 to 610224f Compare August 21, 2024 17:14
@iwahbe iwahbe enabled auto-merge (rebase) August 21, 2024 17:16
iwahbe added a commit that referenced this pull request Aug 21, 2024
@iwahbe iwahbe merged commit 084dacb into master Aug 21, 2024
11 checks passed
@iwahbe iwahbe deleted the iwahbe/map-confusing-tokens branch August 21, 2024 17:30
iwahbe added a commit that referenced this pull request Aug 21, 2024
iwahbe added a commit that referenced this pull request Aug 22, 2024
@pulumi-bot
Copy link
Contributor

This PR has been shipped in release v3.90.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic generating sdk for the MaterializeInc/materialize provider
3 participants