i’m using version 0.14.8. any idea on how to get the aws_ami datasource to dynamically filter with a list or map? this is what i have below but does not work.
variable “filter-tags” {
type = map
}
data “aws_ami” “db_ami” {
most_recent = true
owners = [“self”]
dynamic “filter” {
for_each = var.filter-tags
content {
name = tag.key
values = tag.value
}
}
terraform plan
Error: Invalid value for module argument
on main.tf line 38, in module “ec2_cluster”:
38: filter-tags = {
39: “tag:os” = [“ubuntu”]
40: “tag:release” = [“bionic”]
41: “tag:Team” = [“dba”]
42: “tag:purpose” = [“goodpurpose”]
43: }
The given value is not suitable for child module variable “filter-tags”
defined at …/…/…/modules/services/elastic-cluster/variables.tf:142,1-23:
element “tag:release”: string required.
now i have it to where it’s saying " Your query returned no results." and errors out. if i uncomment the hard coded lines, it works fine. I just want to dynamically create them so that I can modularize my terraform scripts.
variable "filter_tags" {
description = "Custom tags to set on the Instances in the ASG"
type = map(string)
default = {
"os" = "ubuntu"
"release" = "bionic"
"Team" = "dba"
"purpose" = "GoodPurpose"
}
dynamic "filter" {
for_each = var.filter_tags
iterator = tag
content {
name = "tag:${tag.key}"
values = ["tag.value"]
}
}
#filter {
# name = "tag:os"
# values = ["ubuntu"]
#}
#filter {
# name = "tag:release"
# values = ["bionic"]
#}
#filter {
# name = "tag:Team"
# values = ["dba"]
#}
#filter {
# name = "tag:purpose"
# values = ["GoodPurpose"]
#}
}
terraform plan
Error: Your query returned no results. Please change your search criteria and try again.
on ../../../modules/services/elastic-cluster/main.tf line 6, in data "aws_ami" "db_ami":
6: data "aws_ami" "db_ami" {
never mind, tag value was off so error was correct.