pulumi / pulumi-terraform-provider

Use any Terraform provider with Pulumi
Apache License 2.0
6 stars 0 forks source link

Blocking issue: ctx.InvokePackageRaw undefined (type *pulumi.Context has no field or method InvokePackageRaw error in the generated SDK #38

Open scraly opened 2 weeks ago

scraly commented 2 weeks ago

What happened?

Hi,

Generating a SDK from an existing provider was working with pulumi-terraform-provider 0.1 but I've got an error with 0.2 version.

$ pulumi preview
Please choose a stack, or create a new one: <create a new stack>
Please enter your desired stack name: dev 
Created stack 'dev'
Enter your passphrase to unlock config/secrets
    (set PULUMI_CONFIG_PASSPHRASE or PULUMI_CONFIG_PASSPHRASE_FILE to remember):  
Enter your passphrase to unlock config/secrets
Previewing update (dev):
     Type                 Name           Plan     Info
     pulumi:pulumi:Stack  go-tf-ovh-dev           1 error; 12 messages

Diagnostics:
  pulumi:pulumi:Stack (go-tf-ovh-dev):
    # github.com/pulumi/pulumi-terraform-provider/sdks/go/ovh
    sdks/ovh/getCloudProject.go:58:23: ctx.InvokePackageRaw undefined (type *pulumi.Context has no field or method InvokePackageRaw)
    sdks/ovh/getCloudProjectCapabilitiesContainerregistry.go:47:23: ctx.InvokePackageRaw undefined (type *pulumi.Context has no field or method InvokePackageRaw)
    sdks/ovh/getCloudProjectCapabilitiesContainerregistryFilter.go:56:23: ctx.InvokePackageRaw undefined (type *pulumi.Context has no field or method InvokePackageRaw)
    sdks/ovh/getCloudProjectContainerregistries.go:47:23: ctx.InvokePackageRaw undefined (type *pulumi.Context has no field or method InvokePackageRaw)
    sdks/ovh/getCloudProjectContainerregistry.go:57:23: ctx.InvokePackageRaw undefined (type *pulumi.Context has no field or method InvokePackageRaw)
    sdks/ovh/getCloudProjectContainerregistryIpRestrictionsManagement.go:49:23: ctx.InvokePackageRaw undefined (type *pulumi.Context has no field or method InvokePackageRaw)
    sdks/ovh/getCloudProjectContainerregistryIpRestrictionsRegistry.go:49:23: ctx.InvokePackageRaw undefined (type *pulumi.Context has no field or method InvokePackageRaw)
    sdks/ovh/getCloudProjectContainerregistryOidc.go:66:23: ctx.InvokePackageRaw undefined (type *pulumi.Context has no field or method InvokePackageRaw)
    sdks/ovh/getCloudProjectContainerregistryUsers.go:49:23: ctx.InvokePackageRaw undefined (type *pulumi.Context has no field or method InvokePackageRaw)
    sdks/ovh/getCloudProjectDatabase.go:67:23: ctx.InvokePackageRaw undefined (type *pulumi.Context has no field or method InvokePackageRaw)
    sdks/ovh/getCloudProjectDatabase.go:67:23: too many errors

    error: error in compiling Go: unable to run `go build`: exit status 1

Example

Commands executed:

$ pulumi login --local
$ pulumi new go -y
$ pulumi package add terraform-provider ovh/ovh
$ go mod edit -replace github.com/pulumi/pulumi-terraform-provider/sdks/go/ovh=./sdks/ovh

# fill the main.go file:
package main

import (
    "github.com/pulumi/pulumi-terraform-provider/sdks/go/ovh"
    "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    "github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
    "github.com/pulumiverse/pulumi-harbor/sdk/v3/go/harbor"
)

func main() {
    pulumi.Run(func(ctx *pulumi.Context) error {

        serviceName := config.Require(ctx, "serviceName")

        // Initiate the configuration of the registry
        regcap, err := ovh.GetCloudProjectCapabilitiesContainerregistryFilter(ctx, &ovh.GetCloudProjectCapabilitiesContainerregistryFilterArgs{
            ServiceName: &serviceName,
            PlanName:    "SMALL",
            Region:      "GRA",
        }, nil)
        if err != nil {
            return err
        }

        // Deploy a new Managed private registry
        myRegistry, err := ovh.NewCloudProjectContainerregistry(ctx, "my-registry", &ovh.CloudProjectContainerregistryArgs{
            ServiceName: pulumi.String(*regcap.ServiceName),
            PlanId:      pulumi.String(regcap.Id),
            Region:      pulumi.String(regcap.Region),
        })
        if err != nil {
            return err
        }

        // Create a User
        myRegistryUser, err := ovh.NewCloudProjectContainerregistryUser(ctx, "user", &ovh.CloudProjectContainerregistryUserArgs{
            ServiceName: pulumi.String(*regcap.ServiceName),
            RegistryId:  myRegistry.ID(),
            Email:       pulumi.String("myuser@ovh.com"),
            Login:       pulumi.String("myuser"),
        })
        if err != nil {
            return err
        }

        // Add as an output registry information
        ctx.Export("registryID", myRegistry.ID())
        ctx.Export("registryName", myRegistry.Name)
        ctx.Export("registryURL", myRegistry.Url)
        ctx.Export("registryVersion", myRegistry.Version)
        ctx.Export("registryUser", myRegistryUser.User)
        ctx.Export("registryPassword", myRegistryUser.Password)

        // Use the created registry to initiate the harbor provider
        harborProvider, err := harbor.NewProvider(ctx, "harbor", &harbor.ProviderArgs{
            Username: myRegistryUser.User,
            Password: myRegistryUser.Password,
            Url:      myRegistry.Url,
        }, pulumi.DependsOn([]pulumi.Resource{myRegistry, myRegistryUser}))
        if err != nil {
            return err
        }

        // Create a public project in your harbor registry
        project, err := harbor.NewProject(ctx, "project", &harbor.ProjectArgs{
            Name:         pulumi.String("my-new-project"),
            Public:       pulumi.Bool(true),
            ForceDestroy: pulumi.Bool(true), // force_destroy set to true in order to be allowed to destroy a project event in it's not empty
        }, pulumi.Provider(harborProvider))
        if err != nil {
            return err
        }

        ctx.Export("project", project.Name)

        return nil
    })
}

$ go mod tidy

$ pulumi up #or pulumi preview

Output of pulumi about

CLI          
Version      3.134.1
Go Version   go1.23.1
Go Compiler  gc

Plugins
KIND      NAME                VERSION
language  go                  unknown
resource  harbor              3.10.13
resource  terraform-provider  0.2.0

Host     
OS       ubuntu
Version  22.04
Arch     x86_64

This project is written in go: executable='/home/linuxbrew/.linuxbrew/bin/go' version='go version go1.23.1 linux/amd64'

Backend        
Name           ovh-publiccloudexamp-k7r156qicyg
URL            file://~
User           gitpod
Organizations  
Token type     personal

Dependencies:
NAME                                                     VERSION
github.com/pulumi/pulumi-terraform-provider/sdks/go/ovh  
github.com/pulumi/pulumi/sdk/v3                          v3.129.0
github.com/pulumiverse/pulumi-harbor/sdk/v3              v3.10.13

Pulumi locates its logs in /tmp by default
warning: Failed to get information about the current stack: No current stack

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

VenelinMartinov commented 2 weeks ago

Hi @scraly, thanks for reporting the issue and sorry you've hit problems there.

I was able to compile the above program fine with github.com/pulumi/pulumi/sdk/v3 v3.133.0. Can you please try updating you dependencies and running the program again? Thanks!

VenelinMartinov commented 2 weeks ago

Opened https://github.com/pulumi/pulumi/issues/17433 for improving the error message in such cases.