I’m using Terraform to manage my DigitalOcean infrastructure and want to automate the creation of snapshots for my Droplets.
Ideally, I’d like to schedule snapshots on a regular basis as part of my Terraform configuration so I don’t have to remember to take backups manually.
I already have the automated backups enabled, but I just want to be sure that I have a snapshot before applying some configuration changes to be safe.
Is there a way to do this directly in Terraform with DigitalOcean, or would I need additional tooling?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hey there! 👋
Currently, DigitalOcean’s Terraform provider doesn’t natively support scheduling Droplet snapshots directly, but you can still set up snapshots using a few creative steps in combination with other tools!
Here are a few ways you can automate Droplet snapshots with Terraform:
While Terraform doesn’t schedule snapshots, you can create snapshots manually before applying any major configuration changes by using
do_droplet_snapshot
:Here’s an example of how you could add this to your configuration:
You’d trigger this manually by running
terraform apply
right before making any critical changes.If you’re looking for more automation, you can create a shell script to trigger snapshots via the DigitalOcean API. Here’s a quick example of a cURL command for creating a snapshot:
You can run this script periodically using a cron job. Just replace
DROPLET_ID
with your droplet’s ID and set it up in your server’s cron scheduler.DigitalOcean also offers SnapShooter integration for scheduled snapshots. SnapShooter automates backups and snapshots, and it’s a good choice if you want full automation without extra scripts or manual commands. Plus, SnapShooter keeps backups separate from Droplet automated backups for extra safety.
On the Terraform side again, since snapshots are best used before applying changes, run
terraform plan
to preview any adjustments. This way, you can be sure everything looks good and has a fresh snapshot in case of any rollback.Hope this helps!
- Bobby