skip to Main Content

I have the following code in Terraform. The issue is the image no longer exits and it’s failing to build.

data "aws_ami" "ami_ai_demos" {
  most_recent = true
  filter {
    name   = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-20200323"]
  }
  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }
  owners = ["099720109477"]
}

I could update values with the current image but do not want to rebuild the image. Is there anyway to work around this issue?

3

Answers


  1. It was most probably deprecated thus not searchable anymore. Just use direct ami ID for your region instead of filters.
    https://cloud-images.ubuntu.com/locator/

    cloud-images.ubuntu.com

    Login or Signup to reply.
  2. Thank you for the suggestions. As my requirements are that the EC2 instance is not rebuilt, I will have to remove it from Terraform state. This makes sense as so long as Terraform see’s it it’ll want to act on the resource.

    https://www.terraform.io/cli/commands/state/rm

    Login or Signup to reply.
  3. The better option would be to use like this, as this will always pick up the latest image avalaible and your build will not fail.

    data "aws_ami" "ubuntu" {
    most_recent = true
      owners      = ["099720109477"]
      filter {
        name   = "name"
        values = ["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"]
      }
      filter {
        name   = "root-device-type"
        values = ["ebs"]
      }
      filter {
        name   = "virtualization-type"
        values = ["hvm"]
      }
      filter {
        name   = "architecture"
        values = ["x86_64"]
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search