brikis98 / terraform-up-and-running-code

Code samples for the book "Terraform: Up & Running" by Yevgeniy Brikman
http://www.terraformupandrunning.com/
MIT License
2.87k stars 1.92k forks source link

Chapter 3 (the terraform_remote_state Data source) #47

Closed davidATsains closed 4 years ago

davidATsains commented 4 years ago

Chapter 3 section: The terraform_remote_state Data Source I am completed this section which taught me how the web sever cluster can access the database address and port via Terraform. I got the address for the alb dns but when i curl it on the command line or on a web browser nothing happens it times out Please can you tell where i went wrong? what can i do to address this?

Screenshot 2020-01-02 at 11 37 43

brikis98 commented 4 years ago

Hard to say without seeing the code! You can typically use a systematic approach to debug these sorts of things, going through each step of the network path (you can check most of this in the AWS web console):

  1. Does the security group of the ELB allow incoming TCP requests on port 80 from your IP (or from 0.0.0.0/0)?
  2. Are there any EC2 instances registered in the ELB?
  3. Are the health checks passing for those instances?
  4. Does the security group of the ELB allow outbound requests (necessary to send health checks)?
  5. Does the security group of the instances allow inbound requests from the ELB?
  6. Is the web server running on the instances? You can SSH to an instance and curl localhost:8080 to check. You can also look for errors in the system log output to see if there was an error in your User Data script.

Any of the above could lead to the symptoms you're seeing, so check one at a time!

davidATsains commented 4 years ago

Hard to say without seeing the code! You can typically use a systematic approach to debug these sorts of things, going through each step of the network path (you can check most of this in the AWS web console):

  1. Does the security group of the ELB allow incoming TCP requests on port 80 from your IP (or from 0.0.0.0/0)?
  2. Are there any EC2 instances registered in the ELB?
  3. Are the health checks passing for those instances?
  4. Does the security group of the ELB allow outbound requests (necessary to send health checks)?
  5. Does the security group of the instances allow inbound requests from the ELB?
  6. Is the web server running on the instances? You can SSH to an instance and curl localhost:8080 to check. You can also look for errors in the system log output to see if there was an error in your User Data script.

Any of the above could lead to the symptoms you're seeing, so check one at a time!

I believed that since i used the security group both for the instance and elb in chapter 2, i used the same terraform code for chapter 3. Thus, this was the root of the problem. but now i have fixed it.