# Terraform Resources

This page documents all resources available in the DanubeData Terraform provider.

## danubedata_vps

Manages a Virtual Private Server (VPS) instance.

### Example Usage

```hcl
resource "danubedata_ssh_key" "main" {
  name       = "my-key"
  public_key = file("~/.ssh/id_ed25519.pub")
}

resource "danubedata_vps" "web" {
  name             = "web-server"
  image            = "ubuntu-24.04"
  datacenter       = "fsn1"
  resource_profile = "small_shared"
  auth_method      = "ssh_key"
  ssh_key_id       = danubedata_ssh_key.main.id
}
```

### Argument Reference

| Attribute | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `name` | string | Yes | - | Server name. DNS-compatible, lowercase alphanumeric with hyphens. |
| `image` | string | Yes | - | OS image (e.g., `ubuntu-24.04`, `debian-12`, `alma-9`). |
| `datacenter` | string | Yes | - | Datacenter code (currently `fsn1`). |
| `resource_profile` | string | No | `nano_shared` | Resource profile. See profiles below. |
| `cpu_allocation_type` | string | No | `shared` | `shared` (4:1 overcommit) or `dedicated`. |
| `auth_method` | string | Yes | - | `ssh_key` or `password`. |
| `ssh_key_id` | string | Conditional | - | Required if `auth_method = "ssh_key"`. |
| `password` | string | Conditional | - | Required if `auth_method = "password"`. Min 12 characters. |
| `network_stack` | string | No | `dual_stack` | `ipv4_only`, `ipv6_only`, or `dual_stack`. |
| `cpu_cores` | number | No | - | Override CPU cores. Requires VPS to be stopped. |
| `memory_size_gb` | number | No | - | Override memory in GB. Requires VPS to be stopped. |
| `storage_size_gb` | number | No | - | Override storage in GB. Requires VPS to be stopped. |
| `custom_cloud_init` | string | No | - | Custom cloud-init configuration. |

### Resource Profiles

**Shared CPU:**
- `nano_shared`: 2 vCPU, 2 GB RAM, 20 GB NVMe
- `micro_shared`: 3 vCPU, 4 GB RAM, 40 GB NVMe
- `small_shared`: 4 vCPU, 8 GB RAM, 80 GB NVMe
- `medium_shared`: 8 vCPU, 16 GB RAM, 160 GB NVMe
- `large_shared`: 16 vCPU, 32 GB RAM, 320 GB NVMe

**Dedicated CPU:**
- `nano`: 2 vCPU, 2 GB RAM, 40 GB NVMe
- `micro`: 3 vCPU, 4 GB RAM, 80 GB NVMe
- `small`: 4 vCPU, 8 GB RAM, 160 GB NVMe
- `medium`: 8 vCPU, 16 GB RAM, 320 GB NVMe
- `large`: 16 vCPU, 32 GB RAM, 640 GB NVMe

### Available Images

- `ubuntu-26.04`, `ubuntu-24.04`, `ubuntu-22.04`
- `debian-13`, `debian-12`, `debian-11`
- `alma-9`, `alma-8`
- `rocky-9`, `rocky-8`
- `fedora-42`, `fedora-41`
- `alpine-3.22`, `alpine-3.21`, `alpine-3.20`
- `windows-server-2025`

### Attribute Reference

| Attribute | Type | Description |
|-----------|------|-------------|
| `id` | string | VPS instance ID. |
| `status` | string | Current status (Running, Stopped, etc.). |
| `public_ip` | string | Public IPv4 address. |
| `private_ip` | string | Private IP address. |
| `ipv6_address` | string | IPv6 address (if enabled). |
| `monthly_cost` | number | Monthly cost in EUR. |
| `monthly_cost_cents` | number | Monthly cost in cents. |
| `deployed_at` | string | Deployment timestamp. |
| `created_at` | string | Creation timestamp. |
| `updated_at` | string | Last update timestamp. |

### Import

```bash
terraform import danubedata_vps.web 12345
```

---

## danubedata_database

Manages a managed database instance.

### Example Usage

```hcl
resource "danubedata_database" "main" {
  name             = "production-db"
  database_name    = "myapp"
  engine           = "postgresql"
  version          = "16"
  resource_profile = "medium"
  datacenter       = "fsn1"
}

output "connection_string" {
  value     = "postgresql://${danubedata_database.main.username}@${danubedata_database.main.endpoint}:${danubedata_database.main.port}/${danubedata_database.main.database_name}"
  sensitive = true
}
```

### Argument Reference

