pulumi/sdk
Aaron Friel 933c2027c5 Go generics proof of concept with interoperability
This is a proof of concept for implementing Output[T], provisionally called
Promise[T] in this branch. Deviating from the work of Joe Duffy, we seek to
maintain support for the existing Output type.

The OutputState type, whose internals were always hidden to users, are now
implemented using a promiseState[any]. That is, all Outputs embed a Promise.

This enables relatively seemless interoperability between Outputs and Promises.
Conversion to Promise[any] is a no-op, and conversion from Promise[T] to an
AnyOutput is handled with an Apply.

The new Promise *is* a Monad: apply is fmap and a join function is provided to
flatten Promise[Promise[T]]. This is because the type system does not otherwise
allow us to express that operation without a join.

---

This is a basic proof of concept for using Go generics in our Go
SDK. There were a number of "on the fly" design decisions made:

* Replace Input altogether.

* Keep Output[T], but it needs to be a struct largely due to the
  lack of generics support in the Go reflection library.

* Introduce AnyOutput as a base interface that all Output[*]s
  implement, which lets us treat any "outputtish" things uniformly.

This is enough to get the basic hello, world working:

  package main

  import (
      "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
  )

  func main() {
      pulumi.Run(func(ctx *pulumi.Context) error {
          var bucket Bucket
          if err := ctx.RegisterResource("aws:s3/bucket:Bucket", "myBucket", pulumi.Map{}, &bucket); err != nil {
              return err
          }

          ctx.Export("bucketName", bucket.Bucket)

          nameLength := pulumi.Apply(bucket.Bucket, func(name string) int {
              return len(name)
          })
          ctx.Export("bucketNameLength", nameLength)

          return nil
      })
  }

There are plenty of embarassing hacks needed to get this to work,
and some blatent omissions too. For instance, I doubt Any works, and
obviously the tests won't run clean. Nevertheless, I wanted to save/
archive/share this work in the event that it's helpful to someone.

Joe Duffy <joe@pulumi.com>
Aaron Friel <friel@pulumi.com>
2022-09-25 18:11:08 -07:00
..
dotnet Make getOrganization total, default to 'organization' 2022-09-22 11:06:51 -07:00
go Go generics proof of concept with interoperability 2022-09-25 18:11:08 -07:00
nodejs Merge #10820 #10833 2022-09-22 18:59:18 +00:00
proto/go Fix the go_package option on the .proto files 2022-09-20 09:31:03 +01:00
python Make getOrganization total, default to 'organization' 2022-09-22 11:06:51 -07:00
README.md Compile protobufs with "pulumi" namespace (#10074) 2022-07-12 14:45:03 +01:00
go.mod Go generics proof of concept with interoperability 2022-09-25 18:11:08 -07:00
go.sum Use project schema to validate projects we load 2022-09-02 10:09:24 +01:00

README.md

Pulumi Language SDKs

This directory contains the Pulumi SDKs for all supported languages.

Please see the respective READMEs for information about installing and using these libraries:

The language providers work by implementing gRPC interfaces defined in the top level directory proto.