1. Answers
  2. Using delete_before_replace and ignore_changes in Pulumi

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

  1. Import Pulumi and AWS SDK: We start by importing the necessary modules from Pulumi and AWS SDK.
  2. Define S3 Bucket: We define an AWS S3 bucket with specific properties such as acl and tags.
  3. Options:
    • deleteBeforeReplace: Set to true to ensure the bucket is deleted before being replaced.
    • ignoreChanges: Specifies that changes to the tags property should be ignored.
  4. 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 up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up