pulumi/tests/integration/construct_component_plain/testcomponent/index.ts
Justin Van Patten f7cc19f89d
[sdk/nodejs] Keep prompt values prompt in construct (#6522)
In order to support prompt values in multi-lang components, if an input value is prompt, keep it as-is instead of wrapping it in an Output.
2021-04-09 14:36:22 -07:00

62 lines
1.7 KiB
TypeScript

// Copyright 2016-2021, Pulumi Corporation. All rights reserved
import * as pulumi from "@pulumi/pulumi";
import * as dynamic from "@pulumi/pulumi/dynamic";
import * as provider from "@pulumi/pulumi/provider";
let currentID = 0;
class Resource extends dynamic.Resource {
constructor(name: string, opts?: pulumi.CustomResourceOptions) {
const provider = {
create: async (inputs: any) => {
return {
id: (currentID++).toString(),
outs: undefined,
};
},
};
super(provider, name, {}, opts);
}
}
interface ComponentArgs {
children?: number;
}
class Component extends pulumi.ComponentResource {
constructor(name: string, args?: ComponentArgs, opts?: pulumi.ComponentResourceOptions) {
super("testcomponent:index:Component", name, {}, opts);
const children = args?.children ?? 0;
if (children <= 0) {
return;
}
for (let i = 0; i < children; i++) {
new Resource(`child-${name}-${i+1}`, {parent: this});
}
}
}
class Provider implements provider.Provider {
public readonly version = "0.0.1";
construct(name: string, type: string, inputs: pulumi.Inputs,
options: pulumi.ComponentResourceOptions): Promise<provider.ConstructResult> {
if (type != "testcomponent:index:Component") {
throw new Error(`unknown resource type ${type}`);
}
const component = new Component(name, inputs, options);
return Promise.resolve({
urn: component.urn,
state: {},
});
}
}
export function main(args: string[]) {
return provider.main(new Provider(), args);
}
main(process.argv.slice(2));