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.12k stars 9.47k forks source link

Extend EC2 instance type change processing #18855

Open MaximF opened 5 years ago

MaximF commented 5 years ago

Use-cases

We migrated EC2 cluster to the newer instance type and that caused Terraform to stop the whole cluster, update the instance type and relaunch it again. That means a downtime for that particular cluster.

terraform plan showed the changes in yellow "update" color, which didn't bring an alert to us.

Attempted Solutions

Current solution looks like this:

Proposal

We could extend a functionality of lifecycle configuration block and add create_before_stop step there. It could follow the steps that were described in "Attempted Solutions" section and allow doing seamless instance_type migrations.

References:

AjayNaiduJami commented 4 years ago

In my case, if I want to change the existing infra (Instance type from t2.micro -> t2.large) which was created by terraform, I have found a workaround.

I would be changing the Infra (Instance type, eg. t2.micro -> t2.large) manually via AWS console, I would be changing the code of terraform from t2.micro -> t2.large which I used to up that infra, I would be changing the desired value in the tfstate file (t2.micro -> t2.large), Finally, I would check the infra differences using terraform plan to confirm.

Please note that the instance state must be similar. If the infra firstly raised state is running, make sure that after changes the infra state must be running too. If not terraform may propose a change in infra.

anu4love commented 4 years ago

Hello All, Please confirm the solution on how to do it in Terraform end, rather than the manual way on AWS.

jimsmith commented 2 years ago

In my case, if I want to change the existing infra (Instance type from t2.micro -> t2.large) which was created by terraform, I have found a workaround.

I would be changing the Infra (Instance type, eg. t2.micro -> t2.large) manually via AWS console, I would be changing the code of terraform from t2.micro -> t2.large which I used to up that infra, I would be changing the desired value in the tfstate file (t2.micro -> t2.large), Finally, I would check the infra differences using terraform plan to confirm.

Please note that the instance state must be similar. If the infra firstly raised state is running, make sure that after changes the infra state must be running too. If not terraform may propose a change in infra.

An anti pattern for sure, purpose of Terraform is not to do manual operations then manual manipulation of terraform's tfstate file.

rootalam commented 5 months ago

If you just update the instance_type field and run a plan you should see Terraform showing an in place modification (should be in yellow with a ~ and saying it wants to change something rather than destroy and create.

Note that it will stop the instance, change the instance type and then start it so this will cause some downtime if you are relying on the instance being up all the time.