github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/codegen/testing/test/testdata/plain-object-defaults/go/example/foo.go (about)

     1  // Code generated by test DO NOT EDIT.
     2  // *** WARNING: Do not edit by hand unless you're certain you know what you are doing! ***
     3  
     4  package example
     5  
     6  import (
     7  	"context"
     8  	"reflect"
     9  
    10  	"github.com/pkg/errors"
    11  	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    12  )
    13  
    14  // test new feature with resoruces
    15  type Foo struct {
    16  	pulumi.CustomResourceState
    17  
    18  	// A test for plain types
    19  	DefaultKubeClientSettings KubeClientSettingsPtrOutput `pulumi:"defaultKubeClientSettings"`
    20  }
    21  
    22  // NewFoo registers a new resource with the given unique name, arguments, and options.
    23  func NewFoo(ctx *pulumi.Context,
    24  	name string, args *FooArgs, opts ...pulumi.ResourceOption) (*Foo, error) {
    25  	if args == nil {
    26  		return nil, errors.New("missing one or more required arguments")
    27  	}
    28  
    29  	if args.BackupKubeClientSettings == nil {
    30  		return nil, errors.New("invalid value for required argument 'BackupKubeClientSettings'")
    31  	}
    32  	args.BackupKubeClientSettings = args.BackupKubeClientSettings.ToKubeClientSettingsOutput().ApplyT(func(v KubeClientSettings) KubeClientSettings { return *v.Defaults() }).(KubeClientSettingsOutput)
    33  	if args.KubeClientSettings != nil {
    34  		args.KubeClientSettings = args.KubeClientSettings.ToKubeClientSettingsPtrOutput().ApplyT(func(v *KubeClientSettings) *KubeClientSettings { return v.Defaults() }).(KubeClientSettingsPtrOutput)
    35  	}
    36  	if args.Settings != nil {
    37  		args.Settings = args.Settings.ToLayeredTypePtrOutput().ApplyT(func(v *LayeredType) *LayeredType { return v.Defaults() }).(LayeredTypePtrOutput)
    38  	}
    39  	var resource Foo
    40  	err := ctx.RegisterResource("example:index:Foo", name, args, &resource, opts...)
    41  	if err != nil {
    42  		return nil, err
    43  	}
    44  	return &resource, nil
    45  }
    46  
    47  // GetFoo gets an existing Foo resource's state with the given name, ID, and optional
    48  // state properties that are used to uniquely qualify the lookup (nil if not required).
    49  func GetFoo(ctx *pulumi.Context,
    50  	name string, id pulumi.IDInput, state *FooState, opts ...pulumi.ResourceOption) (*Foo, error) {
    51  	var resource Foo
    52  	err := ctx.ReadResource("example:index:Foo", name, id, state, &resource, opts...)
    53  	if err != nil {
    54  		return nil, err
    55  	}
    56  	return &resource, nil
    57  }
    58  
    59  // Input properties used for looking up and filtering Foo resources.
    60  type fooState struct {
    61  }
    62  
    63  type FooState struct {
    64  }
    65  
    66  func (FooState) ElementType() reflect.Type {
    67  	return reflect.TypeOf((*fooState)(nil)).Elem()
    68  }
    69  
    70  type fooArgs struct {
    71  	Argument *string `pulumi:"argument"`
    72  	// Options for tuning the Kubernetes client used by a Provider.
    73  	BackupKubeClientSettings KubeClientSettings `pulumi:"backupKubeClientSettings"`
    74  	// Options for tuning the Kubernetes client used by a Provider.
    75  	KubeClientSettings *KubeClientSettings `pulumi:"kubeClientSettings"`
    76  	// describing things
    77  	Settings *LayeredType `pulumi:"settings"`
    78  }
    79  
    80  // The set of arguments for constructing a Foo resource.
    81  type FooArgs struct {
    82  	Argument *string
    83  	// Options for tuning the Kubernetes client used by a Provider.
    84  	BackupKubeClientSettings KubeClientSettingsInput
    85  	// Options for tuning the Kubernetes client used by a Provider.
    86  	KubeClientSettings KubeClientSettingsPtrInput
    87  	// describing things
    88  	Settings LayeredTypePtrInput
    89  }
    90  
    91  func (FooArgs) ElementType() reflect.Type {
    92  	return reflect.TypeOf((*fooArgs)(nil)).Elem()
    93  }
    94  
    95  type FooInput interface {
    96  	pulumi.Input
    97  
    98  	ToFooOutput() FooOutput
    99  	ToFooOutputWithContext(ctx context.Context) FooOutput
   100  }
   101  
   102  func (*Foo) ElementType() reflect.Type {
   103  	return reflect.TypeOf((**Foo)(nil)).Elem()
   104  }
   105  
   106  func (i *Foo) ToFooOutput() FooOutput {
   107  	return i.ToFooOutputWithContext(context.Background())
   108  }
   109  
   110  func (i *Foo) ToFooOutputWithContext(ctx context.Context) FooOutput {
   111  	return pulumi.ToOutputWithContext(ctx, i).(FooOutput)
   112  }
   113  
   114  type FooOutput struct{ *pulumi.OutputState }
   115  
   116  func (FooOutput) ElementType() reflect.Type {
   117  	return reflect.TypeOf((**Foo)(nil)).Elem()
   118  }
   119  
   120  func (o FooOutput) ToFooOutput() FooOutput {
   121  	return o
   122  }
   123  
   124  func (o FooOutput) ToFooOutputWithContext(ctx context.Context) FooOutput {
   125  	return o
   126  }
   127  
   128  // A test for plain types
   129  func (o FooOutput) DefaultKubeClientSettings() KubeClientSettingsPtrOutput {
   130  	return o.ApplyT(func(v *Foo) KubeClientSettingsPtrOutput { return v.DefaultKubeClientSettings }).(KubeClientSettingsPtrOutput)
   131  }
   132  
   133  func init() {
   134  	pulumi.RegisterInputType(reflect.TypeOf((*FooInput)(nil)).Elem(), &Foo{})
   135  	pulumi.RegisterOutputType(FooOutput{})
   136  }