diff --git a/dynamic/main.go b/dynamic/main.go index 7e7f09a7b..8b1de3205 100644 --- a/dynamic/main.go +++ b/dynamic/main.go @@ -17,11 +17,7 @@ package main import ( "context" "encoding/json" - "errors" "fmt" - "os" - "os/exec" - "github.com/blang/semver" "github.com/opentofu/opentofu/shim/run" "github.com/pulumi/pulumi/pkg/v3/codegen/schema" @@ -29,6 +25,8 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/common/diag/colors" "github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin" "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract" + "os" + "os/exec" "github.com/pulumi/pulumi-terraform-bridge/dynamic/parameterize" "github.com/pulumi/pulumi-terraform-bridge/dynamic/version" @@ -158,19 +156,20 @@ func initialSetup() (info.Provider, pfbridge.ProviderMetadata, func() error) { } fullDocs = args.Remote.Docs if fullDocs { - upstreamRepoDir := "terraform-provider-" + info.Name + "-v" + info.Version - // Only clone if the directory doesn't exist in the expected location - if _, err := os.Stat(upstreamRepoDir); errors.Is(err, os.ErrNotExist) { - versionWithPrefix := "v" + info.Version - ghRepo := "https://github.com/" + info.GitHubOrg + "/terraform-provider-" + info.Name - - cmd := exec.Command("git", "clone", "--depth", "1", "-b", versionWithPrefix, ghRepo, upstreamRepoDir) - err = cmd.Run() - if err != nil { - return plugin.ParameterizeResponse{}, err - } + // Write the upstream files at this version to a temporary directory + tmpDir, err := os.MkdirTemp("", "upstreamRepoDir") + if err != nil { + return plugin.ParameterizeResponse{}, err + } + versionWithPrefix := "v" + info.Version + ghRepo := "https://github.com/" + info.GitHubOrg + "/terraform-provider-" + info.Name + + cmd := exec.Command("git", "clone", "--depth", "1", "-b", versionWithPrefix, ghRepo, tmpDir) + err = cmd.Run() + if err != nil { + return plugin.ParameterizeResponse{}, err } - info.UpstreamRepoPath = upstreamRepoDir + info.UpstreamRepoPath = tmpDir } return plugin.ParameterizeResponse{ Name: p.Name(), diff --git a/dynamic/parameterize/args.go b/dynamic/parameterize/args.go index af5ac9b6e..ffe5dafa6 100644 --- a/dynamic/parameterize/args.go +++ b/dynamic/parameterize/args.go @@ -72,6 +72,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-3 arguments: [version] fullDocs") + return Args{}, fmt.Errorf("expected to be parameterized by 1-3 arguments: [version] [fullDocs]") } } diff --git a/dynamic/parameterize/args_test.go b/dynamic/parameterize/args_test.go index fa014baf8..78f1c1c1b 100644 --- a/dynamic/parameterize/args_test.go +++ b/dynamic/parameterize/args_test.go @@ -51,12 +51,12 @@ func TestParseArgs(t *testing.T) { { name: "no args", args: []string{}, - errMsg: autogold.Expect("expected to be parameterized by 1-3 arguments: [version] fullDocs"), + errMsg: autogold.Expect("expected to be parameterized by 1-3 arguments: [version] [fullDocs]"), }, { name: "too many args", args: []string{"arg1", "arg2", "arg3", "arg4"}, - errMsg: autogold.Expect("expected to be parameterized by 1-3 arguments: [version] fullDocs"), + errMsg: autogold.Expect("expected to be parameterized by 1-3 arguments: [version] [fullDocs]"), }, { name: "invalid third arg", diff --git a/pkg/tfbridge/info/info.go b/pkg/tfbridge/info/info.go index da9f8c219..a7ac7f714 100644 --- a/pkg/tfbridge/info/info.go +++ b/pkg/tfbridge/info/info.go @@ -130,7 +130,7 @@ type Provider struct { // - TFProviderModuleVersion // // For dynamically bridged providers, when the fullDocs option is set on the parameterized inputs, - // this field will be automatically set to "terraform-provider--v". + // this field will be automatically set to a temporary directory containing a shallow clone of the upstream repo. // This list may change over time. UpstreamRepoPath string diff --git a/pkg/tfgen/generate.go b/pkg/tfgen/generate.go index 4fc2827e7..28b97c3c5 100644 --- a/pkg/tfgen/generate.go +++ b/pkg/tfgen/generate.go @@ -787,7 +787,6 @@ type GenerateSchemaResult struct { func GenerateSchemaWithOptions(opts GenerateSchemaOptions) (*GenerateSchemaResult, error) { ctx := context.Background() - info := opts.ProviderInfo sink := opts.DiagnosticsSink g, err := NewGenerator(GeneratorOptions{ @@ -802,6 +801,7 @@ func GenerateSchemaWithOptions(opts GenerateSchemaOptions) (*GenerateSchemaResul if err != nil { return nil, errors.Wrapf(err, "failed to create generator") } + return g.generateSchemaResult(ctx) }