@@ -49,19 +49,22 @@ 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 for SSH tunnel only (most secure)
5454use_elastic_ip = true
5555grafana_password = "YourSecurePassword123!"
56+ bind_host = "127.0.0.1:" # Bind internal services to localhost
5657```
5758
5859###Optional parameters
5960
6061``` hcl
6162# 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")
63+ postgres_ai_api_key = "your-api-key" # For uploading reports
64+ enable_demo_db = false # Demo database (default: false)
65+ postgres_ai_version = "0.9" # Git branch/tag (default: "0.9")
66+ grafana_bind_host = "127.0.0.1:" # Grafana on localhost only (default, use SSH tunnel)
67+ # grafana_bind_host = "" # OR: Grafana accessible from outside
6568
6669monitoring_instances = [
6770 {
@@ -85,15 +88,17 @@ instance_type = "t3.medium"
8588data_volume_size = 100
8689data_volume_type = "gp3"
8790root_volume_type = "gp3"
88- allowed_ssh_cidr = ["203.0.113.0/24"]
89- allowed_cidr_blocks = ["203.0.113.0/24"]
91+ allowed_ssh_cidr = ["YOUR_IP/32"] # Replace with your actual IP
92+ allowed_cidr_blocks = [] # SSH tunnel only (most secure)
9093use_elastic_ip = true
9194grafana_password = "SecurePassword123!"
95+ bind_host = "127.0.0.1:"
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.9"
101+ grafana_bind_host = "127.0.0.1:" # Default, SSH tunnel only
97102
98103monitoring_instances = [
99104 {
@@ -116,6 +121,30 @@ terraform output ssh_command
116121ssh -i~ /.ssh/postgres-ai-key.pem ubuntu@$( terraform output -raw external_ip)
117122```
118123
124+ ###Grafana access
125+
126+ ** Option 1: SSH tunnel (default, most secure)**
127+
128+ When` allowed_cidr_blocks = [] ` :
129+
130+ ``` bash
131+ # Create SSH tunnel
132+ ssh -i~ /.ssh/postgres-ai-key.pem -L 3000:localhost:3000 ubuntu@$( terraform output -raw external_ip)
133+
134+ # Open browser
135+ open http://localhost:3000
136+ # Login: monitor / <your grafana_password>
137+ ```
138+
139+ ** Option 2: Direct access**
140+
141+ When` allowed_cidr_blocks = ["YOUR_IP/32"] ` :
142+
143+ ``` bash
144+ # Open browser
145+ open$( terraform output -raw grafana_url)
146+ ```
147+
119148###Service management
120149
121150``` bash
@@ -176,14 +205,25 @@ sudo docker-compose up -d
176205
177206###Recommendations
178207
179- 1 . Restrict SSHaccess :
208+ 1 . ** Most secure setup ( SSHtunnel only) ** :
180209``` hcl
181- allowed_ssh_cidr = ["your.ip.address/32"]
210+ allowed_ssh_cidr = ["your.ip.address/32"]
211+ allowed_cidr_blocks = [] # No direct Grafana access
212+ bind_host = "127.0.0.1:"
213+ grafana_bind_host = "127.0.0.1:"
214+ ```
215+
216+ Access Grafana via SSH tunnel:
217+ ``` bash
218+ ssh -i~ /.ssh/key.pem -L 3000:localhost:3000 ubuntu@instance-ip
182219```
183220
184- 2 . Restrict Grafana access:
221+ 2 . ** Production with direct Grafana access** :
185222``` hcl
186- allowed_cidr_blocks = ["your.office.ip/24"]
223+ allowed_ssh_cidr = ["YOUR_OFFICE_IP/24"] # Replace with your office network
224+ allowed_cidr_blocks = ["YOUR_OFFICE_IP/24"] # Replace with your office network
225+ bind_host = "127.0.0.1:" # Internal services protected
226+ grafana_bind_host = "" # Grafana accessible
187227```
188228
1892293 . Use AWS Systems Manager instead of SSH:
@@ -193,6 +233,13 @@ aws ssm start-session --target $(terraform output -raw instance_id)
193233
1942344 . Automate backups with AWS Backup or cron.
195235
236+ ###Port binding configuration
237+
238+ - ` bind_host = "127.0.0.1:" ` - Internal services only on localhost (recommended)
239+ - ` bind_host = "" ` - Internal services on all interfaces
240+ - ` grafana_bind_host = "127.0.0.1:" ` - Grafana only via SSH tunnel (default)
241+ - ` grafana_bind_host = "" ` - Grafana accessible from network
242+
196243##Monitoring
197244
198245###CloudWatch metrics
@@ -231,6 +278,13 @@ ssh ubuntu@your-ip "sudo docker ps -a"
231278###No access to Grafana
232279
233280``` bash
281+ # Check if allowed_cidr_blocks is empty (SSH tunnel required)
282+ grep allowed_cidr_blocks terraform.tfvars
283+
284+ # If empty, use SSH tunnel
285+ ssh -i~ /.ssh/key.pem -L 3000:localhost:3000 ubuntu@your-ip
286+ # Then open http://localhost:3000
287+
234288# Check Security Group
235289aws ec2 describe-security-groups \
236290 --group-ids$( terraform output -raw security_group_id)