# Provider-Specific Configuration Guides

Cloud provider and infrastructure platform integrations for Provisioning.

## AWS (Amazon Web Services)

Configure Provisioning for AWS deployments.

### Authentication

```bash
# Configure AWS credentials
aws configure --profile provisioning

# Or use environment variables
export AWS_ACCESS_KEY_ID="AKIA..."
export AWS_SECRET_ACCESS_KEY="..."
export AWS_DEFAULT_REGION="us-east-1"
```

### AWS Configuration

```nickel
{
  provider = "aws",

  aws = {
    region = "us-east-1",
    profile = "provisioning",

    # VPC configuration
    vpc = {
      cidr_block = "10.0.0.0/16",
      enable_dns_hostnames = true,
      enable_dns_support = true
    },

    # Default subnets
    subnets = [
      {
        cidr_block = "10.0.1.0/24",
        availability_zone = "us-east-1a"
      },
      {
        cidr_block = "10.0.2.0/24",
        availability_zone = "us-east-1b"
      }
    ],

    # Security group
    security_group = {
      name = "provisioning-sg",
      ingress = [
        { from_port = 22, to_port = 22, protocol = "tcp", cidr_blocks = ["0.0.0.0/0"] },
        { from_port = 443, to_port = 443, protocol = "tcp", cidr_blocks = ["0.0.0.0/0"] }
      ]
    },

    # Instance settings
    instances = {
      ami = "ami-0c55b159cbfafe1f0",  # Ubuntu 22.04
      instance_type = "t3.large",
      ebs_optimized = true
    },

    # RDS database
    rds = {
      engine = "postgres",
      engine_version = "15",
      instance_class = "db.r6i.xlarge",
      allocated_storage = 500,
      storage_type = "gp3",
      multi_az = true
    }
  }
}
```

### AWS IAM Roles

```nickel
{
  iam = {
    roles = [
      {
        name = "provisioning-role",
        assume_role_policy = {
          Effect = "Allow",
          Principal = { Service = "ec2.amazonaws.com" },
          Action = "sts:AssumeRole"
        },
        policies = [
          {
            name = "ec2-full-access",
            policy = {
              Effect = "Allow",
              Action = "ec2:*",
              Resource = "*"
            }
          }
        ]
      }
    ]
  }
}
```

## UpCloud

Configure for UpCloud platform.

### Authentication

```bash
# Set UpCloud credentials
export UPCLOUD_USERNAME="[user@example.com](mailto:user@example.com)"
export UPCLOUD_API_PASSWORD="api-password"
```

### UpCloud Configuration

```nickel
{
  provider = "upcloud",

  upcloud = {
    # Zone selection
    zone = "us-sjc",  # Silicon Valley

    # Network configuration
    network = {
      cidr_block = "10.0.0.0/16",
      dns = ["94.237.127.9", "94.237.127.10"]
    },

    # Server defaults
    server_defaults = {
      plan = "4xCPU-8GB",  # 4 cores, 8GB RAM
      storage_tier = "maxiops",
      storage_size = 100,  # GB
      os_disk_tier = "maxiops",
      firewall = "on"
    },

    # Available plans
    available_plans = [
      { name = "1xCPU-1GB", cores = 1, memory = 1 },
      { name = "2xCPU-2GB", cores = 2, memory = 2 },
      { name = "4xCPU-8GB", cores = 4, memory = 8 },
      { name = "8xCPU-16GB", cores = 8, memory = 16 },
      { name = "16xCPU-32GB", cores = 16, memory = 32 }
    ]
  }
}
```

### UpCloud Firewall

```nickel
{
  firewall = {
    enabled = true,
    rules = [
      {
        action = "accept",
        direction = "in",
        family = "IPv4",
        protocol = "tcp",
        destination_port_start = 22,
        destination_port_end = 22
      },
      {
        action = "accept",
        direction = "in",
        family = "IPv4",
        protocol = "tcp",
        destination_port_start = 80,
        destination_port_end = 80
      },
      {
        action = "accept",
        direction = "in",
        family = "IPv4",
        protocol = "tcp",
        destination_port_start = 443,
        destination_port_end = 443
      }
    ]
  }
}
```

## Hetzner Cloud

Configure for Hetzner platform.

### Authentication

```bash
export HCLOUD_TOKEN="token..."
```

### Hetzner Configuration

```nickel
{
  provider = "hetzner",

  hetzner = {
    # Location selection
    location = "fsn1",  # Falkenstein, Germany

    # Server configuration
    server = {
      server_type = "cx21",  # 2 cores, 4GB RAM
      image = "ubuntu-22.04",
      public_net = {
        ipv4_enabled = true,
        ipv6_enabled = true
      }
    },

    # Networking
    network = {
      cidr = "10.0.0.0/16"
    },

    # Available server types
    available_types = [
      { id = "cx11", cores = 1, memory = 1, disk = 25 },
      { id = "cx21", cores = 2, memory = 4, disk = 40 },
      { id = "cx31", cores = 2, memory = 8, disk = 80 },
      { id = "cx41", cores = 4, memory = 16, disk = 160 }
    ]
  }
}
```

