# This data sourec will fetch latest amazon linux AMI image
data "aws_ami" "amzlinux" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["amzn2-ami-hvm-*"]
}
filter {
name = "root-device-type"
values = ["ebs"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
filter {
name = "architecture"
values = ["x86_64"]
}
}
resource "aws_instance" "web" {
ami = data.aws_ami.amzlinux.id
instance_type = "t1.micro"
}
data "aws_instances" "test" {
instance_tags = {
Name = "Dev"
}
filter {
name = "instance.group-id"
values = ["sg-12345678"]
}
instance_state_names = ["running", "stopped"]
}
resource "aws_eip" "test" {
count = length(data.aws_instances.test.ids)
instance = data.aws_instances.test.ids[count.index]
}