After running Terraform apply, you get a connection timeout error. What is the most likely cause?
medium
A. The EC2 instance's security group does not allow SSH (port 22) inbound
B. The password authentication is not supported by SSH
C. The inline commands have syntax errors
D. The host attribute should be a private IP, not public IP
Solution
Step 1: Understand connection timeout causes
Timeout usually means network connection to SSH port 22 is blocked or unreachable.
Step 2: Check common network issues
If the EC2 security group lacks inbound SSH rules, connection fails despite correct credentials.
Final Answer:
The EC2 instance's security group does not allow SSH (port 22) inbound -> Option A
Quick Check:
Timeout = network block on SSH port 22 [OK]
Hint: Timeout usually means SSH port 22 blocked in firewall/security group [OK]
Common Mistakes:
Blaming inline command syntax for connection errors
Assuming password auth is always unsupported
Confusing public and private IP for SSH host
5. You want to use remote-exec to run a script on multiple newly created instances in a loop. Which approach is best to ensure commands run on each instance correctly?
hard
A. Use local-exec provisioner to SSH manually to each instance
B. Define one resource and run remote-exec with a list of all instance IPs in one provisioner
C. Run remote-exec provisioner only once after all instances are created using a null_resource
D. Use a for_each on the resource and include a remote-exec provisioner inside each resource block
Solution
Step 1: Understand resource loops with provisioners
Using for_each creates multiple resource instances, each with its own provisioner execution.
Step 2: Why per-resource provisioner is best
Provisioners inside each resource run commands on that specific instance, ensuring correct targeting.
Final Answer:
Use a for_each on the resource and include a remote-exec provisioner inside each resource block -> Option D
Quick Check:
Provisioner per resource instance = A [OK]
Hint: Use for_each with provisioner inside resource for multiple instances [OK]
Common Mistakes:
Trying to run remote-exec on all IPs in one provisioner
Using null_resource without proper triggers
Using local-exec instead of remote-exec for remote commands
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.