# How to specify what block I want to use in Terraform

**URL:** <https://discuss.hashicorp.com/t/how-to-specify-what-block-i-want-to-use-in-terraform/23099>\
**Category:** Terraform\
**Created:** [April 13, 2021, 5:01pm UTC](https://discuss.hashicorp.com/t/how-to-specify-what-block-i-want-to-use-in-terraform/23099 "2021-04-13T17:01:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lotarcc](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/lotarcc/32/18595_2.png) [@Lotarcc](https://discuss.hashicorp.com/u/Lotarcc)\
**Post date:** [April 13, 2021, 5:01pm UTC](https://discuss.hashicorp.com/t/how-to-specify-what-block-i-want-to-use-in-terraform/23099/1 "2021-04-13T17:01:13Z")

</div>

I have this Code in Terraform. And I have the outputs.tf. I have assigned variables like os\_family in my terraform.tfvars but whenever I do apply it’s just dropping cause of `Query returned no results` I think that’s because it’s trying to query both things. How Can I specify to use the Ubuntu part instead of the RHEL part if I want to install Ubuntu and vice versa for the RHEL? Cause my way is definitely not working. Thank you.

**Main.tf**

```
data "aws_ami" "ubuntu" {
  most_recent = true

  filter {
    name = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-*-${var.os_version}*amd64*"]
  }

  filter {
    name = "virtualization-type"
    values = ["hvm"]
  }

  owners = ["REDACTED"]
}

data "aws_ami" "rhel" {
  most_recent = true

  filter {
    name = "name"
    values = ["RHEL-${var.os_version}*GA*x86_64*"]
  }

  filter {
    name = "virtualization-type"
    values = ["hvm"]
  }

  owners = ["REDACTED"]
}

```

**outputs.tf**

```
output "image_id" {
  value = var.os_family == "rhel" ? data.aws_ami.rhel.id : data.aws_ami.ubuntu.id
}
```
