Created
January 25, 2019 19:51
-
-
Save levand/0b77a9dec11b46bb9e3b71d77204d7ca to your computer and use it in GitHub Desktop.
PulumiContext utility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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