The instance resource
The instance resource. Terraform: Manage instances and snapshots as code with the KiviDB Terraform provider.
A KiviDB Cloud database.
resource "kividb_instance" "cache" {
name = "orders-cache"
tier = "essentials"
cloud = "aws"
region = "us-east-1"
data_size_gb = 8
}
Required
| Attribute | Notes |
|---|---|
tier | essentials, pro or scale |
cloud | aws, azure or gcp (Google Cloud; provider 0.2.4 or later). Forces replacement. |
region | e.g. us-east-1, swedencentral. Forces replacement. |
data_size_gb | Logical data size. Resized in place. |
Optional
| Attribute | Default | Notes |
|---|---|---|
name | generated | Hostname-safe, unique across KiviDB. Renamed in place. |
throughput_mode | standard | standard or high. Changed in place. |
replica_count | 0 | 0 at creation for a single node; scaling afterwards accepts 1–3. |
kividb_version | current | Engine version, e.g. 1.1.0. Rolling restart. |
lua_enabled | false | Lua scripting. Rolling restart. |
tls_enabled | false | Serve TLS alongside plaintext. Rolling restart. |
aof_enabled | true | Append-only persistence. Forces replacement. |
tls_only | false | Refuse plaintext. Forces replacement. |
wait_for_ready | true | Wait for provisioning before the apply completes. |
cloud_account_id | none | Run the database in your own connected cloud account (Bring your own cloud); provider 0.3.0 or later. Changing it to another account forces replacement; from 0.5.0, leaving it out keeps the database where it is, and a database created from a snapshot takes the snapshot's account. |
restore_from_snapshot_id | none | Create the database from a disk snapshot; provider 0.5.0 or later. See From a snapshot. |
restore_from_kdb_snapshot_id | none | Create the database from a KDB snapshot; provider 0.5.0 or later. See From a snapshot. |
Read-only
| Attribute | Notes |
|---|---|
id | The database's id. Use this to import. |
status | Lifecycle status. |
endpoint | Connection endpoint. |
public_endpoint | Public endpoint, when one is exposed. |
org_id | Owning organization. |
private_endpoint | In your own cloud account only: the name that resolves to the primary's private address. |
private_readonly_endpoint | In your own cloud account only (Pro): the read-only name for the replicas. |
private_replica_endpoints | In your own cloud account only (Pro): one name per replica. Empty otherwise. |
cloud_account_name | The connected account's name, or empty in KiviDB's cloud. Provider 0.5.0 or later. |
Tiers and sizes
Essentials is a single node. Pro is replicated: a writer and one to three read replicas, with automatic failover.
Pro has a minimum dataset size, and it differs by cloud:
| Cloud | Pro minimum |
|---|---|
| AWS | 4 GB |
| Azure | 8 GB |
| Google Cloud | 8 GB |
That is hardware, not pricing. AWS's smallest Pro-capable machine has 1 vCPU and 4 GiB; Azure has no 1-vCPU sustained-performance VM, and Google Cloud's custom machine types start at two vCPUs, so the smallest honest Pro instance on either is an 8 GB-shaped machine whatever it is called. Asking for a smaller Pro database is refused with both numbers and the cloud named:
Error: Could not change the tier
Pro on aws starts at 4 GB and this instance is 2 GB. Resize it to at least
4 GB first, then upgrade.
Resize first, then upgrade — or do both in one apply and let the provider sequence them.
Upgrading to Pro
Set tier = "pro" and give it a replica_count:
resource "kividb_instance" "primary" {
name = "orders-primary"
tier = "pro"
cloud = "aws"
region = "us-east-1"
data_size_gb = 8
replica_count = 2
}
Upgrading is in place and the data is kept. A snapshot is taken before the machine is resized, so there is a restore point if anything goes wrong.
Pro is the only tier an existing database can be upgraded to. Moving in the
other direction, or to scale, is refused with an explanation rather than
attempted.
Replicas
replica_count scales between 1 and 3 on a Pro database. Going back to 0
is refused:
Error: Replicas cannot be scaled to zero
KiviDB scales replicas between 1 and 3. Removing replication entirely changes
the shape of the database rather than its size, so it is not an in-place
operation. Create a new database without replicas and migrate, or keep at
least one replica.
That is a real constraint, not a missing feature: a replicated database and a single-node one are laid out differently, and the endpoint your clients use for reads exists only on the replicated one.
TLS
tls_enabled adds the TLS port alongside the plain one, applied by a rolling
restart across every node. On a Pro database that means the writer and every
replica — the read endpoint gets its certificate at the same time as the writer,
not eventually.
tls_only withdraws the plaintext port. It forces replacement, because it
changes how the database is laid out rather than what it serves. If you want
TLS-only, set it at creation.
Certificates are renewed automatically within 30 days of expiry, across every node. There is nothing to configure and nothing in this resource for it.
Changing several things at once
This works, and it is worth understanding what it costs:
resource "kividb_instance" "cache" {
# ...
data_size_gb = 16 # was 8
replica_count = 2 # was 1
tls_enabled = true # was false
}
Most of these operations refuse a database that is still busy with the previous
one, so the provider performs them in order and waits between them. The apply
takes roughly as long as the operations do, added together. Terraform will print
Still modifying… throughout; that is the wait, not a hang.
If something fails partway, the error says which operation failed, and state records what the database actually is — not what was planned — so the next plan shows the remaining difference and tries again.
In your own cloud account
Connect the account in the console first (Settings → Cloud accounts), then look it up by name and place the database in it:
data "kividb_cloud_account" "prod" {
name = "Production AWS"
}
resource "kividb_instance" "orders" {
name = "orders"
cloud = "aws"
region = "us-east-1" # one of the account's regions
tier = "pro"
data_size_gb = 8
replica_count = 1
cloud_account_id = data.kividb_cloud_account.prod.id
}
output "orders_private_endpoint" {
value = kividb_instance.orders.private_endpoint
}
For a connected Google Cloud project, set cloud = "gcp" and one of the
project's regions; for a connected Azure subscription, cloud = "azure" and
one of its regions. The account must be Verified and the region one it
covers. A database in
your account cannot use private connectivity (it is already in your network)
or the free tier. kividb_cloud_accounts lists every connected account. See
Bring your own cloud.
From a snapshot
Provider 0.5.0 or later can create a database from a disk snapshot or a KDB
snapshot. A snapshot restores only where it was taken: the same cloud, region
and account. Leave cloud_account_id out and the database goes into the
snapshot's account:
resource "kividb_instance" "orders_restored" {
name = "orders-restored"
cloud = "aws"
region = "us-east-1" # the snapshot's region
tier = "essentials"
data_size_gb = 4
restore_from_kdb_snapshot_id = "6e439d6d-e42d-4f5c-b91c-be29e02d9387"
}
terraform plan checks the snapshot: a different cloud, region or account is
an error at plan time, naming the value to set. Pointing at a different
snapshot later replaces the database; removing the attribute changes nothing.
Set one of restore_from_snapshot_id or restore_from_kdb_snapshot_id, not
both.
Importing
$ terraform import kividb_instance.cache 790df3ae-c064-45f5-b924-9ed89471fd72
The id is in the console URL, or from list_databases if you use an assistant.
An imported database plans clean immediately, provided your configuration
matches what is actually there.
Deleting
terraform destroy deletes the database and its data. The call returns as soon
as the deletion is accepted — teardown continues in the background — so a
configuration that destroys and immediately recreates under the same name can
race its own teardown. If you are cycling a database, give the new one a
different name or wait for the old one to disappear from list_databases.
When something is accepted but does not happen
An update waits for the change itself, not just for the status to settle. If the work behind a change fails, you get this rather than a false success:
Error: The change was accepted but the database did not settle
the change was accepted but never took effect: data_size_gb is still 1, not
2. The database is healthy and reports status "running", so the work behind
the change did not reach it
State is written from what was read, so the next plan still shows the difference and will try again.