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.