| Attribute | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `name` | string | Yes | - | Instance name. DNS-compatible, lowercase alphanumeric. |
| `engine` | string | Yes | - | Database engine: `mysql`, `postgresql`, or `mariadb`. |
| `database_name` | string | No | - | Initial database name. Max 64 characters. |
| `resource_profile` | string | Yes | - | Profile: `small`, `medium`, or `large`. |
| `version` | string | No | - | Engine version (e.g., `16` for PostgreSQL). |
| `datacenter` | string | Yes | - | Datacenter code. |
| `parameter_group_id` | string | No | - | Custom parameter group ID. |

### Resource Profiles

| Profile | vCPU | Memory | Storage |
|---------|------|--------|---------|
| `small` | 1 | 2 GB | 25 GB |
| `medium` | 2 | 4 GB | 50 GB |
| `large` | 4 | 8 GB | 100 GB |

### Supported Versions

- **PostgreSQL**: 15, 16, 17, 18
- **MySQL**: 8.0, 8.4, 9.0, 9.1
- **MariaDB**: 10.11, 11.4, 11.6

### Attribute Reference

| Attribute | Type | Description |
|-----------|------|-------------|
| `id` | string | Database instance ID. |
| `status` | string | Current status. |
| `endpoint` | string | Connection hostname. |
| `port` | number | Connection port. |
| `username` | string | Admin username. |
| `storage_size_gb` | number | Storage size in GB. |
| `memory_size_mb` | number | Memory in MB. |
| `cpu_cores` | number | Number of CPU cores. |
| `monthly_cost` | number | Monthly cost in EUR. |

### Import

```bash
terraform import danubedata_database.main 67890
```

---

## danubedata_cache

Manages an in-memory cache instance.

### Example Usage

```hcl
resource "danubedata_cache" "redis" {
  name             = "app-cache"
  cache_provider   = "redis"
  resource_profile = "small"
  datacenter       = "fsn1"
}
```

### Argument Reference

| Attribute | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `name` | string | Yes | - | Instance name. Alphanumeric with hyphens. |
| `cache_provider` | string | Yes | - | Provider: `redis`, `valkey`, or `dragonfly`. |
| `resource_profile` | string | Yes | - | Profile: `micro`, `small`, `medium`, or `large`. |
| `memory_size_mb` | number | No | - | Override memory size in MB. |
| `cpu_cores` | number | No | - | Override CPU cores. |
| `version` | string | No | - | Provider version. |
| `datacenter` | string | Yes | - | Datacenter code. |
| `parameter_group_id` | string | No | - | Custom parameter group ID. |

### Resource Profiles

| Profile | Memory | vCPU |
|---------|--------|------|
| `micro` | 256 MB | 0.5 |
| `small` | 512 MB | 1 |
| `medium` | 1 GB | 2 |
| `large` | 2 GB | 4 |

### Cache Providers

- **Redis**: Industry-standard in-memory data store
- **Valkey**: Redis-compatible, community-driven fork
- **Dragonfly**: Multi-threaded, high-performance cache

### Attribute Reference

| Attribute | Type | Description |
|-----------|------|-------------|
| `id` | string | Cache instance ID. |
| `status` | string | Current status. |
| `endpoint` | string | Connection hostname. |
| `port` | number | Connection port (usually 6379). |
| `monthly_cost` | number | Monthly cost in EUR. |

### Import

```bash
terraform import danubedata_cache.redis 11111
```

---

## danubedata_storage_bucket

Manages an S3-compatible object storage bucket.

### Example Usage

```hcl
resource "danubedata_storage_bucket" "assets" {
  name               = "my-app-assets"
  display_name       = "Application Assets"
  region             = "fsn1"
  versioning_enabled = true
  encryption_enabled = true
}
```

### Argument Reference

| Attribute | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `name` | string | Yes | - | Bucket name. S3-compatible (3-63 chars, lowercase). |
| `display_name` | string | No | - | Human-readable display name. |
| `region` | string | Yes | - | Region (currently `fsn1`). |
| `public_access` | bool | No | `false` | Enable public read access. |
| `versioning_enabled` | bool | No | `false` | Enable object versioning. |
| `encryption_enabled` | bool | No | `true` | Enable server-side encryption. |
| `encryption_type` | string | No | `sse-s3` | `none`, `sse-s3`, or `sse-kms`. |

### Attribute Reference

| Attribute | Type | Description |
|-----------|------|-------------|
| `id` | string | Bucket ID. |
| `status` | string | Current status. |
| `endpoint_url` | string | S3 endpoint URL. |
| `minio_bucket_name` | string | Internal bucket name. |
| `size_bytes` | number | Total size in bytes. |
| `object_count` | number | Number of objects. |
| `monthly_cost` | number | Monthly cost in EUR. |

