diff --git a/examples/go/main.go b/examples/go/main.go index 6a929a0..546a4ba 100644 --- a/examples/go/main.go +++ b/examples/go/main.go @@ -7,9 +7,7 @@ import ( func main() { pulumi.Run(func(ctx *pulumi.Context) error { - myModel, err := compose.NewInstanceResourceModel(ctx, "myModel", &compose.InstanceResourceModelArgs{ - Length: pulumi.Int(24), - }) + myModel, err := compose.NewInstanceResourceModel(ctx, "myModel", &compose.InstanceResourceModelArgs{}) if err != nil { return err } diff --git a/provider/provider.go b/provider/provider.go index 4511bb7..b67cb08 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -15,6 +15,7 @@ package provider import ( + "github.com/pulumi/pulumi/sdk/v3/go/common/resource" "math/rand" "time" @@ -58,7 +59,7 @@ type InstanceResourceModelArgs struct { // Fields projected into Pulumi must be public and hava a `pulumi:"..."` tag. // The pulumi tag doesn't need to match the field name, but it's generally a // good idea. - Length int `pulumi:"length"` + Length int `pulumi:"length,optional"` } // Each resource has a state, describing the fields that exist on the created resource. @@ -89,3 +90,10 @@ func determineResult(length int) string { } return string(result) } + +func (InstanceResourceModel) Check(ctx p.Context, name string, oldInputs, newInputs resource.PropertyMap) (InstanceResourceModelArgs, []p.CheckFailure, error) { + if _, ok := newInputs["length"]; !ok { + newInputs["length"] = resource.NewNumberProperty(12) + } + return infer.DefaultCheck[InstanceResourceModelArgs](newInputs) +} diff --git a/sdk/go/aem/compose/instanceResourceModel.go b/sdk/go/aem/compose/instanceResourceModel.go index 4abfe88..d5b7219 100644 --- a/sdk/go/aem/compose/instanceResourceModel.go +++ b/sdk/go/aem/compose/instanceResourceModel.go @@ -7,7 +7,6 @@ import ( "context" "reflect" - "errors" "github.com/pulumi/pulumi/sdk/v3/go/pulumi" "github.com/wttech/pulumi-provider-aem/sdk/go/aem/internal" ) @@ -15,7 +14,7 @@ import ( type InstanceResourceModel struct { pulumi.CustomResourceState - Length pulumi.IntOutput `pulumi:"length"` + Length pulumi.IntPtrOutput `pulumi:"length"` Result pulumi.StringOutput `pulumi:"result"` } @@ -23,12 +22,9 @@ type InstanceResourceModel struct { func NewInstanceResourceModel(ctx *pulumi.Context, name string, args *InstanceResourceModelArgs, opts ...pulumi.ResourceOption) (*InstanceResourceModel, error) { if args == nil { - return nil, errors.New("missing one or more required arguments") + args = &InstanceResourceModelArgs{} } - if args.Length == nil { - return nil, errors.New("invalid value for required argument 'Length'") - } opts = internal.PkgResourceDefaultOpts(opts) var resource InstanceResourceModel err := ctx.RegisterResource("aem:compose:InstanceResourceModel", name, args, &resource, opts...) @@ -62,12 +58,12 @@ func (InstanceResourceModelState) ElementType() reflect.Type { } type instanceResourceModelArgs struct { - Length int `pulumi:"length"` + Length *int `pulumi:"length"` } // The set of arguments for constructing a InstanceResourceModel resource. type InstanceResourceModelArgs struct { - Length pulumi.IntInput + Length pulumi.IntPtrInput } func (InstanceResourceModelArgs) ElementType() reflect.Type { @@ -107,8 +103,8 @@ func (o InstanceResourceModelOutput) ToInstanceResourceModelOutputWithContext(ct return o } -func (o InstanceResourceModelOutput) Length() pulumi.IntOutput { - return o.ApplyT(func(v *InstanceResourceModel) pulumi.IntOutput { return v.Length }).(pulumi.IntOutput) +func (o InstanceResourceModelOutput) Length() pulumi.IntPtrOutput { + return o.ApplyT(func(v *InstanceResourceModel) pulumi.IntPtrOutput { return v.Length }).(pulumi.IntPtrOutput) } func (o InstanceResourceModelOutput) Result() pulumi.StringOutput { diff --git a/sdk/nodejs/compose/instanceResourceModel.ts b/sdk/nodejs/compose/instanceResourceModel.ts index 2077549..4045cbb 100644 --- a/sdk/nodejs/compose/instanceResourceModel.ts +++ b/sdk/nodejs/compose/instanceResourceModel.ts @@ -31,7 +31,7 @@ export class InstanceResourceModel extends pulumi.CustomResource { return obj['__pulumiType'] === InstanceResourceModel.__pulumiType; } - public readonly length!: pulumi.Output; + public readonly length!: pulumi.Output; public /*out*/ readonly result!: pulumi.Output; /** @@ -41,13 +41,10 @@ export class InstanceResourceModel extends pulumi.CustomResource { * @param args The arguments to use to populate this resource's properties. * @param opts A bag of options that control this resource's behavior. */ - constructor(name: string, args: InstanceResourceModelArgs, opts?: pulumi.CustomResourceOptions) { + constructor(name: string, args?: InstanceResourceModelArgs, opts?: pulumi.CustomResourceOptions) { let resourceInputs: pulumi.Inputs = {}; opts = opts || {}; if (!opts.id) { - if ((!args || args.length === undefined) && !opts.urn) { - throw new Error("Missing required property 'length'"); - } resourceInputs["length"] = args ? args.length : undefined; resourceInputs["result"] = undefined /*out*/; } else { @@ -63,5 +60,5 @@ export class InstanceResourceModel extends pulumi.CustomResource { * The set of arguments for constructing a InstanceResourceModel resource. */ export interface InstanceResourceModelArgs { - length: pulumi.Input; + length?: pulumi.Input; } diff --git a/tests/provider_test.go b/tests/provider_test.go index e51f4f0..57a2019 100644 --- a/tests/provider_test.go +++ b/tests/provider_test.go @@ -31,12 +31,16 @@ import ( func TestInstanceResourceModelCreate(t *testing.T) { prov := provider() + checkResponse, err := prov.Check(p.CheckRequest{ + Urn: urn("InstanceResourceModel"), + News: resource.PropertyMap{}, + }) + require.NoError(t, err) + response, err := prov.Create(p.CreateRequest{ - Urn: urn("InstanceResourceModel"), - Properties: resource.PropertyMap{ - "length": resource.NewNumberProperty(12), - }, - Preview: false, + Urn: urn("InstanceResourceModel"), + Properties: checkResponse.Inputs, + Preview: false, }) require.NoError(t, err)