# module.aws_us_west_2.data.aws_availability_zones.available will be read during apply
# (depends on a resource or a module with changes pending)
<= data "aws_availability_zones" "available" {
+ group_names = (known after apply)
+ id = (known after apply)
+ names = (known after apply)
+ zone_ids = (known after apply)
}
My code has this
data "aws_availability_zones" "available" {}
I can’t touch the zone, it’s owned by AWS. So what could possibly convince terraform that it depends on one of my resources or modules? Let alone that they could change it in some way?
Because of this of course it wasn’t to replace a bunch of things that use the zone name in their name.
# module.aws_us_west_2.data.aws_availability_zones.available will be read during apply
# (depends on a resource or a module with changes pending)
You haven’t supplied the configuration which is needed to see why, but you have made the data source depend on a managed resource with changes, which means the data source cannot be read until after those changes have been applied.
Can you show an example of the config that causes this?
I am not sure what you mean by the config. Google wasn’t much help either. What information are you looking for?
Also… you said “you have made the data source depend a managed resource with changes”. The only way I can think of to do that for a read only resource like that would be to have a filter on the data directive that is derived from another resource. But I don’t have anything like that. So I am still confused on how it thinks that I did.
“config” here would mean enough of your terraform configuration to piece together all of the dependencies related to the data source in question.
Since the data source block itself doesn’t contain any references, and the data source is located at module.aws_us_west_2.data.aws_availability_zones, my next guess would be that you have a depends_on in the aws_us_west_2 module call, which indirectly applies that dependency to the data source (and everything else) it contains.
So that would be a lot of code. But help me understand what you are saying. I get that we have resources which use the name of the availability zone in their name, and so if the az data source were to change, those resources that depend on it would need to be updated or recreated. But that doesn’t explain why terraform thinks the AZ data source is going to change. The data object clearly has no explicit depends_on, and an empty block so it isn’t depending on something to get text to use as a filter. It should essentially be parent-less. The resource itself is also read-only, so it can’t change. Yet terraform is saying depends on a resource or a module with changes pending
Seems like you might be saying, that because the data source is in a module. If that module specifically depends on something else, terraform just assumed that everything in the module now depends on whatever the module depends on. So the fix would be to move the data source to the top of the state, and pass it down?
If that module specifically depends on something else, terraform just assumed that everything in the module now depends on whatever the module depends on
Terraform doesn’t assume anything here Putting depends_on in a module call explicitly states “everything in this module depends on these things”.
You could move the data source outside of the module, but there is never a reason you need depends_on in a module call, and it’s a mistake to use it in many cases. It would be better to remove the depends_on and make sure the data flow represents the necessary dependencies. If there is something in the module which has an out-of-band dependency on something outside of the module, you can pass in the data from the dependency and set depends_on directly in the resource which requires it.
Well, not all the resources in the module depend on things from the dependency. The this one, the az. It doesn’t depend on anything. It is just needed in the module, so that is where the data object is.
As for the module depends on. The top level is calling several modules. And the depends_on is to make sure they happen in the right order. We already pass in a variety of values to the module, and inside various resources use those values to figure out their values. So it sounds like you are saying that terraform would figure out the order without the depends_on due to the inputs? so there is no reason to have it on the module?
Yes, Terraform determines the order of operations by the references between all the configuration objects (depends_on is not doing anything other than creating an artificial reference). There is no need to use depends_on unless you have resources which have a real-world dependency but no way to create a natural reference between them in the configuration.