Terraform error Reference to “count” in non-counted context for resources not necessarily data here's my part of my code that I am having issues with. Unfortunately I could not understand the relationship between the last answer, despite being almost what I need, and my situation.

data "aws_internet_gateway" "zyz_igw" {
  depends_on = [aws_internet_gateway.this]

    filter {
    name   = "attachment.vpc-id"
    values = aws_vpc.this[count.index]
    #values = [aws_vpc.this[count.index]]   #based on https://www.terraform.io/docs/providers/oci/guides/filters.html
  }

  filter {
    name   = "tag:Name"
    values = ["ZYZ_Mirror_ZYZ-tp-zyz-IGW"]
  }
}


The error I am getting is the following:

Error: Reference to "count" in non-counted context

  on modules/xyz/main.tf line 292, in data "aws_internet_gateway" "zyz_igw":
 292:     values = aws_vpc.this[count.index]

The "count" object can be used only in "resource" and "data" blocks, and only
when the "count" argument is set.


I get confused since I believe my issue may be with the resource and not sure how to change the data. I also saw something related to 'for_each' to use that instead of 'count' on 0.12. But the in the very beginning of my code I have the normal 'aws_vpc' resource:

resource "aws_vpc" "this" {
  count = var.zyz_create_vpc ? 1 : 0
looks like your new to stack exchange. You need to form a clearer question to get a good answer.... 

As far as your error goes.... count is a reserved name. It's only accessible when the block you're writing has a count set! 

You have You just need to specify the count of aws_internet_gateway data resources you're trying to get. Your code implies there is more than one.

data "aws_internet_gateway" "zyz_igw" {
   count = 1000000000
   ...