Skip to content

Commit

Permalink
Migrate from transformations to transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
tlinhart committed Sep 2, 2024
1 parent ca9e5bf commit 769f4a0
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion examples/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"dependencies": {
"@pulumi/aws": "^6.0.0",
"@pulumi/pulumi": "^3.0.0",
"@pulumi/pulumi": "^3.118.0",
"pulumi-aws-tags": "^0"
}
}
2 changes: 1 addition & 1 deletion examples/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pulumi>=3.0.0
pulumi>=3.118.0
pulumi_aws>=6.0.0
pulumi_aws_tags>=0.7.0
13 changes: 6 additions & 7 deletions nodejs/autotag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@ import {isTaggable} from "./taggable";
const UNSUPPORTED_RESOURCE_TYPES: string[] = ["aws:autoscaling/group:Group"];

/**
* Register a global auto-tagging stack transformation.
* Register a global auto-tagging stack transform.
*
* The transformation merges a set of given tags with whatever was also
* explicitly added to the resource definition.
* The transform merges a set of given tags with whatever was also explicitly
* added to the resource definition.
*/
export function registerAutoTags(autoTags: Record<string, string>): void {
pulumi.runtime.registerStackTransformation((args) => {
pulumi.runtime.registerResourceTransform((args) => {
if (isTaggable(args.type)) {
if (UNSUPPORTED_RESOURCE_TYPES.includes(args.type)) {
// See https://github.com/pulumi/pulumi/issues/16654 for why we cannot
// associate the message with the resource.
pulumi.log.warn(
`resource of type ${args.type} does not support auto-tagging`
);
return undefined;
}
args.props["tags"] = {...args.props["tags"], ...autoTags};
const tags = pulumi.output(args.props.tags || {});
args.props.tags = tags.apply((tags) => ({...tags, ...autoTags}));
return {props: args.props, opts: args.opts};
}
return undefined;
Expand Down
2 changes: 1 addition & 1 deletion nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
},
"dependencies": {
"@pulumi/aws": "^4.0.0 || ^5.0.0 || ^6.0.0",
"@pulumi/pulumi": "^3.0.0"
"@pulumi/pulumi": "^3.118.0"
}
}
16 changes: 8 additions & 8 deletions python/pulumi_aws_tags/autotag.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@


def register_auto_tags(auto_tags):
"""Register a global auto-tagging stack transformation.
"""Register a global auto-tagging stack transform.
The transformation merges a set of given tags with whatever was also
explicitly added to the resource definition.
The transform merges a set of given tags with whatever was also explicitly
added to the resource definition.
"""
pulumi.runtime.register_stack_transformation(
pulumi.runtime.register_resource_transform(
lambda args: _auto_tag(args, auto_tags)
)

Expand All @@ -22,9 +22,9 @@ def _auto_tag(args, auto_tags):
if is_taggable(args.type_):
if args.type_ in _UNSUPPORTED_RESOURCE_TYPES:
pulumi.log.warn(
"resource does not support auto-tagging",
resource=args.resource,
f"resource of type {args.type_} does not support auto-tagging"
)
return
args.props["tags"] = {**(args.props["tags"] or {}), **auto_tags}
return pulumi.ResourceTransformationResult(args.props, args.opts)
tags = pulumi.Output.from_input(args.props.get("tags") or {})
args.props["tags"] = tags.apply(lambda tags: {**tags, **auto_tags})
return pulumi.ResourceTransformResult(args.props, args.opts)
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ classifiers = [
]
urls = { Homepage = "https://github.com/tlinhart/pulumi-aws-tags" }
requires-python = ">=3.8"
dependencies = ["pulumi>=3.0.0,<4.0.0", "pulumi_aws>=4.0.0,<7.0.0"]
dependencies = ["pulumi>=3.118.0,<4.0.0", "pulumi_aws>=4.0.0,<7.0.0"]

[build-system]
requires = ["setuptools"]
Expand Down

0 comments on commit 769f4a0

Please sign in to comment.