# Task Services Guide

Complete reference for 50+ task services across 18 categories for infrastructure automation.

## Overview

Task services are specialized microservices that execute specific infrastructure operations.
They are organized by capability and integrated with Provisioning's orchestrator.

## Task Service Categories

### 1. Compute Services (8 services)

Services for managing compute resources (VMs, containers, serverless):

| Service | Purpose | Providers | Version |
| --- | --- | --- | --- |
| **vm-manager** | Virtual machine lifecycle | AWS, UpCloud, Hetzner | v3.1.0 |
| **kubernetes-deployer** | K8s cluster management | AWS, UpCloud, Hetzner | v3.2.0 |
| **container-runtime** | Container orchestration | Docker, Podman, Containerd | v3.0.0 |
| **serverless-deployer** | Serverless functions | AWS Lambda, GCP Cloud Functions | v2.1.0 |
| **batch-processor** | Batch job execution | AWS Batch, GCP Dataflow | v2.2.0 |
| **scaling-manager** | Auto-scaling policies | All providers | v3.3.0 |
| **scheduler** | Scheduled execution | Cron, Kubernetes CronJobs | v3.0.0 |
| **cost-optimizer** | Cost optimization | All providers | v1.0.0 |

**Example: Using vm-manager**

```nickel
{
  task = {
    type = "vm-manager",
    action = "create",

    parameters = {
      provider = "aws",
      instance_type = "t3.large",
      image = "ubuntu-22.04",
      count = 3,
      name = "web-server",
      tags = { environment = "production" }
    }
  }
}
```

### 2. Database Services (6 services)

Database provisioning, migration, and backup:

| Service | Purpose | Databases | Version |
| --- | --- | --- | --- |
| **postgres-manager** | PostgreSQL management | PostgreSQL | v3.1.0 |
| **mysql-manager** | MySQL/MariaDB management | MySQL, MariaDB | v3.0.0 |
| **mongodb-deployer** | MongoDB cluster setup | MongoDB | v2.3.0 |
| **redis-cache** | Redis cluster management | Redis | v3.2.0 |
| **backup-restorer** | Backup and restore | All databases | v3.0.0 |
| **migration-service** | Database migration | Multi-source | v2.1.0 |

**Example: Using postgres-manager**

```nickel
{
  task = {
    type = "postgres-manager",
    action = "create",

    parameters = {
      name = "production-db",
      version = "15",
      instance_class = "db.r6i.2xlarge",
      replicas = 3,
      multi_az = true,
      backup_retention = 30
    }
  }
}
```

### 3. Networking Services (7 services)

Network configuration, security groups, load balancing:

| Service | Purpose | Providers | Version |
| --- | --- | --- | --- |
| **vpc-manager** | VPC/Network creation | AWS, UpCloud, Hetzner | v3.1.0 |
| **security-group** | Firewall rules | All providers | v3.0.0 |
| **load-balancer** | LB configuration | All providers | v3.2.0 |
| **dns-manager** | DNS record management | Route53, CloudDNS | v3.0.0 |
| **vpn-gateway** | VPN setup | All providers | v2.1.0 |
| **nat-gateway** | NAT configuration | AWS, GCP | v3.0.0 |
| **bgp-router** | BGP routing | Hetzner, UpCloud | v1.0.0 |

**Example: Using load-balancer**

```nickel
{
  task = {
    type = "load-balancer",
    action = "create",

    parameters = {
      name = "main-lb",
      type = "application",
      backends = ["web-01", "web-02", "web-03"],
      health_check = {
        path = "/health",
        interval = 30,
        timeout = 5
      },
      ssl_policy = "modern"
    }
  }
}
```

### 4. Storage Services (5 services)

Block storage, object storage, and file systems:

| Service | Purpose | Providers | Version |
| --- | --- | --- | --- |
| **ebs-manager** | Block storage | AWS | v3.0.0 |
| **s3-manager** | Object storage | AWS, MinIO | v3.1.0 |
| **efs-deployer** | NFS/File storage | AWS | v2.1.0 |
| **snapshot-manager** | Snapshot management | All providers | v3.0.0 |
| **disk-optimizer** | Disk optimization | All providers | v1.0.0 |

**Example: Using s3-manager**

```nickel
{
  task = {
    type = "s3-manager",
    action = "create",

    parameters = {
      bucket_name = "app-backups",
      region = "us-east-1",
      encryption = "aes256",
      versioning = true,
      lifecycle_rules = [
        {
          days = 90,
          action = "transition",
          storage_class = "GLACIER"
        }
      ]
    }
  }
}
```

### 5. Monitoring & Logging (6 services)

Observability, metrics, and logging:

| Service | Purpose | Stack | Version |
| --- | --- | --- | --- |
| **prometheus-deployer** | Metrics collection | Prometheus | v3.0.0 |
| **grafana-deployer** | Visualization | Grafana | v3.1.0 |
| **elasticsearch-deployer** | Log aggregation | ELK Stack | v3.0.0 |
| **alerting-service** | Alert management | Alertmanager | v2.1.0 |
| **tracing-deployer** | Distributed tracing | Jaeger | v2.0.0 |
| **log-aggregator** | Log collection | Fluentd, Logstash | v3.0.0 |

**Example: Using prometheus-deployer**

```nickel
{
  task = {
    type = "prometheus-deployer",
    action = "create",

    parameters = {
      replicas = 2,
      retention = "30d",
      scrape_interval = "15s",
      storage_size = "500Gi"
    }
  }
}
```

### 6. Security Services (5 services)

Secrets management, certificate authority, access control:

