是否有一种方法来排序aws_ami最老的而不是最新的?



现在我正在做这个:

data "aws_ami" "windows-image" {
most_recent = true
filter {
name   = "name"
values = ["Windows_Server-2019-English-Full-Base-*"]
}
owners = ["amazon"]
}

但是我想尝试一些过时的ami。没有oldest参数。如果我能得到aws_ami返回一个列表,我想我可以在上面使用reverse(),但似乎我需要做过滤,否则我得到这个错误:

Error: Your query returned more than one result. Please try a more specific search criteria, or set `most_recent` attribute to true.

我刚刚看到有一个单独的资源用于获取id的列表

data "aws_ami_ids" "windows-image" {
sort_ascending = true // sort by oldest to newest
filter {
name   = "name"
values = ["Windows_Server-2019-English-Full-Base-*"]
}
owners = ["amazon"]
}
output "test" {
value = data.aws_ami_ids.windows-image.ids[0]
}

最新更新