Quantcast
Channel: Terraform - HashiCorp Discuss
Viewing all articles
Browse latest Browse all 11533

Using for_each inside Data Source (aws_instance and aws_instances)

$
0
0

Hi,
In the Terraform documentation I found a data source called aws_ebs_volumes and in the example they use aws_ebs_volume data source too (code below)

`data "aws_ebs_volumes" "example" {
   tags = {
     VolumeSet = "TestVolumeSet"
    }
  }

data "aws_ebs_volume" "example" {
  for_each = data.aws_ebs_volumes.example.ids
  filter {
    name   = "volume-id"
    values = [each.value]
  }
}`

The question is, can I do the same with aws_instances and aws_instance ? I have the following code

`#return all the instances that fill the paramenters (filters)
data "aws_instances" "get_instances" {
    filter {
        name = "instance-type"
        values = ["t2.micro"]
    }

filter {
    name = "availability-zone"
    values = ["sa-east-1a"]
}

instance_state_names = ["running", "stopped"]
}

#return the data of one specific insntace
data "aws_instance" "get_specific_instance" {
    for_each = "${data.aws_instances.get_instances.ids}"

   filter {
    name = "tag:Name"
    values = ["PocTerraform", "Application"]
  }
}`

but it doesn’t work, is it just syntax errors or it’s not possible to do it?
Thanks in advance

3 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 11533

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>