Skip to content

Instantly share code, notes, and snippets.

@levand
Created January 25, 2019 19:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save levand/0b77a9dec11b46bb9e3b71d77204d7ca to your computer and use it in GitHub Desktop.
Save levand/0b77a9dec11b46bb9e3b71d77204d7ca to your computer and use it in GitHub Desktop.
PulumiContext utility
const pulumi = require("@pulumi/pulumi");
const deepmerge = require('deepmerge');
const isPlainObject = require('is-plain-object');
const merge = function(x, y) {
return deepmerge(x || {} ,y || {}, { isMergeableObject: isPlainObject });
};
class PulumiContext {
constructor(props, opts) {
this.props = props;
this.opts = opts;
}
withProps(props) {
return new PulumiContext(merge(this.props, props), this.opts);
}
withOpts(opts) {
return new PulumiContext(this.props, merge(this.opts, opts));
}
r(ctor, name, props, opts) {
return new ctor(name, merge(this.props, props), merge(this.opts, opts));
}
withComponent(type, name) {
let c = new pulumi.ComponentResource(type, name, null, this.opts);
return this.withOpts({parent: c});
}
}
exports.PulumiContext = PulumiContext;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment