0

I have this below code when I run apply it gets a timeout. An instance is created but remote-exec commands don't work. I am running this in the windows 10 machine. Terraform version is v0.12.12 provider.aws v2.33.0

resource "aws_instance" "web" {
  ami           = "ami-54d2a63b"
  instance_type = "t2.nano"
  key_name = "terra"
  tags = {
    Name = "HelloWorld"
  }
   connection {
    type     = "ssh"
    user     = "ubuntu"
    private_key = "${file("C:/Users/Vinayak/Downloads/terra.pem")}"
    host     = self.public_ip

  }

  provisioner "remote-exec" {
    inline = [
      "echo cat > test.txt"
    ]
  }

}
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
niranjan pb
  • 1,125
  • 11
  • 14
  • It looks like you're looking for something similar to -- https://stackoverflow.com/questions/55878755/terraform-fails-remote-exec-aws-ec2 there's a comment in there that this is likely a security issue: "open your security group/other network policies to the instance to allow SSH from the machine running Terraform" – Pam Jun 01 '20 at 19:47

1 Answers1

0

Please try to change you host line to

host = "${self.public_ip}"

Letting people know the actual error message you are getting might help too. :)

Izan
  • 9
  • 1
  • 1
    Interpolation-only expressions are deprecated, so the self.public_ip is correct (and is appropriate for all versions of Terraform 0.12+) – Pam Jun 01 '20 at 19:48