Open MaximF opened 5 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.
Hello All, Please confirm the solution on how to do it in Terraform end, rather than the manual way on AWS.
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.
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.
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 addcreate_before_stop
step there. It could follow the steps that were described in "Attempted Solutions" section and allow doing seamless instance_type migrations.References: