Snapshots
A point-in-time copy of a database's data volume, managed as configuration.
A point-in-time copy of a database's data volume, managed as configuration.
resource "kividb_disk_snapshot" "before_migration" {
instance_id = kividb_instance.cache.id
label = "before-migration"
}
Attributes
| Attribute | Notes |
|---|---|
instance_id | The database to snapshot. Forces replacement. |
label | A name you choose. The only thing you can change afterwards. |
wait_for_ready | Wait for the copy to finish. Default true. |
id, status, size_gb, cloud, region, instance_name, created_at | Read-only. |
What it is for
A snapshot in configuration is a snapshot you can point at. The useful pattern is taking one immediately before something irreversible, and having Terraform enforce the ordering for you:
resource "kividb_disk_snapshot" "pre_resize" {
instance_id = kividb_instance.cache.id
label = "pre-resize-${formatdate("YYYYMMDD", timestamp())}"
}
resource "kividb_instance" "cache" {
# ...
depends_on = [kividb_disk_snapshot.pre_resize]
}
This is not a backup schedule. For routine, recurring copies use scheduled snapshots in the console or through an assistant — they run without a Terraform apply and are retained by policy. Use this resource for the deliberate, named copy you take before doing something you might want to undo.
Pointing it somewhere else replaces it
instance_id forces replacement, because nothing re-points a copy that has
already been taken. Changing it plans a new snapshot of the new database and
destroys the old one — which deletes a restore point. Read that plan.
label is the exception: it changes in place, so renaming a snapshot is free.
Waiting
By default the apply waits for the copy to finish, because a snapshot that is
still being written cannot be restored from and a resource that reports ready
when it is not is worse than a slow apply. Set wait_for_ready = false to
return as soon as the server accepts it.
Restoring
Restoring is not a Terraform operation. A restore replaces the contents of a running database, which is a thing you do deliberately and watch, not something a plan should perform because a file changed. Restore from the console, or through an assistant.
Retention
Deleting this resource deletes the snapshot. Snapshots also expire under the retention policy set on the database, so a snapshot Terraform believes it owns can be removed underneath it. The next plan notices, drops it from state and offers to take a fresh one — which is usually what you want, but it does mean a long-lived snapshot resource should have a retention policy that agrees with it.