# Controlling order of resource/module replacement

**URL:** <https://discuss.hashicorp.com/t/controlling-order-of-resource-module-replacement/44604>\
**Category:** Terraform\
**Created:** [September 21, 2022, 6:01pm UTC](https://discuss.hashicorp.com/t/controlling-order-of-resource-module-replacement/44604 "2022-09-21T18:01:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sven](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/sven/32/16852_2.png) [@sven](https://discuss.hashicorp.com/u/sven)\
**Post date:** [September 21, 2022, 6:01pm UTC](https://discuss.hashicorp.com/t/controlling-order-of-resource-module-replacement/44604/1 "2022-09-21T18:01:05Z")

</div>

Hello,

I’m struggling with trying to control the replacement order/cadence for my project:

I have two EC2 instances that I need to be replaced on change (such as AMI change, etc) **one at a time** in order to avoid downtime. From my understanding and observation, Terraform will only destroy _everything_ first before it creates anything.

I’d like to destroy + create Instance1 before destroying + creating Instance2. I have tried using `depends_on` but this will only implement the order of the destruction or creation but both instances will still be destroyed before they are then both created in whichever order.

Options I am aware of but are not currently viable:

- For my project, I am unable to utilize `terraform apply -replace` to target a resource or any other customization of `terraform apply`
- changing to using AutoScalingGroups
- `create_before_destroy` (instances have network interfaces so this isn’t very feasible)

Any tips or help would be greatly appreciated! Thanks very much in advance for your time and consideration.

---

<div class="post-metadata">

**Author:** ![stuart-c](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/stuart-c/32/10789_2.png) [@stuart-c](https://discuss.hashicorp.com/u/stuart-c)\
**Post date:** [September 23, 2022, 2:56pm UTC](https://discuss.hashicorp.com/t/controlling-order-of-resource-module-replacement/44604/2 "2022-09-23T14:56:38Z")

</div>

Terraform isn’t an orchestration tool.

To do orchestration involving Terraform you either need to be creating resources which do it (e.g. creating ASGs instead of EC2 directly) or having a tool that calls Terraform in different ways (e.g. passing in different variable values across multiple applies).

As you seem to have discounted both options I don’t believe there is anything else to suggest.
