Storage examples
A storage disk is a block disk that is separate from the root disk of an Instance. Keeping application data on its own disk lets you increase its size, back it up or move the data to another Instance without affecting the operating system. For detailed concepts, see Storage Disks overview.
Prerequisites
- ✅ You have completed Set up and configure.
- ✅ You have an Instance to attach the disk to. The examples below read two existing Instances named
app-server-01andapp-server-02, for example created as in Instance examples.
Shared configuration
# shared.tf
data "fptcloud_vpc" "example" {
name = "example-vpc"
}
data "fptcloud_storage_policy" "ssd" {
vpc_id = data.fptcloud_vpc.example.id
filter {
key = "name"
values = ["Premium-SSD"]
}
}
# shared.tf
data "fptcloud_instance" "app" {
vpc_id = data.fptcloud_vpc.example.id
name = "app-server-01"
}
data "fptcloud_instance" "standby" {
vpc_id = data.fptcloud_vpc.example.id
name = "app-server-02"
}
In a real configuration, you can use fptcloud_instance.app.id directly if the Instance is created in the same Terraform folder.
Data disk attached to an Instance
This is the most common case: a separate disk for application data. Terraform creates the disk and waits until the disk is attached to the Instance:
# disk.tf
resource "fptcloud_storage" "app_data" {
vpc_id = data.fptcloud_vpc.example.id
name = "app-data-disk"
type = "EXTERNAL"
size_gb = 200
storage_policy_id = data.fptcloud_storage_policy.ssd.storage_policies[0].id
instance_id = data.fptcloud_instance.app.id
}
A newly attached disk is empty. Before you use it, format the disk in the operating system of the Instance as described in the section Newly Attached Disk Does Not Appear Inside the Instance of Storage Disks troubleshooting.
Disk not attached to an Instance
Leave out the instance_id argument to create a standalone disk, for example to prepare a disk in advance for an Instance that you will create later:
# disk.tf
resource "fptcloud_storage" "spare" {
vpc_id = data.fptcloud_vpc.example.id
name = "spare-disk"
type = "EXTERNAL"
size_gb = 100
storage_policy_id = data.fptcloud_storage_policy.ssd.storage_policies[0].id
}
When you need to attach it, add instance_id and run terraform apply.
Several disks for one Instance
Put data and logs on two separate disks so that each disk has a suitable size and storage policy:
# disks.tf
locals {
app_disks = {
data = 200
logs = 50
}
}
resource "fptcloud_storage" "app" {
for_each = local.app_disks
vpc_id = data.fptcloud_vpc.example.id
name = "app-${each.key}-disk"
type = "EXTERNAL"
size_gb = each.value
storage_policy_id = data.fptcloud_storage_policy.ssd.storage_policies[0].id
instance_id = data.fptcloud_instance.app.id
}
Move a disk to another Instance
An EXTERNAL disk can move between Instances while its data stays intact. Change instance_id to the new Instance, then run terraform apply:
# disk.tf
resource "fptcloud_storage" "shared_data" {
vpc_id = data.fptcloud_vpc.example.id
name = "shared-data-disk"
type = "EXTERNAL"
size_gb = 100
storage_policy_id = data.fptcloud_storage_policy.ssd.storage_policies[0].id
instance_id = data.fptcloud_instance.standby.id # previously the app Instance
}
To detach the disk from the Instance without attaching it to another Instance, delete the instance_id line, then run terraform apply.
Unmount the disk in the operating system before you move or detach the disk, as recommended in Storage Disks troubleshooting.
Increase the size and change the storage policy
Increase size_gb to expand the disk, or change storage_policy_id to move the disk to another performance level. Both changes are applied in place, and the data is kept:
# disk.tf
data "fptcloud_storage_policy" "fast" {
vpc_id = data.fptcloud_vpc.example.id
filter {
key = "name"
values = ["Premium-SSD-6000"] # Replace with a storage policy available in your VPC
}
}
# disk.tf
resource "fptcloud_storage" "reports" {
vpc_id = data.fptcloud_vpc.example.id
name = "reports-disk"
type = "EXTERNAL"
size_gb = 300 # previously 200
storage_policy_id = data.fptcloud_storage_policy.fast.storage_policies[0].id
instance_id = data.fptcloud_instance.app.id
}
After you increase the size, go into the operating system of the Instance and expand the matching partition, as described in Manage the Storage Disks of an Instance.
The disk size can only be increased, not decreased. The provider does not block a smaller value at the terraform plan step, so check carefully before you apply.
Instance Snapshot
Take a Snapshot before a major change, for example an operating system upgrade, so that you can return to the previous state. Each fptcloud_snapshot is one Snapshot, which is created when you apply and deleted when you destroy:
# snapshot.tf
resource "fptcloud_snapshot" "before_upgrade" {
vpc_id = data.fptcloud_vpc.example.id
instance_id = data.fptcloud_instance.app.id
name = "app-before-upgrade"
}
A Snapshot name is 1 to 30 characters long and contains letters, digits, underscores, hyphens, periods and spaces. For more information, see Snapshots overview.
Common storage disk arguments
| Argument | Required | When changed |
|---|---|---|
vpc_id | Yes | Cannot be changed after creation. |
name | Yes | Renames in place. For an EXTERNAL disk, the name must not match another disk in the VPC. |
type | Yes | Cannot be changed: apply returns an error. Values: EXTERNAL, LOCAL. |
size_gb | Yes | Increases the size in place. |
storage_policy_id | Yes | Changes the storage policy in place. |
instance_id | No | For EXTERNAL: moves or detaches the disk in place. For LOCAL: required at creation and cannot be changed. |
tag_ids | No | Updates tags in place. |
Use EXTERNAL for data disks. A LOCAL disk is permanently attached to one Instance and cannot be moved or detached.
Do not use fptcloud_storage for the root disk of an Instance. The root disk is managed with the storage_size_gb and storage_policy_id arguments of fptcloud_instance.
Delete a disk
When you remove a disk from the configuration or run terraform destroy, Terraform detaches the disk from the Instance, deletes the disk and waits until the deletion is complete.
Deleting a disk permanently deletes all data on the disk. This action cannot be undone.