Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
//
// 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) => U, opts?: pulumi.CustomResourceOptions) {
const provider = {
check: (olds: any, news: any) => Promise.resolve({ inputs: news, failedChecks: [] }),
diff: (id: pulumi.ID, olds: any, news: any) => Promise.resolve({}),
create: (inputs: any) => Promise.resolve({
id: name,
outs: { output: func(inputs.input as T) },
}),
update: (id: pulumi.ID, olds: any, news: any) => Promise.resolve({
outs: { output: func(news.input as T) },
}),
read: (id: pulumi.ID, state: any) => Promise.resolve({id: id, props: state}),
delete: (id: pulumi.ID, props: any) => Promise.resolve(),
};</u>
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);
}
}
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)
}
}
const sleep = require("sleep-promise");
class InputProvider implements dynamic.ResourceProvider {
check = (olds: any, news: any) => {
const assert = require("assert");
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) {
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);
}
})();
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, input: any) {
super(new NullProvider(), name, {input: input}, undefined);
}
}
async function getInput(): Promise> {
await sleep(1000);
return (new NullResource("a", "")).urn;
}
const b = new NullResource("b", getInput());
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 {
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) {
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);
}
}