### Import

```bash
terraform import danubedata_storage_bucket.assets abc123
```

---

## danubedata_storage_access_key

Manages S3 access keys for object storage.

### Example Usage

```hcl
resource "danubedata_storage_access_key" "app" {
  name = "app-storage-key"
}

output "access_key_id" {
  value = danubedata_storage_access_key.app.access_key_id
}

output "secret_access_key" {
  value     = danubedata_storage_access_key.app.secret_access_key
  sensitive = true
}
```

### Argument Reference

| Attribute | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `name` | string | Yes | - | Access key name (1-255 chars). |
| `expires_at` | string | No | - | Expiration date (ISO 8601 format). |

### Attribute Reference

| Attribute | Type | Description |
|-----------|------|-------------|
| `id` | string | Access key ID (internal). |
| `access_key_id` | string | S3 access key ID. |
| `secret_access_key` | string | S3 secret access key (sensitive). |
| `status` | string | Current status. |

### Import

```bash
terraform import danubedata_storage_access_key.app key123
```

---

## danubedata_ssh_key

Manages SSH keys for VPS authentication.

### Example Usage

```hcl
resource "danubedata_ssh_key" "deploy" {
  name       = "deploy-key"
  public_key = file("~/.ssh/id_ed25519.pub")
}
```

### Argument Reference

| Attribute | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `name` | string | Yes | - | Key name. |
| `public_key` | string | Yes | - | OpenSSH format public key (ssh-rsa or ssh-ed25519). |

### Attribute Reference

| Attribute | Type | Description |
|-----------|------|-------------|
| `id` | string | SSH key ID. |
| `fingerprint` | string | SHA256 fingerprint. |
| `created_at` | string | Creation timestamp. |
| `updated_at` | string | Last update timestamp. |

### Import

```bash
terraform import danubedata_ssh_key.deploy 22222
```

---

## danubedata_serverless

Manages Knative-based serverless containers.

### Example Usage

```hcl
resource "danubedata_serverless" "api" {
  name             = "my-api"
  deployment_type  = "image"
  image_url        = "ghcr.io/myorg/my-api:latest"
  resource_profile = "small"
  port             = 8080
  min_instances    = 0
  max_instances    = 10

  environment_variables = {
    NODE_ENV = "production"
    LOG_LEVEL = "info"
  }
}

output "api_url" {
  value = danubedata_serverless.api.url
}
```

### Argument Reference

| Attribute | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `name` | string | Yes | - | Service name. |
| `resource_profile` | string | No | `small` | Profile: `small`, `medium`, or `large`. |
| `deployment_type` | string | Yes | - | `image` (Docker) or `git`. |
| `image_url` | string | Conditional | - | Docker image URL. Required if `deployment_type = "image"`. |
| `git_repository` | string | Conditional | - | Git repo URL. Required if `deployment_type = "git"`. |
| `git_branch` | string | No | `main` | Git branch to deploy. |
| `port` | number | No | `8080` | Container port (1-65535). |
| `min_instances` | number | No | `0` | Minimum instances. 0 enables scale-to-zero. |
| `max_instances` | number | No | `5` | Maximum instances (1-100). |
| `environment_variables` | map | No | - | Environment variables for the container. |

### Resource Profiles

| Profile | vCPU | Memory |
|---------|------|--------|
| `small` | 0.5 | 512 MB |
| `medium` | 1 | 1 GB |
| `large` | 2 | 2 GB |

### Attribute Reference

| Attribute | Type | Description |
|-----------|------|-------------|
| `id` | string | Serverless service ID. |
| `status` | string | Current status. |
| `url` | string | Public URL. |
| `current_month_cost_cents` | number | Current month cost in cents. |

### Import

```bash
terraform import danubedata_serverless.api 33333
```

---

## danubedata_firewall

Manages firewall rules for network security.

### Example Usage

```hcl
resource "danubedata_firewall" "web" {
  name           = "web-firewall"
  description    = "Firewall for web servers"
  default_action = "drop"

  rules {
    name             = "allow-ssh"
    action           = "allow"
    direction        = "inbound"
    protocol         = "tcp"
    port_range_start = 22
    port_range_end   = 22
    source_ips       = ["0.0.0.0/0"]
    priority         = 100
  }

  rules {
    name             = "allow-http"
    action           = "allow"
    direction        = "inbound"
    protocol         = "tcp"
    port_range_start = 80
    port_range_end   = 80
    source_ips       = ["0.0.0.0/0"]
    priority         = 200
  }

  rules {
    name             = "allow-https"
    action           = "allow"
    direction        = "inbound"
    protocol         = "tcp"
    port_range_start = 443
    port_range_end   = 443
    source_ips       = ["0.0.0.0/0"]
    priority         = 300
  }
}
```

