pulumi/pkg/codegen/testing/test/testdata/provider-config-schema/go/configstation
Aaron Friel 695360ac19 fix(sdkgen/go): illegal cast in resource constructors when secret-wrapping input arguments
Codegen for wrapping input properties as secrets performed an incorrect cast, as
seen in Pulumi's AWS classic SDK.

Using the sample program and the resource constructor described in #11664 as our
 test case, from `pulumi-aws/sdk/v5/go/aws/secretmanager/secretVersion.go`:

```go
      func NewSecretVersion(ctx *pulumi.Context,
        name string, args *SecretVersionArgs, opts ...pulumi.ResourceOption) (*SecretVersion, error) {
        if args == nil {
          return nil, errors.New("missing one or more required arguments")
        }

        if args.SecretId == nil {
          return nil, errors.New("invalid value for required argument 'SecretId'")
        }
        if args.SecretBinary != nil {
82:        args.SecretBinary = pulumi.ToSecret(args.SecretBinary).(pulumi.StringPtrOutput)
        }
        if args.SecretString != nil {
85:        args.SecretString = pulumi.ToSecret(args.SecretString).(pulumi.StringPtrOutput)
        }
```

`args.SecretBinary` is of type `pulumi.StringPtrInput` and `pulumi.ToSecret`
returns `pulumi.Output` returns its input as an Output-wrapped value marked
secret.

As `StringPtrInput` is an interface accepting multiple input types, the return
value would be either `pulumi.StringOutput` `pulumi.StringPtrOutput`. These are
both concrete types, and casting to the incorrect one would panic.

Fortunately we can cast back to the arg's type, as verified by building the new
codegen and testing the Pulumi program in #11664. This should handle regular
inputs and plain inputs.

The new codegen below converts an input type `T` to `pulumi.Output`, then casts
back to `T`.

```go
      func NewSecretVersion(ctx *pulumi.Context,
        // ...
        if args.SecretBinary != nil {
82:             args.SecretBinary = pulumi.ToSecret(args.SecretBinary).(pulumi.StringPtrInput)
        }
        if args.SecretString != nil {
85:             args.SecretString = pulumi.ToSecret(args.SecretString).(pulumi.StringPtrInput)
        }
```
2022-12-16 17:27:10 -08:00
..
config modify codegen/python to generate valid python code for non-string secrets 2022-12-07 11:36:15 -08:00
doc.go codegen/go: Remove superfluous newline in doc.go 2022-11-30 14:17:13 +00:00
funcWithAllOptionalInputs.go Commit codegen changes that were not applied to python, typescript and go 2022-09-15 11:14:02 +02:00
init.go Idiomatic Go: generated code message (#9419) 2022-04-19 18:39:23 +02:00
provider.go fix(sdkgen/go): illegal cast in resource constructors when secret-wrapping input arguments 2022-12-16 17:27:10 -08:00
pulumi-plugin.json export codegen tests for internal use (#8928) 2022-02-07 12:10:04 +01:00
pulumiEnums.go ci: gofmt 1.18+ clean 2022-09-21 09:48:39 -07:00
pulumiTypes.go ci: gofmt 1.18+ clean 2022-09-21 09:48:39 -07:00
pulumiUtilities.go Idiomatic Go: generated code message (#9419) 2022-04-19 18:39:23 +02:00