Getting Started — DigitalOcean
Everything you need before using any module from terraform-do-modules: installation, API token setup, provider config, remote state, and the variable conventions shared by every module.
Prerequisites
| Tool | Minimum version | Install |
|---|---|---|
| Terraform | 1.6.0+ | developer.hashicorp.com/terraform/install |
| DigitalOcean provider | 2.0+ | declared in required_providers |
doctl (optional) | any recent | github.com/digitalocean/doctl |
Authentication
Create a Personal Access Token
- Log in to cloud.digitalocean.com
- Go to API → Tokens → Generate New Token
- Give it a name and enable Write scope
Export the token as an environment variable — never hard-code it in .tf files:
export TF_VAR_do_token="dop_v1_xxxxxxxxxxxxxxxxxxxx"
Provider configuration
# versions.tf
terraform {
required_version = ">= 1.6.0"
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = ">= 2.0"
}
}
}
variable "do_token" {
type = string
sensitive = true
}
provider "digitalocean" {
token = var.do_token
}
Remote state on Spaces
DigitalOcean Spaces is S3-compatible, so Terraform's s3 backend works with a small configuration adjustment.
1. Create a Spaces bucket and access key
Create a bucket in the DigitalOcean control panel (Spaces → Create Space), then generate a Spaces access key under API → Spaces Keys → Generate New Key.
2. Export the Spaces credentials
export AWS_ACCESS_KEY_ID="<spaces-access-key>"
export AWS_SECRET_ACCESS_KEY="<spaces-secret-key>"
3. Add the backend block
terraform {
backend "s3" {
endpoint = "https://blr1.digitaloceanspaces.com" # your Spaces region endpoint
bucket = "my-tfstate"
key = "prod/terraform.tfstate"
region = "us-east-1" # required placeholder, ignored by Spaces
skip_credentials_validation = true
skip_metadata_api_check = true
skip_region_validation = true
force_path_style = true
}
}
Workflow
# Download providers and initialise the backend
terraform init
# Preview what will change
terraform plan
# Apply changes
terraform apply
# Tear down (use with care in production)
terraform destroy
Common variables
Every module in terraform-do-modules shares these standard variables:
| Variable | Type | Default | Description |
|---|---|---|---|
name | string | "" | Short resource name, e.g. app, cluster |
environment | string | "" | Environment label — prod, dev, staging |
region | string | "blr1" | DigitalOcean region slug |
enabled | bool | true | Set to false to skip resource creation |
label_order | list | ["name","environment"] | Controls label order in resource names |
managedby | string | "terraform-do-modules" | Tag identifying the managing team |
Available region slugs
| Slug | Location |
|---|---|
nyc3 | New York 3 |
sfo3 | San Francisco 3 |
ams3 | Amsterdam 3 |
sgp1 | Singapore 1 |
blr1 | Bangalore 1 |
lon1 | London 1 |
fra1 | Frankfurt 1 |
tor1 | Toronto 1 |
Pinning module versions
Always pin modules to a release tag in production:
source = "git::https://github.com/terraform-do-modules/terraform-digitalocean-kubernetes.git?ref=v1.0.0"
Next steps
- DigitalOcean Recipes → — end-to-end examples combining multiple modules
- DigitalOcean Module Reference → — full list of available modules