### Argument Reference

| Attribute | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `name` | string | Yes | - | Firewall name. |
| `description` | string | No | - | Description. |
| `is_default` | bool | No | `false` | Mark as default firewall for team. |
| `default_action` | string | No | `drop` | Default action: `drop` or `accept`. |
| `rules` | list | No | - | List of firewall rules. |

### Rule Arguments

| Attribute | Type | Required | Description |
|-----------|------|----------|-------------|
| `name` | string | Yes | Rule name. |
| `action` | string | Yes | `allow` or `deny`. |
| `direction` | string | Yes | `inbound` or `outbound`. |
| `protocol` | string | Yes | `tcp`, `udp`, or `icmp`. |
| `port_range_start` | number | No | Start port (1-65535). |
| `port_range_end` | number | No | End port (1-65535). |
| `source_ips` | list | No | List of source CIDR blocks. |
| `priority` | number | Yes | Rule priority (lower = higher priority). |

### Attribute Reference

| Attribute | Type | Description |
|-----------|------|-------------|
| `id` | string | Firewall ID. |
| `status` | string | Current status. |

### Import

```bash
terraform import danubedata_firewall.web 44444
```

---

## danubedata_vps_snapshot

Manages point-in-time snapshots of VPS instances.

### Example Usage

```hcl
resource "danubedata_vps_snapshot" "backup" {
  name            = "pre-upgrade-backup"
  description     = "Snapshot before major upgrade"
  vps_instance_id = danubedata_vps.web.id
}
```

### Argument Reference

| Attribute | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `name` | string | Yes | - | Snapshot name. |
| `description` | string | No | - | Snapshot description. |
| `vps_instance_id` | string | Yes | - | ID of the VPS instance to snapshot. |

### Attribute Reference

| Attribute | Type | Description |
|-----------|------|-------------|
| `id` | string | Snapshot ID. |
| `status` | string | Current status. |
| `size_gb` | number | Snapshot size in GB. |
| `created_at` | string | Creation timestamp. |
| `updated_at` | string | Last update timestamp. |

### Import

```bash
terraform import danubedata_vps_snapshot.backup 55555
```

---

## danubedata_database_snapshot

Manages point-in-time snapshots of managed databases.

### Example Usage

```hcl
resource "danubedata_database_snapshot" "backup" {
  name                 = "pre-migration"
  description          = "Snapshot before schema migration"
  database_instance_id = danubedata_database.main.id
}
```

### Argument Reference

| Attribute | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `name` | string | Yes | - | Snapshot name. |
| `description` | string | No | - | Snapshot description. |
| `database_instance_id` | string | Yes | - | ID of the database instance to snapshot. |

### Attribute Reference

| Attribute | Type | Description |
|-----------|------|-------------|
| `id` | string | Snapshot ID. |
| `status` | string | Current status (`pending`, `completed`, `failed`). |
| `size_gb` | number | Snapshot size in GB. |
| `created_at` | string | Creation timestamp. |
| `updated_at` | string | Last update timestamp. |

### Import

```bash
terraform import danubedata_database_snapshot.backup 66666
```

---

## danubedata_cache_snapshot

Manages point-in-time snapshots of cache instances.

### Example Usage

```hcl
resource "danubedata_cache_snapshot" "backup" {
  name              = "nightly"
  description       = "Nightly cache snapshot"
  cache_instance_id = danubedata_cache.sessions.id
}
```

### Argument Reference

| Attribute | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `name` | string | Yes | - | Snapshot name. |
| `description` | string | No | - | Snapshot description. |
| `cache_instance_id` | string | Yes | - | ID of the cache instance to snapshot. |

### Attribute Reference

| Attribute | Type | Description |
|-----------|------|-------------|
| `id` | string | Snapshot ID. |
| `status` | string | Current status (`pending`, `completed`, `failed`). |
| `size_mb` | number | Snapshot size in MB. |
| `created_at` | string | Creation timestamp. |
| `updated_at` | string | Last update timestamp. |

### Import

```bash
terraform import danubedata_cache_snapshot.backup 77777
```

---

## danubedata_database_replica

Adds a read replica to a managed database instance.

