pulumi/tests/integration/partial_state/step1/resource.ts

50 lines
1.4 KiB
TypeScript

// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
import * as pulumi from "@pulumi/pulumi";
import * as dynamic from "@pulumi/pulumi/dynamic";
export class Provider implements dynamic.ResourceProvider {
public static readonly instance = new Provider();
private id: number = 0;
public async check(olds: any, news: any): Promise<dynamic.CheckResult> {
return {
inputs: news,
};
}
public async create(inputs: any): Promise<dynamic.CreateResult> {
const id = (this.id++).toString();
if (inputs.state === 4) {
return Promise.reject({
message: "state can't be 4", id: id.toString(), properties: inputs,
});
}
return {
id: id.toString(),
outs: inputs,
};
}
public async update(id: pulumi.ID, olds: any, news: any): Promise<dynamic.UpdateResult> {
if (news.state === 4) {
return Promise.reject({
message: "state can't be 4", id: id.toString(), properties: news,
});
}
return {
outs: news,
};
}
}
export class Resource extends dynamic.Resource {
public readonly state: pulumi.Output<number>;
constructor(name: string, num: pulumi.Input<number>, opts?: pulumi.ResourceOptions) {
super(Provider.instance, name, { state: num }, opts);
}
}