### Hetzner Load Balancer

```nickel
{
  load_balancer = {
    name = "web-lb",
    load_balancer_type = "lb11",
    location = "fsn1",

    services = [
      {
        protocol = "http",
        listen_port = 80,
        destination_port = 80,
        proxyprotocol = false
      },
      {
        protocol = "https",
        listen_port = 443,
        destination_port = 443,
        proxyprotocol = false
      }
    ]
  }
}
```

## Local Development

Configure for local/on-premise deployments.

### Local Configuration

```nickel
{
  provider = "local",

  local = {
    # Docker/Podman for containerized workloads
    container_runtime = "docker",

    # Networking
    network = {
      bridge_name = "provisioning-br0",
      subnet = "172.20.0.0/16"
    },

    # Storage
    storage = {
      base_path = "/var/provisioning",
      enable_nfs = false
    },

    # Kubernetes (if using local k8s)
    kubernetes = {
      context = "docker-desktop",  # or kind, minikube
      namespace = "provisioning"
    }
  }
}
```

### Local Kubernetes Setup

```bash
# Create local Kubernetes cluster
kind create cluster --name provisioning \
  --config - <<EOF
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
EOF

# Configure provisioning
provisioning workspace create local-dev \
  --provider local \
  --kubernetes-context kind-provisioning
```

## Demo/Test Provider

For testing and CI/CD:

```nickel
{
  provider = "demo",

  demo = {
    # Simulated infrastructure
    simulate_latency = true,
    latency_ms = 100,

    # Always succeed for testing
    always_succeed = false,

    # Custom resource limits
    max_instances = 100,
    max_storage_gb = 1000
  }
}
```

## Multi-Cloud Configuration

Deploy across multiple providers:

```nickel
{
  infrastructure = {
    # Web tier in AWS
    web_tier = {
      provider = "aws",
      region = "us-east-1",
      servers = [
        { name = "web-01", instance_type = "t3.large" },
        { name = "web-02", instance_type = "t3.large" }
      ]
    },

    # API tier in UpCloud
    api_tier = {
      provider = "upcloud",
      zone = "us-sjc",
      servers = [
        { name = "api-01", plan = "4xCPU-8GB" },
        { name = "api-02", plan = "4xCPU-8GB" }
      ]
    },

    # Database in Hetzner
    database_tier = {
      provider = "hetzner",
      location = "fsn1",
      server = {
        server_type = "cx41",
        name = "db-primary"
      }
    }
  }
}
```

## Provider Credentials

Secure credential management:

```bash
# Store provider credentials in vault
provisioning vault add --name "aws-access-key" --value "AKIA..."
provisioning vault add --name "upcloud-api-password" --value "..."
provisioning vault add --name "hcloud-token" --value "..."
```

Use in configuration:

```nickel
let credentials = {
  aws = {
    access_key = std.get_env "AWS_ACCESS_KEY_ID",
    secret_key = std.get_env "AWS_SECRET_ACCESS_KEY"
  },
  upcloud = {
    username = std.get_env "UPCLOUD_USERNAME",
    api_password = std.get_env "UPCLOUD_API_PASSWORD"
  }
}

{ credentials = credentials }
```

## Provider Limits and Quotas

### AWS

- EC2 instances: 20 (soft limit)
- VPCs: 5 per region
- RDS: 20 instances
- EBS: 100 snapshots

### UpCloud

- Servers: 50 per account
- Networks: 100
- Storage: 5TB total

### Hetzner

- Cloud servers: 100 per account
- Load balancers: 10
- Networks: 20

## Provider Health Checks

Monitor provider connectivity:

```bash
# Check provider connectivity
provisioning provider health

# Test authentication
provisioning provider auth-test aws
provisioning provider auth-test upcloud
provisioning provider auth-test hetzner

# Get provider info
provisioning provider info aws
provisioning provider info upcloud
```

## Cost Estimation by Provider

Compare costs across providers:

```bash
provisioning cost estimate \
  --providers aws,upcloud,hetzner \
  --infrastructure config.ncl \
  --region us-east-1

# Output:
# AWS:     $1,250/month
# UpCloud: $980/month
# Hetzner: $850/month
```

## Related Documentation

- [Providers Reference](./providers.md)
- [Multi-Cloud Deployment](../examples/multi-cloud.md)
- [Infrastructure Overview](./README.md)
- [Disaster Recovery](../guides/disaster-recovery.md)