### Example Usage

```hcl
resource "danubedata_database_replica" "read" {
  database_instance_id = danubedata_database.main.id
}
```

### Argument Reference

| Attribute | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `database_instance_id` | string | Yes | - | ID of the parent database instance. |

### Attribute Reference

| Attribute | Type | Description |
|-----------|------|-------------|
| `id` | string | Replica ID. |
| `replica_index` | number | 1-based index of this replica within the parent instance. |
| `seconds_behind_master` | number | Replication lag in seconds. |
| `is_replication_healthy` | bool | Whether replication is healthy. |

### Import

```bash
# Format: {database_instance_id}:{replica_index}
terraform import danubedata_database_replica.read 67890:1
```

---

## danubedata_parameter_group

Manages a reusable parameter group for databases or caches.

### Example Usage

```hcl
resource "danubedata_parameter_group" "redis_tuned" {
  name          = "redis-high-throughput"
  type          = "cache"
  provider_type = "redis"
  description   = "Higher I/O threading"

  parameters = {
    "io-threads" = "4"
  }
}
```

### Argument Reference

| Attribute | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `name` | string | Yes | - | Parameter group name. |
| `type` | string | Yes | - | Group type: `cache`, `database`, or `queue`. |
| `provider_type` | string | Yes | - | Provider, e.g. `redis`, `valkey`, `dragonfly`, `mysql`, `postgresql`, `mariadb`. |
| `parameters` | map(string) | Yes | - | Key/value parameters. Numeric and boolean values are expressed as strings. |
| `family` | string | No | - | Optional family label (e.g. `redis7.x`). |
| `description` | string | No | - | Optional description. |

### Attribute Reference

| Attribute | Type | Description |
|-----------|------|-------------|
| `id` | string | Parameter group ID. |
| `locked_parameters` | list(string) | Parameter keys that instances cannot override. |
| `is_default` | bool | Whether this is the default group for the provider type. |
| `is_active` | bool | Whether the group is active. |
| `is_system` | bool | Whether this is a system-managed group (read-only). |

### Import

```bash
terraform import danubedata_parameter_group.redis_tuned 88888
```

---

## danubedata_static_site

Manages a static site.

### Example Usage

```hcl
resource "danubedata_static_site" "marketing" {
  team_id = 42
  name    = "marketing-site"
}
```

### Argument Reference

| Attribute | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `team_id` | number | Yes | - | ID of the team that owns the site. |
| `name` | string | Yes | - | Name of the static site. |

### Attribute Reference

| Attribute | Type | Description |
|-----------|------|-------------|
| `id` | string | Site ID. |
| `slug` | string | URL slug for the site. |
| `url` | string | Default URL of the deployed site. |
| `output_directory` | string | Build output directory served as the site root. |
| `status` | string | Current status of the site. |
| `current_deployment_id` | number | ID of the currently-active deployment, if any. |

### Import

```bash
terraform import danubedata_static_site.marketing 99999
```

---

## danubedata_static_site_domain

Attaches a custom domain to a static site.

### Example Usage

```hcl
resource "danubedata_static_site_domain" "www" {
  static_site_id = danubedata_static_site.marketing.id
  domain         = "www.example.com"
}
```

After apply, configure the returned `verification_record` (a CNAME) at your DNS provider.

### Argument Reference

| Attribute | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `static_site_id` | string | Yes | - | ID of the parent static site. |
| `domain` | string | Yes | - | The custom domain (e.g. `www.example.com`). |

### Attribute Reference

| Attribute | Type | Description |
|-----------|------|-------------|
| `id` | string | Domain attachment ID. |
| `type` | string | Domain type: `default` or `custom`. |
| `status` | string | Status of the domain (`pending`, `active`, `failed`). |
| `verification_record` | string | DNS CNAME record to configure for verification. Empty once verified. |
| `verified_at` | string | Timestamp when the domain was verified, if any. |

### Import

```bash
# Format: {static_site_id}:{domain}
terraform import danubedata_static_site_domain.www abc123:www.example.com
```

---

## Timeouts

All resources support configurable timeouts:

```hcl
resource "danubedata_vps" "app" {
  # ...

  timeouts {
    create = "10m"
    update = "10m"
    delete = "5m"
  }
}
```

## Next Steps

- [Terraform Data Sources](https://docs.danubedata.ro/terraform-data-sources) - Query existing resources
- [Terraform Examples](https://docs.danubedata.ro/terraform-examples) - Real-world examples
- [Terraform Overview](https://docs.danubedata.ro/terraform-overview) - Getting started guide
