-1

i create a private ami on amazon and installed few things on it manually. I am new to packer and i now want to use the previous image as base and create new ami using packer. However i keep on getting error message that my base image does not exists. Here is my packer file

       data "amazon-ami" "cocktails" {
         filters = {
         virtualization-type = "hvm"
         name                = "test-ami-24112022"
         root-device-type    = "ebs"
     }
     owners      = ["my-account-id"]
     most_recent = true
    }

   source "amazon-ebs" "cocktails" {
   instance_type = "t2.micro"
   region        = "eu-west-2"
   ssh_username  = "ec2-user"
   ami_name      = "test-${uuidv4()}"
   source_ami    = data.amazon-ami.cocktails.id
  }

 build {
 sources = ["source.amazon-ebs.cocktails"]
 provisioner "file" {
 source      = "test.txt"
destination = "/home/ec2-user/test.txt"
 }
}

This is the error i am getting

   Datasource.Execute failed: No AMI was found matching filters: {
   Filters: [{
  Name: "root-device-type",
  Values: ["ebs"]
  },{
  Name: "virtualization-type",
  Values: ["hvm"]
},{
  Name: "name",
  Values: ["test-ami-24112022"]
}],
 Owners: ["my-account-id"]
}

 on main.pkr.hcl line 1:
 (source code not available)
srk786
  • 551
  • 3
  • 10
  • 19
  • Is the image shared with your account? – Paolo Nov 24 '22 at 18:58
  • @Paolo i am using same aws account in which i create manual ami, i am using access key and secret key as admin on same account. i am the owner of the account. i logged in using root account to create manual ami. but its not being picked up using packer to then create another image using this ami as base – srk786 Nov 24 '22 at 19:18
  • Oh right. If you created it, and if the packer build is running with sufficient permissions, then your filters must be incorrect – Paolo Nov 24 '22 at 19:20
  • @Paolo i just now edited my code and used ubuntu image with ubuntu owner id and it started to work, so my filters are correct, however i can see on aws console that the ami exists as private, and also i am using correct owner id with correct ami name, but still getting error – srk786 Nov 24 '22 at 19:27

1 Answers1

0

The issue was in my config file of aws. It had some pre loaded data which i used previously and it was pointing to wrong region, when i deleted the config and recreated using correct region it worked

srk786
  • 551
  • 3
  • 10
  • 19