New to Terraform. Experimented a lot past days. Still trying to get my head around some of the behaviour.
I created an AWS instance with a webserver in it then I wanted to update it by adding some tags and keypair. I noticed Terraform is destroying the instance and recreating it.
I can imagine a situation where I have some servers in production running some webapp and I want to rename it. Then essentially it would destroy and recreate my server. which means I will loose my project data in "/var/www/html" While I understand it's the way Terraform works, I fail to see the use here.
what is the solution here other than taking backup of project folder before updating the terraform module ?
The solution is that you design your application and instance to be stateless. This means that no state information (e.g. user data, sessions, databases) is stored on the instance. Consequently, you can terminate your instance at any time (AWS can also do it sometimes), and re-recreate it without affecting your data and the application.
The statelessness is the primary way for developing fault-tolerant, highly available and scalable applications on AWS.
So if your application is developed in such a way that its "project data" depends on the lifetime of an instance, then you may re-consider the design and approach of deploying applications in the cloud environment. Specifically, for storing your data, usually you would store it outside of the instance, with common choices being S3 and EFS. Any database, would also be external.
I would recommend to have a look at AWS Well-Architected and the Five Pillars of development at AWS, which covers these and many other topics which are helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With