Skip to content

Commit

Permalink
Merge pull request #3 from wttech/add-check
Browse files Browse the repository at this point in the history
added check command
  • Loading branch information
dominik-przybyl-wttech authored Feb 23, 2024
2 parents 8c9f72e + 4357111 commit 77a47c3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
4 changes: 1 addition & 3 deletions examples/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 9 additions & 1 deletion provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package provider

import (
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"math/rand"
"time"

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
16 changes: 6 additions & 10 deletions sdk/go/aem/compose/instanceResourceModel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions sdk/nodejs/compose/instanceResourceModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class InstanceResourceModel extends pulumi.CustomResource {
return obj['__pulumiType'] === InstanceResourceModel.__pulumiType;
}

public readonly length!: pulumi.Output<number>;
public readonly length!: pulumi.Output<number | undefined>;
public /*out*/ readonly result!: pulumi.Output<string>;

/**
Expand All @@ -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 {
Expand All @@ -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<number>;
length?: pulumi.Input<number>;
}
14 changes: 9 additions & 5 deletions tests/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 77a47c3

Please sign in to comment.