Resource option: deleteBeforeReplace
A resource may need to be replaced if an immutable property changes. In these cases, cloud providers do not support updating an existing resource so a new instance will be created and the old one deleted. By default, to minimize downtime, Pulumi creates new instances of resources before deleting old ones.
Setting the deleteBeforeReplace
option to true means that Pulumi will delete the existing resource before creating its replacement. This option may be necessary for resources that manage scarce resources or resources that cannot exist side-by-side. However, it’s important to note that it can cascade to dependent resources, potentially causing more replacements and downtime. Additionally, eventual consistency in cloud APIs (like AWS) may lead to corrupted dependent resources if deletion hasn’t fully propagated before creation begins.
This example deletes a database entirely before its replacement is created:
let db = new Database("db", {/*...*/},
{ deleteBeforeReplace: true});
let db = new Database("db", {/*...*/},
{ deleteBeforeReplace: true});
db = Database("db",
opts=ResourceOptions(delete_before_replace=True))
db, err := NewDatabase(ctx, "db", &DatabaseArgs{ /*...*/ },
pulumi.DeleteBeforeReplace(true))
// The resource will be deleted before it's replacement is created
var db = new Database("db", new DatabaseArgs(),
new CustomResourceOptions { DeleteBeforeReplace = true });
// The resource will be deleted before it's replacement is created
var db = new Database("db",
DatabaseArgs.Empty,
CustomResourceOptions.builder()
.deleteBeforeReplace(true)
.build());
# The resource will be deleted before it's replacement is created
resources:
db:
type: Database
options:
deleteBeforeReplace: true
Thank 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.