How to use the @pulumi/pulumi/dynamic.Resource function in @pulumi/pulumi

To help you get started, we’ve selected a few @pulumi/pulumi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pulumi / pulumi-eks / nodejs / eks / transform.ts View on Github external
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import * as pulumi from "@pulumi/pulumi";
import * as dynamic from "@pulumi/pulumi/dynamic";

/**
 * Transform is a dynamic resource that evaluates a function when its inputs change and exports the result.
 */
class Transform extends dynamic.Resource {
    public readonly output: pulumi.Output<u>;

    constructor(name: string, input: T, func: (v: T) =&gt; U, opts?: pulumi.CustomResourceOptions) {
        const provider = {
            check: (olds: any, news: any) =&gt; Promise.resolve({ inputs: news, failedChecks: [] }),
            diff: (id: pulumi.ID, olds: any, news: any) =&gt; Promise.resolve({}),
            create: (inputs: any) =&gt; Promise.resolve({
                id: name,
                outs: { output: func(inputs.input as T) },
            }),
            update: (id: pulumi.ID, olds: any, news: any) =&gt; Promise.resolve({
                outs: { output: func(news.input as T) },
            }),
            read: (id: pulumi.ID, state: any) =&gt; Promise.resolve({id: id, props: state}),
            delete: (id: pulumi.ID, props: any) =&gt; Promise.resolve(),
        };</u>
github pulumi / pulumi / tests / integration / partial_state / step1 / resource.ts View on Github external
public async update(id: pulumi.ID, olds: any, news: any): Promise {
        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;

    constructor(name: string, num: pulumi.Input, opts?: pulumi.ResourceOptions) {
        super(Provider.instance, name, { state: num }, opts);
    }
}
github pulumi / pulumi / tests / integration / secret_outputs / res.ts View on Github external
import * as pulumi from "@pulumi/pulumi";
import * as dynamic from "@pulumi/pulumi/dynamic";

export interface RArgs {
    prefix: pulumi.Input
}

const provider: pulumi.dynamic.ResourceProvider = {
    async create(inputs) {
        return { id: "1", outs: {
            prefix: inputs["prefix"]
        }};
    }
}

export class R extends dynamic.Resource {
    public prefix!: pulumi.Output;

    constructor(name: string, props: RArgs, opts?: pulumi.CustomResourceOptions) {
        super(provider, name, props, opts)
    }
}
github pulumi / pulumi / examples / dynamic-provider / derived-inputs / index.ts View on Github external
const sleep = require("sleep-promise");

class InputProvider implements dynamic.ResourceProvider {
    check = (olds: any, news: any) =&gt; {
        const assert = require("assert");
		assert(news.input);
		return Promise.resolve({ inputs: news });
	};
    diff = (id: pulumi.ID, olds: any, news: any) =&gt; Promise.resolve({});
    create = (inputs: any) =&gt; Promise.resolve({ id: "0" });
    update = (id: string, olds: any, news: any) =&gt; Promise.resolve({});
    delete = (id: pulumi.ID, props: any) =&gt; Promise.resolve();
}

class InputResource extends dynamic.Resource {
    constructor(name: string, input: pulumi.Input) {
        super(new InputProvider(), name, { input: input }, undefined);
    }
}

(async () =&gt; {
    try {
        const a = new InputResource("a", "string");
		const b = new InputResource("b", a.urn);
    } catch (err) {
        console.error(err);
        process.exit(-1);
    }
})();
github pulumi / pulumi / examples / dynamic-provider / multiple-turns-2 / index.ts View on Github external
import * as pulumi from "@pulumi/pulumi";
import * as dynamic from "@pulumi/pulumi/dynamic";

const sleep = require("sleep-promise");
const assert = require("assert");

class NullProvider implements dynamic.ResourceProvider {
    check = (olds: any, news: any) =&gt; Promise.resolve({ inputs: news });
    diff = (id: pulumi.ID, olds: any, news: any) =&gt; Promise.resolve({});
    create = (inputs: any) =&gt; Promise.resolve({ id: "0" });
    update = (id: string, olds: any, news: any) =&gt; Promise.resolve({});
    delete = (id: pulumi.ID, props: any) =&gt; Promise.resolve();
}

class NullResource extends dynamic.Resource {
    constructor(name: string, input: any) {
        super(new NullProvider(), name, {input: input}, undefined);
    }
}

async function getInput(): Promise&gt; {
    await sleep(1000);

    return (new NullResource("a", "")).urn;
}

const b = new NullResource("b", getInput());
github pulumi / pulumi / examples / secrets / provider.ts View on Github external
import * as pulumi from "@pulumi/pulumi";
import * as dynamic from "@pulumi/pulumi/dynamic";

class ReflectProvider implements dynamic.ResourceProvider {
    public check(olds: any, news: any) { return Promise.resolve({ inputs: news }); }
    public diff(id: pulumi.ID, olds: any, news: any) { return Promise.resolve({}); }
    public delete(id: pulumi.ID, props: any) { return Promise.resolve(); }
    public create(inputs: any) { return Promise.resolve({ id: "0", outs: inputs }); }
    public update(id: string, olds: any, news: any) { return Promise.resolve({ outs: news }); }
}

export class ReflectResource extends dynamic.Resource {
    public readonly value!: pulumi.Output;

    constructor(name: string, value: pulumi.Input, opts?: pulumi.CustomResourceOptions) {
        super(new ReflectProvider(), name, {value: value}, opts);
    }
}

class DummyProvider implements dynamic.ResourceProvider {
    public check(olds: any, news: any) { return Promise.resolve({ inputs: news }); }
    public diff(id: pulumi.ID, olds: any, news: any) { return Promise.resolve({}); }
    public delete(id: pulumi.ID, props: any) { return Promise.resolve(); }
    public create(inputs: any) { return Promise.resolve({ id: "0", outs: {"value": "hello"} }); }
    public update(id: string, olds: any, news: any) { return Promise.resolve({ outs: news }); }
}

export class DummyResource extends dynamic.Resource {
github pulumi / pulumi / examples / dynamic-provider / multiple-turns / index.ts View on Github external
import * as pulumi from "@pulumi/pulumi";
import * as dynamic from "@pulumi/pulumi/dynamic";

const sleep = require("sleep-promise");
const assert = require("assert");

class NullProvider implements dynamic.ResourceProvider {
    check = (olds: any, news: any) => 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 NullResource extends dynamic.Resource {
    constructor(name: string) {
        super(new NullProvider(), name, {}, undefined);
    }
}

(async () => {
    try {
        const a = new NullResource("a");
        await sleep(1000);
        const b = new NullResource("b");
        await sleep(1000);
        const c = new NullResource("c");
        const urn = await b.urn;
        assert.notStrictEqual(urn, undefined, "expected a defined urn");
        assert.notStrictEqual(urn, "", "expected a valid urn");
    } catch (err) {
github pulumi / pulumi / examples / secrets / provider.ts View on Github external
public readonly value!: pulumi.Output;

    constructor(name: string, value: pulumi.Input, opts?: pulumi.CustomResourceOptions) {
        super(new ReflectProvider(), name, {value: value}, opts);
    }
}

class DummyProvider implements dynamic.ResourceProvider {
    public check(olds: any, news: any) { return Promise.resolve({ inputs: news }); }
    public diff(id: pulumi.ID, olds: any, news: any) { return Promise.resolve({}); }
    public delete(id: pulumi.ID, props: any) { return Promise.resolve(); }
    public create(inputs: any) { return Promise.resolve({ id: "0", outs: {"value": "hello"} }); }
    public update(id: string, olds: any, news: any) { return Promise.resolve({ outs: news }); }
}

export class DummyResource extends dynamic.Resource {
    public readonly value!: pulumi.Output;

    constructor(name: string, opts?: pulumi.CustomResourceOptions) {
        super(new DummyProvider(), name, {}, opts);
    }
}