@@ -49,8 +49,8 @@ instance_type = "t3.medium"
4949data_volume_size = 50
5050data_volume_type = "gp3" # gp3 (SSD), st1 (HDD), sc1 (HDD)
5151root_volume_type = "gp3"
52- allowed_ssh_cidr = ["203.0.113.0/24"]
53- allowed_cidr_blocks = ["203.0.113.0/24"]
52+ allowed_ssh_cidr = ["YOUR_IP/32"] # Replace with your actual IP address
53+ allowed_cidr_blocks = [] # Empty list = no direct access, SSH tunnel required (most secure)
5454use_elastic_ip = true
5555grafana_password = "YourSecurePassword123!"
5656```
@@ -59,9 +59,13 @@ grafana_password = "YourSecurePassword123!"
5959
6060``` hcl
6161# OPTIONAL (have defaults)
62- postgres_ai_api_key = "your-api-key" # For uploading reports
63- enable_demo_db = false # Demo database (default: true)
64- postgres_ai_version = "main" # Git branch/tag (default: "main")
62+ postgres_ai_api_key = "your-api-key" # For uploading reports
63+ enable_demo_db = false # Demo database (default: false)
64+ postgres_ai_version = "0.10" # Git branch/tag (default: "0.10")
65+ bind_host = "127.0.0.1:" # Internal services on localhost (default, most secure)
66+ # bind_host = "" # OR: Bind to all interfaces
67+ grafana_bind_host = "127.0.0.1:" # Grafana on localhost only (default, use SSH tunnel)
68+ # grafana_bind_host = "" # OR: Grafana accessible from outside
6569
6670monitoring_instances = [
6771 {
@@ -85,15 +89,17 @@ instance_type = "t3.medium"
8589data_volume_size = 100
8690data_volume_type = "gp3"
8791root_volume_type = "gp3"
88- allowed_ssh_cidr = ["203.0.113.0/24"]
89- allowed_cidr_blocks = ["203.0.113.0/24"]
92+ allowed_ssh_cidr = ["YOUR_IP/32"] # Replace with your actual IP
93+ allowed_cidr_blocks = [] # Empty list = no direct access (most secure)
9094use_elastic_ip = true
9195grafana_password = "SecurePassword123!"
9296
9397# OPTIONAL
9498postgres_ai_api_key = "your-api-key"
9599enable_demo_db = false
96- postgres_ai_version = "v0.9"
100+ postgres_ai_version = "0.10"
101+ bind_host = "127.0.0.1:" # Default
102+ grafana_bind_host = "127.0.0.1:" # Default
97103
98104monitoring_instances = [
99105 {
@@ -113,7 +119,34 @@ monitoring_instances = [
113119``` bash
114120terraform output ssh_command
115121# Or directly:
116- ssh -i ~ /.ssh/postgres-ai-key.pem ubuntu@$( terraform output -raw external_ip)
122+ ssh -i ~ /.ssh/postgres-ai-key.pem ubuntu@$( terraform output -raw public_ip)
123+ ```
124+
125+ ### Grafana access
126+
127+ Terraform automatically detects the correct access method based on your configuration:
128+
129+ ``` bash
130+ # Get access instructions for your setup
131+ terraform output grafana_access_hint
132+ ```
133+
134+ ** Option 1: SSH tunnel (when ` allowed_cidr_blocks = [] ` or ` grafana_bind_host = "127.0.0.1:" ` )**
135+
136+ ``` bash
137+ # Create SSH tunnel
138+ ssh -i ~ /.ssh/postgres-ai-key.pem -NL 3000:localhost:3000 ubuntu@$( terraform output -raw public_ip)
139+
140+ # Open browser
141+ open http://localhost:3000
142+ # Login: monitor / <your grafana_password>
143+ ```
144+
145+ ** Option 2: Direct access (when ` allowed_cidr_blocks = ["YOUR_IP/32"] ` and ` grafana_bind_host = "" ` )**
146+
147+ ``` bash
148+ # Open browser
149+ open $( terraform output -raw grafana_url)
117150```
118151
119152### Service management
@@ -176,14 +209,25 @@ sudo docker-compose up -d
176209
177210### Recommendations
178211
179- 1 . Restrict SSH access :
212+ 1 . ** Most secure setup ( SSH tunnel only) ** :
180213``` hcl
181- allowed_ssh_cidr = ["your.ip.address/32"]
214+ allowed_ssh_cidr = ["your.ip.address/32"]
215+ allowed_cidr_blocks = [] # Empty list = no direct access to Grafana from anywhere
216+ bind_host = "127.0.0.1:"
217+ grafana_bind_host = "127.0.0.1:"
218+ ```
219+
220+ Access Grafana via SSH tunnel:
221+ ``` bash
222+ ssh -i ~ /.ssh/key.pem -NL 3000:localhost:3000 ubuntu@instance-ip
182223```
183224
184- 2 . Restrict Grafana access:
225+ 2 . ** Production with direct Grafana access** :
185226``` hcl
186- allowed_cidr_blocks = ["your.office.ip/24"]
227+ allowed_ssh_cidr = ["YOUR_OFFICE_IP/24"] # Replace with your office network
228+ allowed_cidr_blocks = ["YOUR_OFFICE_IP/24"] # Replace with your office network
229+ bind_host = "127.0.0.1:" # Internal services protected
230+ grafana_bind_host = "" # Grafana accessible
187231```
188232
1892333 . Use AWS Systems Manager instead of SSH:
@@ -193,6 +237,13 @@ aws ssm start-session --target $(terraform output -raw instance_id)
193237
1942384 . Automate backups with AWS Backup or cron.
195239
240+ ### Port binding configuration
241+
242+ - ` bind_host = "127.0.0.1:" ` - Internal services only on localhost (recommended)
243+ - ` bind_host = "" ` - Internal services on all interfaces
244+ - ` grafana_bind_host = "127.0.0.1:" ` - Grafana only via SSH tunnel (default)
245+ - ` grafana_bind_host = "" ` - Grafana accessible from network
246+
196247## Monitoring
197248
198249### CloudWatch metrics
@@ -231,6 +282,13 @@ ssh ubuntu@your-ip "sudo docker ps -a"
231282### No access to Grafana
232283
233284``` bash
285+ # Check if allowed_cidr_blocks is empty (SSH tunnel required)
286+ grep allowed_cidr_blocks terraform.tfvars
287+
288+ # If empty, use SSH tunnel
289+ ssh -i ~ /.ssh/key.pem -NL 3000:localhost:3000 ubuntu@your-ip
290+ # Then open http://localhost:3000
291+
234292# Check Security Group
235293aws ec2 describe-security-groups \
236294 --group-ids $( terraform output -raw security_group_id)
0 commit comments