I have created a few data blocks for finding the right AMIs. I have 4 data blocks to find 4 AMIs based 4 os. Example,
data "aws_ami" "centos" {
owners = ["123456789"]
most_recent = true
filter {
name = "name"
values = ["CentOS*${var.os-version}*x86_64"]
}
}
data "aws_ami" "suse" {
owners = ["amazon"]
most_recent = true
filter {
name = "name"
values = ["suse-sles-${var.os-version}-sp*-v????????-hvm-ssd-x86_64"]
}
}
I call them like the following ami_id=data.${os_name}.image-id
So what I want is to run only the data block that has been called. If the user chooses "suse" then only the suse data block will run. Not all of them. It's an issue right now because users choose versions based on the os. For example, 16.04 only works for ubuntu not any other so the other data block throws exception like the following,
Error: Your query returned no results. Please change your search criteria and try again.
on main.tf line 79, in data "aws_ami" "suse":
79: data "aws_ami" "suse" {
So how can I achieve it?