Create and Delete Resource on a Schedule

Is there a way to create a resource and destroy it after some time through a cron scheduler ?

External to terraform sure, we do this all the time. Terraform itself doesn’t have timers, it’s matching state as you run it. What we use it for is resetting the object back to base-line – we delete the state of the object and re-run plan, which detects any changes and deletes and re-creates the object.

Thank you @aram for your response. Do you have any references where I can look into to do this. Currently we have AWS Transfer family service running 24*7. I am looking to create a AWS Transfer family SFTP server and delete it after few hours daily through Terraform. This process should repeats every week days i.e create a new server in the morning and destroy after few hours

I would caution you against this but if you do want to do it I would suggest building a plan with “JUST” the SFTP server … use terraform destroy – aka terraform apply -destroy to delete everything in the plan – using cron or atq.