--- name: kafka-iac-deployment description: Terraform deployment expert for Apache Kafka, AWS MSK, and Azure Event Hubs. Use when provisioning Kafka infrastructure with IaC, comparing managed vs self-hosted platforms, or automating cluster deployments. --- # Kafka Infrastructure as Code (IaC) Deployment Expert guidance for deploying Apache Kafka using Terraform across multiple platforms. ## When to Use This Skill I activate when you need help with: - **Terraform deployments**: "Deploy Kafka with Terraform", "provision Kafka cluster" - **Platform selection**: "Should I use AWS MSK or self-hosted Kafka?", "compare Kafka platforms" - **Infrastructure planning**: "How to size Kafka infrastructure", "Kafka on AWS vs Azure" - **IaC automation**: "Automate Kafka deployment", "CI/CD for Kafka infrastructure" ## What I Know ### Available Terraform Modules This plugin provides 3 production-ready Terraform modules: #### 1. **Apache Kafka (Self-Hosted, KRaft Mode)** - **Location**: `plugins/specweave-kafka/terraform/apache-kafka/` - **Platform**: AWS EC2 (can adapt to other clouds) - **Architecture**: KRaft mode (no ZooKeeper dependency) - **Features**: - Multi-broker cluster (3-5 brokers recommended) - Security groups with SASL_SSL - IAM roles for S3 backups - CloudWatch metrics and alarms - Auto-scaling group support - Custom VPC and subnet configuration - **Use When**: - ✅ You need full control over Kafka configuration - ✅ Running Kafka 3.6+ (KRaft mode) - ✅ Want to avoid ZooKeeper operational overhead - ✅ Multi-cloud or hybrid deployments - **Variables**: ```hcl module "kafka" { source = "../../plugins/specweave-kafka/terraform/apache-kafka" environment = "production" broker_count = 3 kafka_version = "3.7.0" instance_type = "m5.xlarge" vpc_id = var.vpc_id subnet_ids = var.subnet_ids domain = "example.com" enable_s3_backups = true enable_monitoring = true } ``` #### 2. **AWS MSK (Managed Streaming for Kafka)** - **Location**: `plugins/specweave-kafka/terraform/aws-msk/` - **Platform**: AWS Managed Service - **Features**: - Fully managed Kafka service - IAM authentication + SASL/SCRAM - Auto-scaling (provisioned throughput) - Built-in monitoring (CloudWatch) - Multi-AZ deployment - Encryption in transit and at rest - **Use When**: - ✅ You want AWS to manage Kafka operations - ✅ Need tight AWS integration (IAM, KMS, CloudWatch) - ✅ Prefer operational simplicity over cost - ✅ Running in AWS VPC - **Variables**: ```hcl module "msk" { source = "../../plugins/specweave-kafka/terraform/aws-msk" cluster_name = "my-kafka-cluster" kafka_version = "3.6.0" number_of_broker_nodes = 3 broker_node_instance_type = "kafka.m5.large" vpc_id = var.vpc_id subnet_ids = var.private_subnet_ids enable_iam_auth = true enable_scram_auth = false enable_auto_scaling = true } ``` #### 3. **Azure Event Hubs (Kafka API)** - **Location**: `plugins/specweave-kafka/terraform/azure-event-hubs/` - **Platform**: Azure Managed Service - **Features**: - Kafka 1.0+ protocol support - Auto-inflate (elastic scaling) - Premium SKU for high throughput - Zone redundancy - Private endpoints (VNet integration) - Event capture to Azure Storage - **Use When**: - ✅ Running on Azure cloud - ✅ Need Kafka-compatible API without Kafka operations - ✅ Want serverless scaling (auto-inflate) - ✅ Integrating with Azure ecosystem - **Variables**: ```hcl module "event_hubs" { source = "../../plugins/specweave-kafka/terraform/azure-event-hubs" namespace_name = "my-event-hub-ns" resource_group_name = var.resource_group_name location = "eastus" sku = "Premium" capacity = 1 kafka_enabled = true auto_inflate_enabled = true maximum_throughput_units = 20 } ``` ## Platform Selection Decision Tree ``` Need Kafka deployment? START HERE: ├─ Running on AWS? │ ├─ YES → Want managed service? │ │ ├─ YES → Use AWS MSK module (terraform/aws-msk) │ │ └─ NO → Use Apache Kafka module (terraform/apache-kafka) │ └─ NO → Continue... │ ├─ Running on Azure? │ ├─ YES → Use Azure Event Hubs module (terraform/azure-event-hubs) │ └─ NO → Continue... │ ├─ Multi-cloud or hybrid? │ └─ YES → Use Apache Kafka module (most portable) │ ├─ Need maximum control? │ └─ YES → Use Apache Kafka module │ └─ Default → Use Apache Kafka module (self-hosted, KRaft mode) ``` ## Deployment Workflows ### Workflow 1: Deploy Self-Hosted Kafka (Apache Kafka Module) **Scenario**: You want full control over Kafka on AWS EC2 ```bash # 1. Create Terraform configuration cat > main.tf < main.tf < main.tf < # Get cluster details # Azure Event Hubs specific az eventhubs namespace list # List namespaces az eventhubs eventhub list --namespace-name --resource-group # List hubs ``` --- **Next Steps After Deployment**: 1. Use **kafka-observability** skill to set up Prometheus + Grafana monitoring 2. Use **kafka-cli-tools** skill to test cluster with kcat 3. Deploy your producer/consumer applications 4. Monitor cluster health and performance