pulumi/tests/testdata/codegen/secrets-go-generics-only/go/mypkg/resource.go

198 lines
7.2 KiB
Go
Raw Permalink Normal View History

[go/sdk-gen] Fix generics-only option missing ToOutput(...) methods (#14584) # Description PR #14492 removed `ToOutput(...)` methods for output types when generating non-generic SDK variants. The fix there was added to only include these when `side-by-side` is enabled, which implicitly included `generics-only` except for a _single_ place where that wasn't the case 😓 (see comment below in `gen.go`) This PR fixes issue and includes tests for go sdkgen where `generics` setting is set to `generics-only`: - `output-funcs-go-generics-only` - `plain-and-default-go-generics-only` - `secrets-go-generics-only` - `simple-enum-schema-go-generics-only` - `simple-plain-schema-go-generics-only` ## Checklist - [ ] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2023-11-16 18:41:57 +00:00
// Code generated by test DO NOT EDIT.
// *** WARNING: Do not edit by hand unless you're certain you know what you are doing! ***
package mypkg
import (
"context"
"reflect"
"errors"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/pulumi/pulumi/sdk/v3/go/pulumix"
"secrets-go-generics-only/mypkg/internal"
)
type Resource struct {
pulumi.CustomResourceState
Config pulumix.GPtrOutput[Config, ConfigOutput] `pulumi:"config"`
ConfigArray pulumix.GArrayOutput[Config, ConfigOutput] `pulumi:"configArray"`
ConfigMap pulumix.GMapOutput[Config, ConfigOutput] `pulumi:"configMap"`
Foo pulumix.Output[string] `pulumi:"foo"`
FooArray pulumix.ArrayOutput[string] `pulumi:"fooArray"`
FooMap pulumix.MapOutput[string] `pulumi:"fooMap"`
}
// NewResource registers a new resource with the given unique name, arguments, and options.
func NewResource(ctx *pulumi.Context,
name string, args *ResourceArgs, opts ...pulumi.ResourceOption) (*Resource, error) {
if args == nil {
return nil, errors.New("missing one or more required arguments")
}
if args.Config == nil {
return nil, errors.New("invalid value for required argument 'Config'")
}
if args.ConfigArray == nil {
return nil, errors.New("invalid value for required argument 'ConfigArray'")
}
if args.ConfigMap == nil {
return nil, errors.New("invalid value for required argument 'ConfigMap'")
}
if args.Foo == nil {
return nil, errors.New("invalid value for required argument 'Foo'")
}
if args.FooArray == nil {
return nil, errors.New("invalid value for required argument 'FooArray'")
}
if args.FooMap == nil {
return nil, errors.New("invalid value for required argument 'FooMap'")
}
if args.Config != nil {
untypedSecretValue := pulumi.ToSecret(args.Config.ToOutput(ctx.Context()).Untyped())
args.Config = pulumix.MustConvertTyped[*ConfigArgs](untypedSecretValue)
}
if args.ConfigArray != nil {
untypedSecretValue := pulumi.ToSecret(args.ConfigArray.ToOutput(ctx.Context()).Untyped())
args.ConfigArray = pulumix.MustConvertTyped[[]*ConfigArgs](untypedSecretValue)
}
if args.ConfigMap != nil {
untypedSecretValue := pulumi.ToSecret(args.ConfigMap.ToOutput(ctx.Context()).Untyped())
args.ConfigMap = pulumix.MustConvertTyped[map[string]*ConfigArgs](untypedSecretValue)
}
if args.Foo != nil {
untypedSecretValue := pulumi.ToSecret(args.Foo.ToOutput(ctx.Context()).Untyped())
args.Foo = pulumix.MustConvertTyped[string](untypedSecretValue)
}
if args.FooArray != nil {
untypedSecretValue := pulumi.ToSecret(args.FooArray.ToOutput(ctx.Context()).Untyped())
args.FooArray = pulumix.MustConvertTyped[[]string](untypedSecretValue)
}
if args.FooMap != nil {
untypedSecretValue := pulumi.ToSecret(args.FooMap.ToOutput(ctx.Context()).Untyped())
args.FooMap = pulumix.MustConvertTyped[map[string]string](untypedSecretValue)
}
secrets := pulumi.AdditionalSecretOutputs([]string{
"config",
"configArray",
"configMap",
"foo",
"fooArray",
"fooMap",
})
opts = append(opts, secrets)
opts = internal.PkgResourceDefaultOpts(opts)
var resource Resource
err := ctx.RegisterResource("mypkg::Resource", name, args, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// GetResource gets an existing Resource resource's state with the given name, ID, and optional
// state properties that are used to uniquely qualify the lookup (nil if not required).
func GetResource(ctx *pulumi.Context,
name string, id pulumi.IDInput, state *ResourceState, opts ...pulumi.ResourceOption) (*Resource, error) {
var resource Resource
err := ctx.ReadResource("mypkg::Resource", name, id, state, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// Input properties used for looking up and filtering Resource resources.
type resourceState struct {
}
type ResourceState struct {
}
func (ResourceState) ElementType() reflect.Type {
return reflect.TypeOf((*resourceState)(nil)).Elem()
}
type resourceArgs struct {
Config Config `pulumi:"config"`
ConfigArray []Config `pulumi:"configArray"`
ConfigMap map[string]Config `pulumi:"configMap"`
Foo string `pulumi:"foo"`
FooArray []string `pulumi:"fooArray"`
FooMap map[string]string `pulumi:"fooMap"`
}
// The set of arguments for constructing a Resource resource.
type ResourceArgs struct {
Config pulumix.Input[*ConfigArgs]
ConfigArray pulumix.Input[[]*ConfigArgs]
ConfigMap pulumix.Input[map[string]*ConfigArgs]
Foo pulumix.Input[string]
FooArray pulumix.Input[[]string]
FooMap pulumix.Input[map[string]string]
}
func (ResourceArgs) ElementType() reflect.Type {
return reflect.TypeOf((*resourceArgs)(nil)).Elem()
}
type ResourceOutput struct{ *pulumi.OutputState }
func (ResourceOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Resource)(nil)).Elem()
}
func (o ResourceOutput) ToResourceOutput() ResourceOutput {
return o
}
func (o ResourceOutput) ToResourceOutputWithContext(ctx context.Context) ResourceOutput {
return o
}
func (o ResourceOutput) ToOutput(ctx context.Context) pulumix.Output[Resource] {
return pulumix.Output[Resource]{
OutputState: o.OutputState,
}
}
func (o ResourceOutput) Config() pulumix.GPtrOutput[Config, ConfigOutput] {
value := pulumix.Apply[Resource](o, func(v Resource) pulumix.GPtrOutput[Config, ConfigOutput] { return v.Config })
unwrapped := pulumix.Flatten[*Config, pulumix.GPtrOutput[Config, ConfigOutput]](value)
return pulumix.GPtrOutput[Config, ConfigOutput]{OutputState: unwrapped.OutputState}
}
func (o ResourceOutput) ConfigArray() pulumix.GArrayOutput[Config, ConfigOutput] {
value := pulumix.Apply[Resource](o, func(v Resource) pulumix.GArrayOutput[Config, ConfigOutput] { return v.ConfigArray })
unwrapped := pulumix.Flatten[[]Config, pulumix.GArrayOutput[Config, ConfigOutput]](value)
return pulumix.GArrayOutput[Config, ConfigOutput]{OutputState: unwrapped.OutputState}
}
func (o ResourceOutput) ConfigMap() pulumix.GMapOutput[Config, ConfigOutput] {
value := pulumix.Apply[Resource](o, func(v Resource) pulumix.GMapOutput[Config, ConfigOutput] { return v.ConfigMap })
unwrapped := pulumix.Flatten[map[string]Config, pulumix.GMapOutput[Config, ConfigOutput]](value)
return pulumix.GMapOutput[Config, ConfigOutput]{OutputState: unwrapped.OutputState}
}
func (o ResourceOutput) Foo() pulumix.Output[string] {
value := pulumix.Apply[Resource](o, func(v Resource) pulumix.Output[string] { return v.Foo })
return pulumix.Flatten[string, pulumix.Output[string]](value)
}
func (o ResourceOutput) FooArray() pulumix.ArrayOutput[string] {
value := pulumix.Apply[Resource](o, func(v Resource) pulumix.ArrayOutput[string] { return v.FooArray })
unwrapped := pulumix.Flatten[[]string, pulumix.ArrayOutput[string]](value)
return pulumix.ArrayOutput[string]{OutputState: unwrapped.OutputState}
}
func (o ResourceOutput) FooMap() pulumix.MapOutput[string] {
value := pulumix.Apply[Resource](o, func(v Resource) pulumix.MapOutput[string] { return v.FooMap })
unwrapped := pulumix.Flatten[map[string]string, pulumix.MapOutput[string]](value)
return pulumix.MapOutput[string]{OutputState: unwrapped.OutputState}
}
func init() {
pulumi.RegisterOutputType(ResourceOutput{})
}