Packer creates the image and timeout ssh

I’ve been trying to get this too work for 3 days now, nothing seems to work.
Could you please help me out or I have to change the solution.

image.pkr.hcl

variable "region" {
  type    = string
  default = "us-east-1"
}


source "amazon-ebs" "example" {
  ami_name      = "packer_tag_example {{timestamp}}"
  instance_type = "t2.micro"
  region        = var.region

  source_ami_filter {
    filters = {
      name                = "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*"
      root-device-type    = "ebs"
      virtualization-type = "hvm"
    }
    most_recent = true
    owners      = ["099720109477"]
  }
  ssh_username  =  "ubuntu"
  ssh_pty = true
  run_tags = {
     Name =  "Test Packer"
     c-domain =  "atlassian"
     c-subdomain =  "atlassian"
     c-service =  "bitubcket_prod"
     c-env =  "prod"
     c-team =  "atlassian-team"
     c-criticality =  "high"
     resource_owner =  "bplump"
     service_name =  "aws_ami_packer_builder"
    }
    tags = {
      Name =  "Test Packer"
      c-domain =  "atlassian"
     c-subdomain =  "atlassian"
     c-service =  "bitubcket_prod"
     c-env =  "prod"
     c-team =  "atlassian-team"
     c-criticality =  "high"
     resource_owner =  "bplump"
     service_name =  "aws_ami_packer_builder"
    }

}


build {
  sources = ["source.amazon-ebs.example"]

  provisioner "file" {
    source      = "../tf-packer.pub"
    destination = "/tmp/tf-packer.pub"
  }
  provisioner "shell" {
    script = "../scripts/setup.sh"
  }

}

logs:

2022/07/20 09:45:18 ui error: --> amazon-ebs: Timeout waiting for SSH.
type or paste code here

What am I missing?

Hi @AlexeiFerreiraCareem sorry to hear that you’re running into trouble here. At a first glance I don’t see anything out of the ordinary that would prevent Packer from logging in via SSH.

What version of Packer are you running?

There was an issue with unsupported key types preventing authentication but I believe that was solely for newer versions of Ubuntu 22.04+ and RedHat variants.

I’m able to successfully build an image using this template with the latest version of Packer v1.8.2. If you could provide a full log it might help pin point the issue.

That said if the instance is taking a long time to spin up it is possible that the SSH connection attempt is timing out. You can bump the timeout time by setting ssh_timeout = "30m".

I look forward to hearing back.