How do I use delete_before_replace and ignore_changes in Pulumi?
In this guide, we will learn how to use the deleteBeforeReplace
and ignoreChanges
options in Pulumi using an AWS S3 bucket as an example. The deleteBeforeReplace
option ensures that the resource is deleted before being replaced, and the ignoreChanges
option allows us to specify properties that Pulumi should ignore when checking for changes.
Key Points
- deleteBeforeReplace: Ensures the resource is deleted before being replaced.
- ignoreChanges: Specifies properties to ignore when Pulumi checks for changes.
Example
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// Define an S3 bucket
const bucket = new aws.s3.Bucket("my-bucket", {
acl: "private",
tags: {
Environment: "Dev",
Name: "MyBucket",
},
}, {
// Ensure the bucket is deleted before being replaced
deleteBeforeReplace: true,
// Ignore changes to the 'tags' property
ignoreChanges: ["tags"],
});
// Export the bucket name
export const bucketName = bucket.bucket;
Explanation
- Import Pulumi and AWS SDK: We start by importing the necessary modules from Pulumi and AWS SDK.
- Define S3 Bucket: We define an AWS S3 bucket with specific properties such as
acl
andtags
. - Options:
deleteBeforeReplace
: Set totrue
to ensure the bucket is deleted before being replaced.ignoreChanges
: Specifies that changes to thetags
property should be ignored.
- Export Bucket Name: Finally, we export the bucket name to make it accessible as a stack output.
Summary
In this example, we demonstrated how to use the deleteBeforeReplace
and ignoreChanges
options in Pulumi to manage an AWS S3 bucket. The deleteBeforeReplace
option ensures that the bucket is deleted before being replaced, and the ignoreChanges
option ignores changes to the tags
property, allowing for more flexible resource management.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.