Terraform Provider Overview
The official DanubeData Terraform provider allows you to manage your cloud infrastructure using Infrastructure as Code (IaC). Deploy VPS instances, databases, caches, storage buckets, and more with version-controlled, reproducible configurations.
Why Use Terraform?
- Version Control: Track infrastructure changes in Git alongside your application code
- Reproducible Deployments: Deploy identical environments across dev, staging, and production
- Team Collaboration: Share configurations and collaborate with pull requests
- Drift Detection: Detect and fix configuration drift automatically
- Cost Visibility: Preview costs before deployment with
terraform plan
Quick Start
1. Install Terraform
Download and install Terraform from terraform.io:
# macOS with Homebrew
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
# Ubuntu/Debian
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform
# Verify installation
terraform version
2. Get Your API Token
- Log in to your DanubeData dashboard
- Navigate to Settings > API Tokens
- Click Create New Token
- Select the permissions you need (at minimum: read/write for resources you want to manage)
- Copy the token - it's shown only once!
3. Configure the Provider
Create a new directory for your Terraform configuration:
mkdir my-infrastructure
cd my-infrastructure
Create a main.tf file:
terraform {
required_providers {
danubedata = {
source = "AdrianSilaghi/danubedata"
version = "~> 0.1"
}
}
}
provider "danubedata" {
# API token is read from DANUBEDATA_API_TOKEN environment variable
}
Set your API token as an environment variable:
export DANUBEDATA_API_TOKEN="your-api-token-here"
4. Initialize and Apply
# Initialize the provider
terraform init
# Preview changes
terraform plan
# Apply changes
terraform apply
Provider Configuration
The provider supports the following configuration options:
| Attribute | Type | Required | Description |
|---|---|---|---|
api_token | string | Yes | Your DanubeData API token. Can also be set via DANUBEDATA_API_TOKEN environment variable. |
base_url | string | No | API endpoint URL. Defaults to https://danubedata.ro/api/v1. Can be set via DANUBEDATA_BASE_URL environment variable. |
Authentication Methods
Recommended: Environment Variable
export DANUBEDATA_API_TOKEN="your-api-token"
provider "danubedata" {}
Alternative: Direct Configuration (not recommended for production)
provider "danubedata" {
api_token = "your-api-token" # Don't commit this to version control!
}
Using Terraform Variables
variable "danubedata_token" {
type = string
sensitive = true
}
provider "danubedata" {
api_token = var.danubedata_token
}
Then set the variable:
export TF_VAR_danubedata_token="your-api-token"
Available Resources
The provider includes 9 resource types:
| Resource | Description |
|---|---|
danubedata_vps | Virtual machines with shared or dedicated CPU |
danubedata_database | Managed MySQL, PostgreSQL, and MariaDB databases |
danubedata_cache | Redis, Valkey, and Dragonfly cache instances |
danubedata_storage_bucket | S3-compatible object storage buckets |
danubedata_storage_access_key | Access keys for object storage |
danubedata_ssh_key | SSH keys for VPS authentication |
danubedata_serverless | Knative-based serverless containers |
danubedata_firewall | Network security rules |
danubedata_vps_snapshot | Point-in-time VPS backups |
See Terraform Resources for detailed documentation.
Available Data Sources
The provider includes 4 data sources for querying existing resources:
| Data Source | Description |
|---|---|
danubedata_vps_images | List available OS images |
danubedata_cache_providers | List available cache providers |
danubedata_database_providers | List available database engines |
danubedata_ssh_keys | List existing SSH keys |
See Terraform Data Sources for detailed documentation.
Supported Datacenters
All resources can be deployed to the following datacenters:
| Code | Location | Country |
|---|---|---|
fsn1 | Falkenstein | Germany |
nbg1 | Nuremberg | Germany |
hel1 | Helsinki | Finland |
ash | Ashburn | USA |
State Management
Terraform tracks your infrastructure state in a state file. For team collaboration, use a remote backend:
Using DanubeData Object Storage as Backend
terraform {
backend "s3" {
bucket = "terraform-state"
key = "my-project/terraform.tfstate"
region = "eu-central-1"
endpoint = "https://s3.danubedata.ro"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_region_validation = true
force_path_style = true
}
}
Set S3 credentials:
export AWS_ACCESS_KEY_ID="your-access-key"
export AWS_SECRET_ACCESS_KEY="your-secret-key"
Importing Existing Resources
You can import existing DanubeData resources into Terraform management:
# Import a VPS instance
terraform import danubedata_vps.my_server 12345
# Import a database
terraform import danubedata_database.my_db 67890
# Import a storage bucket
terraform import danubedata_storage_bucket.my_bucket abc123
Find resource IDs in the DanubeData dashboard or via the API.
Best Practices
Use Variables for Environment-Specific Values
variable "environment" {
type = string
default = "dev"
}
variable "datacenter" {
type = string
default = "fsn1"
}
resource "danubedata_vps" "app" {
name = "${var.environment}-app-server"
datacenter = var.datacenter
# ...
}
Use Workspaces for Multiple Environments
# Create workspaces
terraform workspace new dev
terraform workspace new staging
terraform workspace new production
# Switch workspaces
terraform workspace select staging
Mark Sensitive Outputs
output "database_password" {
value = danubedata_database.main.password
sensitive = true
}
Use Terraform Cloud for Team Collaboration
For larger teams, consider using Terraform Cloud for:
- Remote state management
- Policy enforcement
- VCS integration
- Cost estimation
Troubleshooting
Authentication Errors
If you see "401 Unauthorized":
- Verify your API token is correct
- Check the token has the required permissions
- Ensure the
DANUBEDATA_API_TOKENenvironment variable is set
Provider Not Found
If Terraform can't find the provider:
terraform init -upgrade
Resource Timeouts
For long-running operations, configure timeouts:
resource "danubedata_vps" "app" {
# ...
timeouts {
create = "10m"
update = "10m"
delete = "5m"
}
}
Next Steps
- Terraform Resources - Detailed resource documentation
- Terraform Data Sources - Query existing resources
- Terraform Examples - Real-world configuration examples
- Terraform Registry - Official provider documentation
Support
- Documentation: registry.terraform.io/providers/AdrianSilaghi/danubedata
- GitHub Issues: Report bugs and request features
- Contact Support: Reach out to our support team for help