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

Download upstream docs for dynamically bridged provider #2664

Merged
merged 16 commits into from
Dec 10, 2024

Conversation

guineveresaenger
Copy link
Contributor

@guineveresaenger guineveresaenger commented Nov 22, 2024

This pull request adds logic that enables us to generate resource docs for a dynamically bridged provider using the upstream dependency.

Usage for remote providers:
pulumi package get-schema terraform-provider <registry address> <version> fullDocs=<true|false>.

Adds a parameterized arg field to pulumi package get-schema terraform-provider <registry address> <version> called fullDocs, which when set to true will instruct the bridge to git clone --depth 1 -b <version> <terraform provider github repo> <local dir for dynamic docs>. This allows us to keep the exact same docs logic we have established. The shallow clone targets the exact doc version we need. (*)

For this, we infer the github repo from the OpenTofu org name. It is based on the assumption that registry.opentofu.org/org/foo is based on a provider that lives at github.com/org/terraform-provider-foo. OpenTofu says their protocol follows that of the HashiCorp Terraform Registry which requires an org/user and a provider name of the format terraform-provider-foo and we have historical evidence that GitHub is the most commonly used source host for terraform providers. See also opentofu/registry#1337.

Usage for local providers:
pulumi package get-schema terraform-provider <local-path> upstreamRepoPath=<localPath>. Here, the local docs path gets read directly into upstreamRepoPath.

The one thing that is perhaps missing here is to expand the remote args to allow to take a source repo as an additional argument. However, our internal use case is primarily one of automation, so this is not an immediate need.

(*)Cloning docs for the AWS terraform provider at v5.70.0 has the following time performance:

git clone --depth 1 -b v5.70.0  awsDir  
2.06s user 
1.62s system 
34% cpu 
10.713 total

Fixes #2607

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.

I left a couple of nits, but I have 1 more major piece of design feedback:

Instead of introducing XLoadUpstreamRepoForDocs and then threading the logic into the docs generator, could we download the docs during the GetSchema call directly in dynamic/main.go and then just set UpstreamRepoPath? That should accomplish the same effect without adding more logic to the docs generator.

dynamic/info.go Outdated Show resolved Hide resolved
dynamic/info.go Outdated Show resolved Hide resolved
dynamic/info.go Outdated Show resolved Hide resolved
dynamic/main.go Outdated Show resolved Hide resolved
dynamic/parameterize/args.go Outdated Show resolved Hide resolved
@guineveresaenger guineveresaenger marked this pull request as ready for review November 28, 2024 01:33
Copy link

codecov bot commented Nov 28, 2024

Codecov Report

Attention: Patch coverage is 47.05882% with 18 lines in your changes missing coverage. Please review.

Project coverage is 69.53%. Comparing base (143b3ee) to head (5df05c7).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
pkg/tfgen/generate.go 18.75% 13 Missing ⚠️
pkg/pf/tfgen/main.go 0.00% 4 Missing ⚠️
pkg/tfgen/main.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2664   +/-   ##
=======================================
  Coverage   69.53%   69.53%           
=======================================
  Files         301      301           
  Lines       38646    38655    +9     
=======================================
+ Hits        26871    26878    +7     
- Misses      10254    10257    +3     
+ Partials     1521     1520    -1     

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

@guineveresaenger guineveresaenger force-pushed the guin/dynamic-docs-build branch 2 times, most recently from b194a78 to 5cbcf28 Compare December 2, 2024 17:23
pkg/tfbridge/info/info.go Outdated Show resolved Hide resolved
pkg/tfgen/source.go Outdated Show resolved Hide resolved
pkg/tfgen/generate.go Outdated Show resolved Hide resolved
pkg/tfbridge/info/info.go Outdated Show resolved Hide resolved
dynamic/info.go Show resolved Hide resolved
dynamic/info.go Outdated Show resolved Hide resolved
dynamic/main.go Outdated Show resolved Hide resolved
dynamic/parameterize/args.go Outdated Show resolved Hide resolved
dynamic/parameterize/args.go Outdated Show resolved Hide resolved
dynamic/parameterize/args.go Outdated Show resolved Hide resolved
dynamic/parameterize/args.go Outdated Show resolved Hide resolved
dynamic/parameterize/args.go Outdated Show resolved Hide resolved
@guineveresaenger
Copy link
Contributor Author

guineveresaenger commented Dec 3, 2024

This may not be the way we want to do this, but I changed the function signature of Generate() and UnstableGenerateFromSchema to return a package schema so that we can access it from an outside library.

