How to find aws ami name's value?

Create infrastructure | Terraform | HashiCorp Developer :

provider "aws" {
  region = "us-west-2"
}

data "aws_ami" "ubuntu" {
  most_recent = true

  filter {
    name = "name"
    values = ["ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-*"]
  }

  owners = ["099720109477"] # Canonical
}

resource "aws_instance" "app_server" {
  ami           = data.aws_ami.ubuntu.id
  instance_type = "t2.micro"

  tags = {
    Name = "learn-terraform"
  }
}

how to find this value: “ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-*”? I have search google, ubuntu, amazon website, I can not find it. oh my god.

What value are you trying to find? The AMI name or a general pattern of certain set of images?

Typically you’d need to do a bit of reverse engineering to find the name. One way is to look up the AMI ID of an image in the AWS Management Console. For example, here’s the AMI ID for Ubuntu 24.04 LTS x86 in us-west-2:

Then you can run an AWS CLI command, specifically aws ec2 describe-images to get the name of the AMI. For example:

$ aws ec2 describe-images --image-ids ami-05f991c49d264708f --query "Images[0].Name" --output text

ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-20250610

Based on the AMI name, you can probably deduce the pattern which is used with a wildcard in the Terraform configuration to get the latest version AMI in the tutorial. As a side note, there is another official way of looking up Ubuntu AMI IDs documented at Find Ubuntu images on AWS - Ubuntu on AWS documentation.

You can try the method above with another OS image (e.g. Windows) and see if can get it working.

I am still having trouble understanding your question…

The string ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-* is just a literal string that’s used as a search value for an Ubuntu AMI in the aws_ami data source. There’s no “value” to the string other than the string itself. Unless you can ask your question in a different way, I can only guess that you might mean the following two scenarios:


If you want to reference the argument value within the data.aws_ami.ubuntu data source, it would be something like:

tolist(tolist(data.aws_ami.ubuntu.filter)[0].values)[0].

The tolist function is needed because filter and values are sets which technically don’t allow you to refer to values by indices.

That said, I don’t really see any practical use of this value, since you already know what string you are using (that’s why you are hardcoding it in the configuration). If you need to refer to the string in different places, perhaps externalizing it as a variable would make more sense?

variable "ami_search_string" {
  type    = string
  default = "ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-*"
}

data "aws_ami" "ubuntu" {
  most_recent = true

  filter {
    name   = "name"
    values = [var.ami_search_string]
  }

  owners = ["099720109477"] # Canonical
}

If you want to get the AMI name of the data.aws_ami.ubuntu data source after it’s read from the matching AMI in AWS, then it’s simply:

data.aws_ami.ubuntu.name

However, the name value would not be the same wildcard string ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-* in the Terraform configuration. The data source resolves to an actual AMI (the latest version of the Ubuntu AMI matching the specs) with a actual, canonical name. With the data source, you are effectively saying search for any AMIs with a name that matches the wildcard ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-*, but pick the latest one if there are multiple AMIs returned.

The value of the name attribute would thus be something like:

ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-20250627


In my original response I’ve provided information on the only other scenario where you are just trying to figure out what search string/value to use when looking up an arbitrary AMI.

Given the (now deleted) response, this is possibly a phishing attempt; going to lock this thread. Thanks for the detailed response, @acwwat.