This repository contains the Terraform infrastructure for deploying the Kanshi monitoring stack and its remote agents on AWS.
The deployment consists of two main components:
- Kanshi Server: A
t3.smallx86_64 EC2 instance running the core monitoring services via Docker Compose:- TimescaleDB: Database for storing metrics.
- Core API: The central processing unit of Kanshi.
- Dashboard: Web interface for visualizing metrics.
- Kanshi Agents: Multiple EC2 instances (Ubuntu/Amazon Linux, x86_64/ARM64) running the Kanshi agent, which reports metrics back to the Server.
All resources are deployed within a dedicated VPC with public subnets across two availability zones.
main.tf: Defines the core infrastructure (VPC, Security Groups, and EC2 instances).variables.tf: Configuration variables for ports, environment, and security rules.outputs.tf: Terraform outputs for the deployment.modules/: Contains reusable modules forvpcandec2.scripts/:.env.example: Environment variables for the database.server_user_data.sh.tftpl: Provisioning script for the Server.agent_user_data.sh.tftpl: Provisioning script for the Agent.
-
Environment Setup: Copy the example environment file and update it with your desired database credentials:
cp scripts/.env.example scripts/.env
-
Initialize Terraform:
terraform init
-
Review the Plan:
terraform plan
-
Apply the Configuration:
terraform apply
The deployment will automatically use the values from scripts/.env for the Kanshi server's environment.
The security groups are configured with the following ingress rules by default:
| Port | Protocol | Description |
|---|---|---|
| 80 | TCP | Dashboard |
| 8080 | TCP | Core API |
| 50051 | TCP | Core gRPC (used by agents) |
| 22 | TCP | SSH |
| Port | Protocol | Description |
|---|---|---|
| 22 | TCP | SSH |
Note: Egress traffic is allowed for all protocols to any destination (0.0.0.0/0).
After a successful deployment, Terraform will output:
server_public_ip: The public IP address of the Kanshi Server.agent_public_ips: A map of the public IP addresses of the Kanshi Agents.dashboard_url: The URL to access the Kanshi Dashboard.