Noob here. Some silly questions about terraform

Hello guys,

Started learning about TF last week.

I want to know what makes TF special when it comes to creating and destroying infra fast.

Like my manager gave an example that if we’re hosting something on AWS, the meter starts and whether we use the server or not, we get billed.

So why not just terminate the instance and restart it when we need it.

Where does TF come into picture and save the day and our money?

Sorry if its a silly que.

Thanks

Hi @KMAN,

Terraform does not directly address the use-case you shared here, of automatically starting and stopping EC2 instances. However, you could potentially use Terraform as a part of a solution to meet that requirement.

In a purely manual mode of working, you could write a Terraform configuration to describe the EC2 instance and any other related infrastructure and then use terraform apply when you need it and then terraform destroy later when you no longer need it. Because you described the configuration of the infrastructure as code, you can recreate equivalent infrastructure with a single command.

Some teams use an approach like what I described above but use some other automation solution to run those steps automatically at particular times of day, for example so that the infrastructure is available during your company’s normal business hours but not available outside of those hours. Setting that up will require some other software outside of Terraform’s scope, but it only needs to be something that is capable of running commands in a particular system context (such as a Docker container image, or similar) on a predefined schedule.

In the AWS domain I’ve heard of folks doing this with AWS Lambda functions configured to run on a schedule, presumably with the appropriate terraform executable included in the function’s source code package so that the lambda function can execute it. However, I don’t have any direct experience with that and so I can’t show a full example.

1 Like