Alternatives:

  • Implementing a separate MakeSchemaWithExamples(generator) function in generate.go that takes a pre-created Generator as an argument and returns a package schema for consumption by dynamic
  • Generating the "lightweight" schema first, as before, and then making a separate call to UnstableGenerateFromSchema.

Unfortunately, adding extra options to the GeneratorOpts only gets us halfway - we must call Generate() or its parts somewhere in dynamic.

I've gone with changing the function signature to avoid writing yet another generator function with a narrowly scoped purpose, but can definitely be convinced otherwise.

iwahbe added a commit that referenced this pull request Dec 6, 2024
To be good citizens of the registry, we should set the `Repository`
field.

Related to
#2664 (comment).
@guineveresaenger guineveresaenger force-pushed the guin/dynamic-docs-build branch 2 times, most recently from fa56e6a to 97a7b57 Compare December 6, 2024 23:51
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.

There are currently two argument styles added in this PR:

pulumi package get-schema terraform-provider ./terraform-provider-local upstreamRepoPath=./local
pulumi package get-schema terraform-provider my/provider fullDocs

One is positional, but the other is flag based. Can we standardize? Personally, I'd prefer flags. That would make it:

pulumi package get-schema terraform-provider ./terraform-provider-local upstreamRepoPath=./local
pulumi package get-schema terraform-provider my/provider docs=full

@@ -6,7 +6,7 @@ export PULUMI_DISABLE_AUTOMATIC_PLUGIN_ACQUISITION := true
PROJECT_DIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))

install_plugins::
pulumi plugin install converter terraform 1.0.19
pulumi plugin install converter terraform 1.0.20
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this bump, or is it incidental?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need this bump, otherwise the test won't pass.

dynamic/info.go Outdated Show resolved Hide resolved
dynamic/main.go Outdated Show resolved Hide resolved
dynamic/main.go Outdated Show resolved Hide resolved
dynamic/main.go Outdated Show resolved Hide resolved
dynamic/parameterize/args.go Outdated Show resolved Hide resolved
dynamic/provider_test.go Outdated Show resolved Hide resolved
Comment on lines 462 to 472
type testCase struct {
name string
version string
fullDocs bool
}

tc := testCase{
name: "hashicorp/random",
version: "3.6.3",
fullDocs: true,
}
Copy link
Member

Choose a reason for hiding this comment

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

Why are we defining a local struct only to instantiate one copy? Same with the subtest.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why are we defining a local struct only to instantiate one copy?

  • Test information at a glance
  • More easily add subtests in the future if needed
  • Allows us to run individual tests by name when using an integrated IDE test framework
  • Makes the name of subtest far more obvious for running it in the terminal

Is there a downside here?

Copy link
Member

Choose a reason for hiding this comment

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

Verbosity and the chance of rot. It's an abstraction we aren't using.

pkg/tfgen/docs.go Outdated Show resolved Hide resolved
@guineveresaenger guineveresaenger force-pushed the guin/dynamic-docs-build branch 3 times, most recently from df6f314 to 1bdcf20 Compare December 9, 2024 22:34
@@ -61,6 +102,6 @@ func ParseArgs(args []string) (Args, error) {
remote.Name = args[0]
return Args{Remote: &remote}, nil
default:
return Args{}, fmt.Errorf("expected to be parameterized by 1-2 arguments: <name> [version]")
return Args{}, fmt.Errorf("expected to be parameterized by 1-3 arguments: <name> [version] [fullDocs]")
Copy link
Member

Choose a reason for hiding this comment

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

Let's be consistent with upstreamRepoPath for local providers.

Suggested change
return Args{}, fmt.Errorf("expected to be parameterized by 1-3 arguments: <name> [version] [fullDocs]")
return Args{}, fmt.Errorf("expected to be parameterized by 1-3 arguments: <name> [version] [fullDocs=<true|false>]")

@guineveresaenger guineveresaenger merged commit 334d6b7 into master Dec 10, 2024
17 checks passed
@guineveresaenger guineveresaenger deleted the guin/dynamic-docs-build branch December 10, 2024 21:29
@@ -1,8 +1,8 @@
{
"name": "b2",
"version": "0.8.9",
Copy link
Member

Choose a reason for hiding this comment

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

This is a regression.

guineveresaenger added a commit that referenced this pull request Dec 12, 2024
…#2727)

#2664 introduced using the full Generator for schema gen. 
This added a call to UnstableGenerateFromSchema, which removes the
version field from the package spec, a feature intended to make local
builds stable.
This pull request re-adds the version in `SchemaPostProcessor`.
@pulumi-bot
Copy link
Contributor

This PR has been shipped in release v3.98.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.

Generate Any TF Provider schemas with full examples
3 participants