Skip to content

data aws_instance create list based on resource count query returned no results #10502

Closed as not planned
@DiegoTc

Description

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

Terraform v0.12.10

Affected Resource(s)

*provider.aws v2.32.0

Terraform Configuration Files

resource "aws_instance" "one" {
  instance_type = "${var.lc_instance_type}"
  ami           = "${var.dev_ami}"
  count         = "${var.instance_count}"
  tags = {
    Name = "id"
  }
}

data "aws_instances" "read-ec2" {
  instance_tags= {
    Name = "${var.name_prefix}-id"
  }
}

resource "aws_elb" "loadbalancer" {
  instances = ["${data.aws_instances.read-ec2.ids}"]

  listener {
    ...
  }
}

Debug Output

Error: Your query returned no results. Please change your search criteria and try again.

  on modules/ec2/main.tf line 57, in data "aws_instances" "read-ec2":
  57: data "aws_instances" "read-ec2" {

Panic Output

Expected Behavior

I need to place a list of EC2 instances for the load balancer. Instead of creating instance by instance, I'm using count for the creation. For getting the list of instances created, I'm using data aws_instance, for getting the list of EC2 that were created.

Actual Behavior

At the moment of doing plan/apply I'm getting the error that the query return no results

Steps to Reproduce

Create multiple EC2 instances with the tags above, then execute a data provider to pull back the info.

  1. terraform apply

Important Factoids

References

  • #0000

Metadata

Assignees

No one assigned

    Labels

    service/ec2Issues and PRs that pertain to the ec2 service.service/elbIssues and PRs that pertain to the elb service.staleOld or inactive issues managed by automation, if no further action taken these will get closed.waiting-responseMaintainers are waiting on response from community or contributor.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions