hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.38k stars 9.49k forks source link

create_before_destroy checks #6058

Open jseaidou opened 8 years ago

jseaidou commented 8 years ago

Hey, we want to be able to when upgrading a instance or recycling with the create_before_destroy flag to make sure certain events passed (for example provisionner finished successfully etc .. ). We dont want upgrade and have our cluster taken down because of this. With that being said, is it possible to implement something similar to:

  1. bring up all instances
  2. if any of the instances are unsuccessful destroy all the new instances and the state hasn't changed
  3. if successfull delete all previous instances

This gives the benefit of also not crippling the cluster of VMs because we lost some of our machines and can't handle the load as efficiently.

mitchellh commented 7 years ago

This isn't currently possible but something like this is interesting for a lifecycle option.

apparentlymart commented 2 months ago

This is an old issue so I'm not sure what exactly was possible at the time, but in modern Terraform I would expect that a provisioner failure during the create leg of a "create before destroy" replace would:

  1. Mark the affected object as "tainted" in the state, so a future plan will know to destroy it.
  2. Halt and return the provisioning error before reaching the "destroy" leg, since the destroy would depend on the create.

This doesn't exactly match the request because the first apply won't immediately destroy the failed objects, but the next plan would propose to destroy them unless the operator manually removes the tainted status using the terraform untaint command.

Therefore I wonder if the current behavior is already close enough to consider this "done". 🤔