Skip to content

Commit 1cff296

Browse files
committed
Merge branch 'feature/terraform_module' into 'main'
feat: Add Terraform modules for AWS deployment See merge request postgres-ai/postgres_ai!58
2 parents 7959566 + 38c4997 commit 1cff296

File tree

12 files changed

+1294
-1
lines changed

12 files changed

+1294
-1
lines changed

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ services:
9999
container_name: grafana-with-datasources
100100
environment:
101101
GF_SECURITY_ADMIN_USER: monitor
102-
GF_SECURITY_ADMIN_PASSWORD: demo
102+
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_PASSWORD:-demo}
103103
GF_INSTALL_PLUGINS: yesoreyeram-infinity-datasource
104104
ports:
105105
- "3000:3000"

terraform/README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Terraform deployment modules
2+
3+
Infrastructure as Code modules for deploying postgres_ai monitoring to cloud providers.
4+
5+
## Available modules
6+
7+
### AWS (EC2)
8+
Single EC2 instance deployment with Docker Compose.
9+
10+
- **Path**: `aws/`
11+
- **Architecture**: Single EC2 instance with Docker Compose
12+
- **Best for**: Small to medium deployments (1-10 databases)
13+
- **Documentation**: [aws/README.md](aws/README.md)
14+
15+
### GCP (Coming soon)
16+
Deploy to Google Cloud Platform using Compute Engine or Cloud Run.
17+
18+
### Azure (Coming soon)
19+
Deploy to Microsoft Azure using Virtual Machines or Container Instances.
20+
21+
## Quick start
22+
23+
### AWS deployment
24+
25+
```bash
26+
cd terraform/aws
27+
28+
# Copy example variables
29+
cp terraform.tfvars.example terraform.tfvars
30+
31+
# Edit variables with your settings
32+
vim terraform.tfvars
33+
34+
# Initialize Terraform
35+
terraform init
36+
37+
# Review the plan
38+
terraform plan
39+
40+
# Deploy infrastructure (takes 5-10 minutes)
41+
terraform apply
42+
```
43+
44+
## Architecture overview
45+
46+
The AWS deployment creates:
47+
48+
1. **Compute**
49+
- Single EC2 instance (t3.medium default)
50+
- Ubuntu 22.04 LTS (Jammy) with Docker and Docker Compose
51+
- Systemd service for automatic startup
52+
53+
2. **Storage**
54+
- EBS volume for persistent data
55+
- Automated snapshots available via AWS Backup
56+
57+
3. **Networking**
58+
- VPC with public subnet
59+
- Security Group with restricted access
60+
- Optional Elastic IP for stable addressing
61+
62+
4. **Monitoring stack**
63+
- Runs docker-compose from cloned repository
64+
- Grafana accessible on port 3000
65+
66+
## Security considerations
67+
68+
- EC2 instance in public subnet (can be changed to private with bastion)
69+
- Security groups restrict access to SSH and Grafana only
70+
- All data encrypted at rest (EBS encryption)
71+
- Recommended: Use AWS Systems Manager Session Manager instead of SSH
72+
- Recommended: Restrict `allowed_cidr_blocks` to your office/VPN IP
73+
74+
## Instance types
75+
76+
Recommended instance types based on workload:
77+
78+
- **t3.medium**: 2 vCPU, 4 GiB RAM - suitable for 1-3 databases (default)
79+
- **t3.large**: 2 vCPU, 8 GiB RAM - suitable for 3-10 databases
80+
- **t3.xlarge**: 4 vCPU, 16 GiB RAM - suitable for 10+ databases
81+
82+
Additional options:
83+
- Use Spot Instances for non-critical workloads (subject to interruption)
84+
- Disable Elastic IP if stable address not required
85+
86+
## Support
87+
88+
For issues or questions:
89+
- Open an issue on GitLab
90+
- Contact PostgresAI support
91+
- Check documentation at https://postgres.ai
92+

terraform/aws/.gitignore

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Terraform files
2+
*.tfstate
3+
*.tfstate.*
4+
*.tfvars
5+
!terraform.tfvars.example
6+
.terraform/
7+
.terraform.lock.hcl
8+
crash.log
9+
override.tf
10+
override.tf.json
11+
*_override.tf
12+
*_override.tf.json
13+
tfplan
14+
plan.log
15+
16+
# OS files
17+
.DS_Store
18+
Thumbs.db
19+
20+
# IDE files
21+
.idea/
22+
.vscode/
23+
*.swp
24+
*.swo
25+
*~
26+
27+
# Backup files
28+
*.bak
29+
*.backup
30+
31+
# SSH keys
32+
*.pem
33+
*.key

terraform/aws/QUICKSTART.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Quick start
2+
3+
## Prerequisites
4+
5+
```bash
6+
# Create SSH key
7+
aws ec2 create-key-pair --key-name postgres-ai-key \
8+
--query 'KeyMaterial' --output text > ~/.ssh/postgres-ai-key.pem
9+
chmod 400 ~/.ssh/postgres-ai-key.pem
10+
11+
# Configure AWS credentials
12+
aws configure
13+
```
14+
15+
## Configure
16+
17+
```bash
18+
cd terraform/aws
19+
20+
# Copy example config
21+
cp terraform.tfvars.example terraform.tfvars
22+
vim terraform.tfvars
23+
```
24+
25+
Set required parameters:
26+
- `ssh_key_name` - your AWS SSH key name
27+
- `grafana_password` - custom password (optional, defaults to "demo")
28+
29+
## Add monitoring instances
30+
31+
Edit `terraform.tfvars` to add PostgreSQL instances to monitor:
32+
33+
```hcl
34+
monitoring_instances = [
35+
{
36+
name = "prod-db"
37+
conn_str = "postgresql://monitor:pass@db.example.com:5432/postgres"
38+
environment = "production"
39+
cluster = "main"
40+
node_name = "primary"
41+
}
42+
]
43+
```
44+
45+
## Deploy
46+
47+
```bash
48+
# Validate
49+
./validate.sh
50+
51+
# Deploy
52+
terraform init
53+
terraform plan
54+
terraform apply
55+
56+
# Get access info
57+
terraform output grafana_url
58+
terraform output ssh_command
59+
```
60+
61+
## Access
62+
63+
```bash
64+
# Grafana dashboard
65+
open $(terraform output -raw grafana_url)
66+
# Login: monitor / demo (or your custom password)
67+
68+
# SSH
69+
ssh -i ~/.ssh/postgres-ai-key.pem ubuntu@$(terraform output -raw public_ip)
70+
```
71+
72+
## Operations
73+
74+
```bash
75+
# View logs
76+
ssh ubuntu@IP "sudo cat /var/log/user-data.log"
77+
78+
# Restart services
79+
ssh ubuntu@IP "sudo systemctl restart postgres-ai"
80+
81+
# Destroy
82+
terraform destroy
83+
```
84+
85+
## Troubleshooting
86+
87+
```bash
88+
# Check installation log
89+
ssh ubuntu@IP "sudo cat /var/log/user-data.log"
90+
91+
# Check service status
92+
ssh ubuntu@IP "sudo systemctl status postgres-ai"
93+
94+
# Check containers
95+
ssh ubuntu@IP "sudo docker ps"
96+
```
97+

0 commit comments

Comments
 (0)