pulumi/examples/dynamic-provider/derived-inputs/index.ts
CyrusNajmabadi 275670692b
Introduce Output<T> and update Resource construction code to properly handle it. (#834)
This PR adds a new formalisms at the Resource layer.  First all inputs to a Resource are typed as ```Input<T>```.  This is either a T, ```Promise<T>``
2018-02-05 14:44:23 -08:00

35 lines
1 KiB
TypeScript

// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
import * as pulumi from "pulumi";
import * as dynamic from "pulumi/dynamic";
const sleep = require("sleep-promise");
const assert = require("assert");
class InputProvider implements dynamic.ResourceProvider {
check = (olds: any, news: any) => {
assert(news.input);
return Promise.resolve({ inputs: news });
};
diff = (id: pulumi.ID, olds: any, news: any) => Promise.resolve({});
create = (inputs: any) => Promise.resolve({ id: "0" });
update = (id: string, olds: any, news: any) => Promise.resolve({});
delete = (id: pulumi.ID, props: any) => Promise.resolve();
}
class InputResource extends dynamic.Resource {
constructor(name: string, input: pulumi.Input<string>) {
super(new InputProvider(), name, { input: input }, undefined);
}
}
(async () => {
try {
const a = new InputResource("a", "string");
const b = new InputResource("b", a.urn);
} catch (err) {
console.error(err);
process.exit(-1);
}
})();