Skip to content

Instantly share code, notes, and snippets.

@timmyers
Last active February 9, 2021 19:38
Show Gist options
  • Save timmyers/240f5234f6cbd4666ba185a1f7ecfc03 to your computer and use it in GitHub Desktop.
Save timmyers/240f5234f6cbd4666ba185a1f7ecfc03 to your computer and use it in GitHub Desktop.
Pulumi resource opts mutation
import * as pulumi from '@pulumi/pulumi';
import * as aws from '@pulumi/aws';
import * as datadog from '@pulumi/datadog';
export class MutatedResource extends pulumi.ComponentResource {
public constructor(name: string, args: {}, opts?: pulumi.ComponentResourceOptions) {
super('test:mutation', name, {}, opts);
// Totally reasonable shared options
const defaultOpts: pulumi.CustomResourceOptions = { parent: this };
// defaultOpts.version === undefined
// I am going to mutate defaultOpts
const role = new aws.iam.Role(name, {
assumeRolePolicy: '',
}, defaultOpts);
// defaultOpts.version === i.e. 3.28.0 https://github.com/pulumi/pulumi-aws/releases/tag/v3.28.0
// BAD THINGS HAPPEN HERE
// Since defaultOpts.version == 3.28.0, a datadog.Provider will be constructed using that version which is WRONG.
new datadog.Monitor(name, {
name: 'test',
message: 'test',
query: 'test',
type: 'test',
}, defaultOpts);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment