Skip to content

Resource option: transforms ​

The transforms resource option provides a list of transforms to apply to a resource and all its children. Use this option to override or modify the inputs to the child resources of a component resource. One example is to use the option to add other resource options (such as ignoreChanges or protect). Another example is to modify an input property (such as adding to tags or changing a property that is not directly configurable).

Each transform is a callback that the Pulumi engine invokes. It receives the resource type, name, input properties, and resource options. The callback returns a new set of resource input properties and resource options that will be used to construct the resource instead of the original values.

VPC example ​

This example looks for all VPC and Subnet resources in a component's child hierarchy and adds an option to ignore any changes to their tags property (for example, because you manage all VPC and Subnet tags outside of Pulumi):

typescript
const vpc = new MyVpcComponent("vpc", {}, {
    transforms: [args => {
        if (args.type === "aws:ec2/vpc:Vpc" || args.type === "aws:ec2/subnet:Subnet") {
            return {
                props: args.props,
                opts: pulumi.mergeOptions(args.opts, { ignoreChanges: ["tags"] })
            }
        }
        return undefined;
    }],
});

Stack transforms ​

To apply a transform in bulk to many or all resources in a stack, use a stack transform. A stack transform applies to all future resources constructed in the stack.

typescript
pulumi.runtime.registerResourceTransform(args => {
    if (args.type === "aws:ec2/vpc:Vpc" || args.type === "aws:ec2/subnet:Subnet") {
        return {
            props: args.props,
            opts: pulumi.mergeOptions(args.opts, { ignoreChanges: ["tags"] })
        }
    }
    return undefined;
});

Transforms vs. transformations ​

Transforms are a replacement for transformations. Transformations will be deprecated in the future in favor of transforms.

Transforms offer support for the following capabilities that are not supported by Transformations:

  • Support for transforming child resources of packaged components, such as components in awsx and eks.

  • Support for async transform functions. In Node.js and Python, transform functions can optionally be async and return a Promise/Awaitable so you can use await for async calls in the transform. In .NET, transform functions take a CancellationToken as an argument and return a Task so you can use await for async calls in the transform. In Go, transform functions take a context.Context as an argument, allowing access to the async context for tracing/logging/cancellation.

While the Transforms APIs are similar to Transformations, there are some differences in both API signatures and runtime behavior. These are discussed in detail in Migrating from Transformations to Transforms.

Transforms for packaged component resources ​

Note that a transform will be called twice for packaged component resources (such as those in awsx and eks). The transform will be called before the component resource is constructed, providing an opportunity to modify inputs and resource options before being passed to the provider that implements the component, and then again when the component resource is actually created in the provider, providing an opportunity to modify any resource options that were configured inside the implementation of the component.

Content from the official Pulumi documentation (github.com/pulumi/docs).