Terraform tips & tricks: loops, if-statements, and gotchas
Yevgeniy Brikman
354

Another good article.

Want to mention that in some situation, where you know that creation of one resource will take time before it can be used by another resource (eg, aws_iam_server_certificate should be created before using it aws_elb) you can use provisioner local-exec like this:

resource "aws_iam_server_certificate" "web" {
name = "web"
certificate_body = "..."
private_key = "..."

provisioner "local-exec" {
command = <<EOF
echo "Sleep 10 seconds so that my certificate is propagated by AWS IAM service"
sleep 10
EOF
}
}

PS: depends_on is not always help.