I created the infrastructure manually following the steps provided in the link: connecting-to-a-database-within-an-amazon-vpc.
I could connect to RDS in private subnet from ec2 in public subnet perfectly. That is exactly what I wanted.
But when I tried to create the same exact replica using terraform, it just doesn't connect.
The command:
nslookup <my-hostname>
gives me the Private IP.
The command:
telnet x.x.x.x 5432
results in "telnet: Unable to connect to remote host: Connection timed out"
The command:
netstat -an | grep x.x.x.x
shows "SYN_SENT".
I tried allowing all the IP's in RDS security group by adding 0.0.0.0/0. That didn't work.
I tried to create RDS instance manually, but added it to terraform created VPC and tried to connect using terraform created ec2 instance. That didn't work.
Am i missing something ? Any help is much appreciated.