pulumi/tests/integration/partial_state/step1/resource.ts
Alex Clemmer f037c7d143 Checkpoint resource initialization errors
When a resource fails to initialize (i.e., it is successfully created,
but fails to transition to a fully-initialized state), and a user
subsequently runs `pulumi update` without changing that resource, our
CLI will fail to warn the user that this resource is not initialized.

This commit begins the process of allowing our CLI to report this by
storing a list of initialization errors in the checkpoint.
2018-07-20 17:59:06 -07:00

54 lines
1.6 KiB
TypeScript

// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
import * as pulumi from "@pulumi/pulumi";
import * as dynamic from "@pulumi/pulumi/dynamic";
// NOTE: Dynamic provider is restarted every step, so unless we read this from some external state
// store, this would always be 0 anyway.
const id = 0;
export class Provider implements dynamic.ResourceProvider {
public static readonly instance = new Provider();
public async check(olds: any, news: any): Promise<dynamic.CheckResult> {
return {
inputs: news,
};
}
public async create(inputs: any): Promise<dynamic.CreateResult> {
if (inputs.state === 4) {
return Promise.reject({
message: "Resource failed to initialize", id: id.toString(), properties: inputs,
reasons: ["state can't be 4"],
});
}
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: "Resource failed to initialize", id: id.toString(), properties: news,
reasons: ["state can't be 4"],
});
}
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);
}
}