| Service | Purpose | Integration | Version |
| --- | --- | --- | --- |
| **vault-deployer** | Secrets management | HashiCorp Vault | v3.0.0 |
| **certificate-manager** | TLS certificates | cert-manager | v3.1.0 |
| **kms-service** | Key management | AWS KMS, vault | v3.0.0 |
| **iam-manager** | Identity & access | AWS IAM | v3.0.0 |
| **secret-scanner** | Secret detection | GitGuardian | v1.0.0 |

**Example: Using vault-deployer**

```nickel
{
  task = {
    type = "vault-deployer",
    action = "initialize",

    parameters = {
      replicas = 3,
      storage_backend = "raft",
      unsealing_keys = 5,
      key_threshold = 3,
      auto_unseal = true
    }
  }
}
```

### 7. Container Registry (2 services)

Container image management:

| Service | Purpose | Registries | Version |
| --- | --- | --- | --- |
| **registry-deployer** | Private registry setup | Docker Registry, Harbor | v2.0.0 |
| **image-scanner** | Container image scanning | Trivy, Clair | v1.1.0 |

**Example: Using registry-deployer**

```nickel
{
  task = {
    type = "registry-deployer",
    action = "create",

    parameters = {
      name = "private-registry",
      storage = "s3",
      s3_bucket = "docker-images",
      replicas = 2
    }
  }
}
```

### 8. CI/CD Services (3 services)

Continuous integration and deployment:

| Service | Purpose | Platforms | Version |
| --- | --- | --- | --- |
| **github-actions-deployer** | GitHub Actions runner | GitHub | v2.0.0 |
| **gitlab-runner-deployer** | GitLab Runner setup | GitLab | v2.0.0 |
| **jenkins-deployer** | Jenkins setup | Jenkins | v1.0.0 |

### 9. Message Queue Services (3 services)

Async message processing:

| Service | Purpose | Queues | Version |
| --- | --- | --- | --- |
| **kafka-deployer** | Kafka cluster | Apache Kafka | v2.1.0 |
| **rabbitmq-deployer** | RabbitMQ setup | RabbitMQ | v2.0.0 |
| **sqs-manager** | AWS SQS setup | AWS SQS | v2.0.0 |

**Example: Using kafka-deployer**

```nickel
{
  task = {
    type = "kafka-deployer",
    action = "create",

    parameters = {
      brokers = 3,
      partitions_default = 3,
      replication_factor = 3,
      retention_ms = 604800000  # 7 days
    }
  }
}
```

### 10-18. Additional Categories

| Category | Services | Examples |
| --- | --- | --- |
| **Backup & DR** | 4 | Backup manager, snapshot, recovery, replication |
| **API Gateway** | 2 | Kong, AWS API Gateway |
| **Service Mesh** | 2 | Istio, Linkerd |
| **API Documentation** | 1 | OpenAPI/Swagger |
| **Data Processing** | 2 | Spark, Dataflow |
| **Monitoring Agents** | 2 | Datadog Agent, New Relic |
| **Testing** | 2 | Selenium Grid, Performance testing |
| **Utilities** | 2 | SSH utilities, File sync |

## Task Service Lifecycle

### Create

```nickel
{
  task = {
    type = "postgres-manager",
    action = "create",
    parameters = { ... }
  }
}
```

### Update

```nickel
{
  task = {
    type = "postgres-manager",
    action = "update",
    resource_id = "prod-db",
    parameters = {
      instance_class = "db.r6i.4xlarge"
    }
  }
}
```

### Delete

```nickel
{
  task = {
    type = "postgres-manager",
    action = "delete",
    resource_id = "prod-db",
    parameters = {
      final_snapshot = true,
      skip_final_snapshot = false
    }
  }
}
```

### Describe

```nickel
{
  task = {
    type = "postgres-manager",
    action = "describe",
    resource_id = "prod-db"
  }
}
```

## Task Execution in Orchestrator

Submit a batch with multiple task services:

```nickel
{
  batch = {
    name = "infrastructure-setup",
    operations = [
      {
        name = "create-vpc",
        action = "task",
        task = {
          type = "vpc-manager",
          parameters = { ... }
        }
      },
      {
        name = "create-database",
        action = "task",
        task = {
          type = "postgres-manager",
          parameters = { ... }
        },
        depends_on = ["create-vpc"]
      },
      {
        name = "create-kubernetes",
        action = "task",
        task = {
          type = "kubernetes-deployer",
          parameters = { ... }
        },
        depends_on = ["create-vpc"]
      }
    ]
  }
}
```

## Task Service Configuration

Configure task services in workspace:

```bash
# List available task services
provisioning task-services list

# Show service details
provisioning task-services show postgres-manager

# Configure service parameters
provisioning task-services config postgres-manager --set max_connections=500

# Check service health
provisioning task-services health
```

## Error Handling

Handle task failures gracefully:

```nickel
{
  batch = {
    operations = [
      {
        name = "critical-operation",
        action = "task",
        task = { ... },
        retry = {
          max_attempts = 3,
          backoff = "exponential",
          initial_delay = "5s"
        },
        on_failure = {
          action = "rollback",
          cleanup_resources = true
        }
      }
    ]
  }
}
```

## Performance Tuning

Optimize task execution:

```nickel
{
  task = {
    type = "vm-manager",
    action = "create",
    parameters = { ... },

    # Performance settings
    performance = {
      parallel_count = 5,  # Create 5 VMs in parallel
      timeout = "600s",
      retry_on_timeout = true
    }
  }
}
```

## Related Documentation

- [Batch Workflow System](./batch-workflows.md)
- [Providers Guide](./providers.md)
- [Clusters](./clusters.md)
- [Orchestrator](../features/orchestrator.md)
