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

Fix ImportBasePath for dynamic bridged providers #2705

Merged
merged 2 commits into from
Dec 10, 2024
Merged

Conversation

Frassle
Copy link
Member

@Frassle Frassle commented Dec 10, 2024

The current code generates an import base path like github.com/pulumi/pulumi-terraform-provider/sdks/something/v3. This is a module path (ends with a version number) not a package import path, we always nest our packages one level below the module.

The correct import base path should be github.com/pulumi/pulumi-terraform-provider/sdks/something/v3/something.

@brandonpollack23
Copy link
Contributor

This looks like itll fix the issue that I was running into

Copy link

codecov bot commented Dec 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.50%. Comparing base (faeba17) to head (6c0c44e).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2705      +/-   ##
==========================================
- Coverage   69.51%   69.50%   -0.02%     
==========================================
  Files         301      301              
  Lines       38637    38637              
==========================================
- Hits        26860    26855       -5     
- Misses      10256    10261       +5     
  Partials     1521     1521              

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

@iwahbe
Copy link
Member

iwahbe commented Dec 10, 2024

github.com/pulumi/pulumi-terraform-provider/sdks/something/v3 is a nicer import path then github.com/pulumi/pulumi-terraform-provider/sdks/something/v3/something. Why do we need the double nesting?

we always nest our packages one level below the module.

We don't do this for Any TF Provider code.

Not having the double nesting worked in the past. Has something changed?

@brandonpollack23
Copy link
Contributor

github.com/pulumi/pulumi-terraform-provider/sdks/something/v3 is a nicer import path then github.com/pulumi/pulumi-terraform-provider/sdks/something/v3/something. Why do we need the double nesting?

we always nest our packages one level below the module.

We don't do this for Any TF Provider code.

Not having the double nesting worked in the past. Has something changed?

Fraser's answer will almost certainly be more pointed but this has to do with the way we generate sdks locally in pulumi and the go code is expected to be nested due to the possiblity of multiple parameterizations and is how conformance tests (and the generated sdks are expected to) behave.

It also avoids name overlap

@Frassle
Copy link
Member Author

Frassle commented Dec 10, 2024

We don't do this for Any TF Provider code.

Normal TF providers use a different sdk-gen to dynamic TF providers. When we generate a normal TF provider codegen doesn't output any go.mod and leaves it up to provider authors to add that to their repo wherever they want.

For parameterised packages we do output a go.mod and we output it at a specific place just above the provider package, so we end up with:

sdks
└── pkg
    ├── go.mod
    └── pkg
        └── init.go

If you set the ImportBasePath to github.com/pulumi/pulumi-terraform-provider/sdks/pkg/v3 we'd need to get rid of the double nesting in sdk-gen to instead have:

sdks
└── pkg
    ├── go.mod
    └── init.go

We're not doing that. It doesn't even match existing sdk layouts.

Not having the double nesting worked in the past.

We had a bug where we were generating two go.mods before for parameterised packages, one at the root as expected and another inside the package directory. The one in the package directory could be used with the import path as given, although it didn't match up if actually pushed to GitHub.

@iwahbe iwahbe self-requested a review December 10, 2024 13:18
@iwahbe
Copy link
Member

iwahbe commented Dec 10, 2024

If you set the ImportBasePath to github.com/pulumi/pulumi-terraform-provider/sdks/pkg/v3 we'd need to get rid of the double nesting

We should do that. It's marginally better for users and the double-nesting seems to have no benefit beyond path dependency. I doubt we are going to change it now.

It doesn't even match existing sdk layouts.

It shouldn't matter. Codegen should just trust the import path.

Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

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

This change will need to come with docs updates:

https://github.com/pulumi/pulumi-terraform-provider/blob/6016223e96aa54a6ab7a0e3cfb0aac02d5c53235/docs/_index.md#L75-L79

https://github.com/pulumi/pulumi-terraform-provider/blob/6016223e96aa54a6ab7a0e3cfb0aac02d5c53235/docs/_index.md#L171-L176

If ImportBasePath has correctness requirements, they need to be documented. Ideally, pulumi package use should warn (or fail) for an invalid ImportBasePath.

@Frassle
Copy link
Member Author

Frassle commented Dec 10, 2024

It shouldn't matter. Codegen should just trust the import path.

It does mostly, but when we're trying to infer the module path just from the import path we don't have enough info unless we can assume things are laid out exactly as we expect (which means double nesting) or if the schema gives us the module path (which tfbridge doesn't), but then...

We should do that.

I think we could if we had the module path from the schema as well, but this all requires codegen fixes to change the sdk layout based on those two fields.

If ImportBasePath has correctness requirements...

That's probably the better fix here.

This change will need to come with docs updates:

Sure, I can add that.

@Frassle Frassle merged commit dc97546 into master Dec 10, 2024
17 checks passed
@Frassle Frassle deleted the fraser/importBasePath branch December 10, 2024 13:39
Frassle added a commit to pulumi/pulumi-terraform-provider that referenced this pull request Dec 10, 2024
See pulumi/pulumi-terraform-bridge#2705

That changed the ImportBasePath used for Go packages to match up what sdk-gen
currently writes in terms of folder structure.

This updates the docs so the import statments match.
@pulumi-bot
Copy link
Contributor

This PR has been shipped in release v3.97.1.

iwahbe pushed a commit to pulumi/pulumi-terraform-provider that referenced this pull request Dec 13, 2024
See pulumi/pulumi-terraform-bridge#2705

That changed the ImportBasePath used for Go packages to match up what sdk-gen
currently writes in terms of folder structure.

This updates the docs so the import statments match.
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.

4 participants