Terraform, AWS AMI and the DeprecationTime attribute
This post covers deprecated AMIs in case you are not familiar with that.
I’m running through a lab that I plan to present at F5 AppWorld 2024. The lab uses Terraform to deploy F5 BIG-IP VE’s, among other things.
Things worked fine when I tested this lab a few weeks ago. Now my automation is failing!
The problem
Here’s an excerpt of the Terraform configuration that is now failing:
My terraform.tfvars file:
My ami-search.tf file:
However, when I run terraform plan
I get the error message:
1
2
3
4
5
│ Error: Your query returned no results. Please change your search criteria and try again.
│
│ with data.aws_ami.bigip,
│ on ami-search.tf line 3, in data "aws_ami" "bigip":
│ 3: data "aws_ami" "bigip" {
Why is Terraform not finding the AMI?
I know that an AMI (ami-056a053acf172f5b8
) does exist that matches this search criteria. It has a name attribute of F5 BIGIP-17.1.0.1-0.0.4 PAYG-Adv WAF Plus 25Mbps-230407095221-3c272b55-0405-4478-a772-d0402ccf13f9
I can find it with the AWS CLI:
Searching for deprecated AMI’s
I tried a few things, including searching for the AMI ID specifically in Terraform like this, to no avail:
Then I realized that the DeprecationTime
attribute was now in the past. I quickly found the Terraform documentation and learned I could add include_deprecated = true
to have deprecated AMIs found by Terraform.
Now, this Terraform code is doing what I expect (see line 7 below):
1
2
3
4
5
6
7
8
9
data "aws_ami" "bigip" {
most_recent = true
filter {
name = "name"
values = [var.f5_ami_search_name]
}
include_deprecated = true
owners = ["aws-marketplace"]
}