title: Terraform: wait till the instance is "reachable"
body: <p>I have some Terraform code with an <code>aws_instance</code> and a <code>null_resource</code>:</p>
  
  <pre><code>resource "aws_instance" "example" {
    ami           = data.aws_ami.server.id
    instance_type = "t2.medium"
    key_name      = aws_key_pair.deployer.key_name
  
    tags = {
      name = "example"
    }
  
    vpc_security_group_ids = [aws_security_group.main.id]
  }
  
  resource "null_resource" "example" {
    provisioner "local-exec" {
      command = "ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -T 300 -i ${aws_instance.example.public_dns}, --user centos --private-key files/id_rsa playbook.yml"
    }
  }
  </code></pre>
  
  <p>It kinda works, but sometimes there is a bug (probably when the instance in a pending state). When I rerun Terraform - it works as expected.</p>
  
  <p>Question: How can I run local-exec only when the instance is running and accepting an SSH connection?</p>