What Terraform is telling you, is that it feels a need to make a change to the availability_zone of the volumes, and that is why it wants to recreate them.
I don’t know enough about AWS, or other objects referenced in your setup, to be able to tell if it’s right to do this according to what you have written, or if it’s a bug in the provider’s import support.
I do find it odd that the “forces replacement” attribute is also “known after apply”, not a specific concrete value.
Ah I think I see the problem - thats evaluating to some nulls, not actual AZ names. Fix that, by specifying the correct AZ names directly, and see how Terraform’s plan changes.
Please bear in mind that I have very little experience with AWS… but to me, reading the terraform-provider-aws documentation, it suggests this data source’s availability_zone parameter may be for input filtering only, and may not be usable to query the AZ of a subnet.
It turned out that ignore_changes has worked around the issue. However it still doesn’t make sense to me because the AZ didn’t change.
What if AZ needs to be changed in other cases?
I agree that ignore_changes seems more a workaround than a solution here, but I’m also having trouble following all of the indirection through references in your configuration to get a good sense of how the data is flowing.
Can you see in the terraform show output which availability zone each of these objects currently belongs to, and confirm whether they all seem correct? That would at least eliminate the possibility that the imported data was somehow incorrect or inconsistent, and suggest that there is a bug in your configuration instead.
The only other immediate note I have is that further up the discussion you mentioned using data "aws_subnet" "backend" to read in some information about the subnet that each of your instances is connected to. If all you needed from that was the availability zone you might find it helpful to know that aws_instance has its own availability_zone attribute which reports the AZ the instance is running in, so you shouldn’t need to look up that particular value indirectly via the subnet.
Like I posted above, the AZ of module.knox-cms.aws_ebs_volume.backend-logs[0] didn’t change, and it’s still us-west-2a. module.knox-cms.aws_ebs_volume.backend-logs[1] is in us-west-2b.
Regarding data.aws_subnet, if I don’t use data.aws_subnet.backend, what should I replace element(data.aws_subnet.backend.*.availability_zone, count.index) with?
Is that element(aws_instance.backend.*.availability_zone, count.index)?