My EBS volumes are already created outside of my module. Whenever I try to use the ebs_volumes data source to look them up I get the following:
The “for_each” value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created. To work around this, use the -target argument to first apply only the resources that the for_each depends on.
If your EBS volumes are created outside the module, but within the same configuration, then no the configuration it not technically valid. In that case the values from the actual aws_ebs_volume resources should be passed directly into the module.
A good rule of thumb is that a logical resource should not be represented by both a managed resource and a data source within the same configuration.
Thanks what do you mean by the same configuration ? Our use case is that we need to find all of the ebs volumes currently present in an account and then get the kms key ids for those. This is to enable this for encrypted volumes; Design considerations - AWS Instance Scheduler
So if I run my module config today I might find 20 volumes & if I then run it tomorrow I might find 30 columns so there is a delta that needs to be updated in the AWS instance scheduler.
All of the EBS volumes are managed elsewhere in a different Terraform state along with the EC2 instances that own them.
Here “within the same configuration” is what you are referring to as a Terraform state. In that case the configuration should work as expected, and you have something else interfering with the data source’s ability to be read during planning. Can you show an example of how you have structured your module, and how you are calling it?