pulumi/sdk/go
Abhinav Gupta a244de9092
fix(host/go): Download external plugins even if they're not imported
We previously changed how the Go language host retrieves information
about a Go module:

    before: go list -m -json -mod=mod all
    after:  go list -m -json $importPath1 $importPath1

This change made it possible for us to supprot running in vendored mode
which allowed for use of private plugins that are not go-get-able.

This uncovered a corner case in the `go` command's behavior
when running in module mode:

If a package is listed in the go.mod
but it's not imported by the current module,
`go list -m -json $importPath` will not list its Dir in the output
even if it's present in the module cache.
For example, given a go.mod file that declares a dependency
but code that doesn't import it, as of Go 1.20.5,

    export GOMODCACHE=$(mktemp -d)
    go mod download -json
    go list -m -json $importPath

The output of `go mod download` will include information
about the dependency and the `Dir` where it was downloaded,
but `go list -m` will not.

Unfortunately, we can't just use `go mod download`
because that breaks vendoring:
vendored dependencies cannot always be redownloaded.

To resolve this issue,
we switch to a two-pass variant to gather this information:

- Run `go list -m` to get whatever information we can locally.
  This will be sufficient for the majority of use cases.
- For the handful of cases where the dependency isn't imported,
  we'll use `go mod download -json` to download them on-demand
  and get their location from that instead.

The `go mod download` step will take place only if we're in module mode.
In vendor mode, we'll work with what we have.

Resolves #13301
2023-07-11 16:22:15 -07:00
..
auto deps(go): Upgrade to grpc 1.56.1 2023-07-06 09:04:16 -07:00
common Merge #13447 2023-07-11 22:17:03 +00:00
pulumi Use slice.Prealloc instead of make([]T, 0, ...) 2023-06-29 11:27:50 +01:00
pulumi-language-go fix(host/go): Download external plugins even if they're not imported 2023-07-11 16:22:15 -07:00
Makefile [sdk/go] Fix the `dist` make target 2023-06-30 16:09:03 -07:00
README.md `pulumi update` => `pulumi up` (#2702) 2019-05-06 14:00:18 -07:00

README.md

Pulumi Golang SDK

This directory contains support for writing Pulumi programs in the Go language. There are two aspects to this:

  • pulumi/ contains the client language bindings Pulumi program's code directly against;
  • pulumi-language-go/ contains the language host plugin that the Pulumi engine uses to orchestrate updates.

To author a Pulumi program in Go, simply say so in your Pulumi.yaml

name: <my-project>
runtime: go

and ensure you have pulumi-language-go on your path (it is distributed in the Pulumi download automatically).

By default, the language plugin will use your project's name, <my-project>, as the executable that it loads. This too must be on your path for the language provider to load it when you run pulumi preview or pulumi up.