-
Notifications
You must be signed in to change notification settings - Fork 258
replaceWith Resource Option #16594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
replaceWith Resource Option #16594
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b5ad553
Make it so
i-am-tom d54c492
Front matter
i-am-tom b790b78
edits, meta image, date, social copy
meagancojocar a133330
Update content/blog/dependent-resource-replacements/index.md
SaraDPH c3448b4
Full switcher
i-am-tom 80c8b9b
Mention the other SDKs
i-am-tom 9394488
Change the publish date
i-am-tom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| --- | ||
| title: "New in Pulumi IaC: `replaceWith` Resource Option" | ||
| date: 2025-11-21 | ||
| meta_desc: "You can now use the `replaceWith` resource option to inform Pulumi of extra dependencies" | ||
| meta_image: meta.png | ||
| authors: | ||
| - tom-harding | ||
| tags: | ||
| - features | ||
| - iac | ||
| - releases | ||
|
|
||
| social: | ||
| twitter: "New in Pulumi IaC: Use the `replaceWith` resource option to declare custom resource dependencies and ensure coordinated replacements across your infrastructure." | ||
| linkedin: "Pulumi introduces a powerful new feature for fine-grained infrastructure control: the `replaceWith` resource option. Now you can explicitly define dependencies between resources to ensure coordinated replacements—perfect for scenarios like restarting services when databases are updated or managing complex multi-resource dependencies." | ||
| --- | ||
|
|
||
| The magic of Pulumi is that we rarely have to worry about the fine details of *how* our deployment and infrastructure management works, allowing us to focus instead on *what* we want. If our program declares an S3 bucket, Pulumi handles creation, updates, and deletion automatically. | ||
|
|
||
| Most of the time, this is exactly what we want. However, some use cases require finer-grained control over resource dependencies. Today, we're introducing the `replaceWith` resource option, a new feature that gives you explicit control over replacement dependencies between resources. | ||
|
|
||
| <!--more--> | ||
|
|
||
| ## Custom resource dependencies | ||
|
|
||
| When replacing a resource, the Pulumi engine walks the dependency graph to determine what else needs replacement. However, the answer isn't always obvious: | ||
|
|
||
| * Some dependencies aren't obvious at the infrastructure level. For example, restarting a database server may require restarting its consumers to reconnect. | ||
|
|
||
| * Provider-specific challenges exist. You might not be able to update a subnet's properties while resources are using it, even without an observable dependency. Any subnet change must be accompanied by changes to all its consumers to avoid errors. | ||
|
|
||
| * Application-level dependencies may exist beyond infrastructure. If two services maintain open connections in the application layer, replacing one should trigger replacement of the other. | ||
|
|
||
| ## Declaring our own dependencies | ||
|
|
||
| The `replaceWith` resource option makes these dependencies explicit in your code. Similar to `deletedWith`, passing references to other resources via `replaceWith` defines a relationship: when any target resource is replaced, the source is also replaced. This has some interesting implications: | ||
|
|
||
| * We can define a number of resources that all `replaceWith` each other, and so any change to any member of the group will trigger an update to all the others. | ||
|
|
||
| * Relationships are transitive: organizing resources hierarchically where children `replaceWith` their parents means any ancestor change triggers replacement of all descendants. | ||
|
|
||
| ## In code | ||
|
|
||
| Here's how this works in practice using the TypeScript SDK: | ||
i-am-tom marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```ts | ||
| import * as pulumi from "@pulumi/pulumi"; | ||
| import * as aws from "@pulumi/aws"; | ||
|
|
||
| const database = new aws.rds.Instance("app-db", { /* ... */ }); | ||
|
|
||
| // The database location is provided to this instance | ||
| // by other means, so there is not an explicit dependency | ||
| // linking the two. | ||
| const app = new aws.ec2.Instance("app-service", { /* ... */ }, { | ||
| // Here, we explicitly tie the two together: if the | ||
| // database is upgraded, for example, we will need to | ||
| // restart the application instance to ensure that | ||
| // a connection is re-established. | ||
| replaceWith: [database], | ||
| }); | ||
| ``` | ||
|
|
||
| Of course, this is a simple example, but hopefully it illustrates the point: we now have a way to make implicit dependencies between resources more explicit within our programs, and provide hints to Pulumi as to which services depend on others. | ||
|
|
||
| ## Next steps | ||
|
|
||
| This feature is supported as of [Pulumi `v3.207.0`](https://github.com/pulumi/pulumi/releases/tag/v3.207.0), and is now available within the Go, Python, and NodeJS SDKs. Thanks for reading, and feel free to reach out with any questions via [GitHub](https://github.com/pulumi/pulumi), [X](https://x.com/pulumicorp), or our [Community Slack](https://slack.pulumi.com/). | ||
i-am-tom marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.