Hi,
I’m using aws_ebs_volume to create volume and aws_volume_attachment to attach it.
Everytime I execute “terraform apply” the volume tags keep on rotating (veggies name - below is just a snippet out of the code I am executing)!
Can you share an example terraform plan output showing Terraform proposing a change that won’t converge? I’m not sure from this example how exactly the tags could fail to converge here because it seems to depend only on count.index and that’s fixed as part of each instance’s address. I think something else must be happening that I’m not considering, and seeing some real plan output would hopefully help me to understand what that is.
I think this is happening because there is a contradiction in your configuration: the aws_instance.fruits_node resource says that all of the volumes of this instance should be tagged with the name including “root”, but the aws_ebs_volume resources specify different tags that don’t match that rule. Because of the dependency ordering of the operations, on a single run Terraform will first create the EC2 instance with its root volume only and tag it, and then separately create the other volumes and attach them. But then on the next run, the aws_instance implementation notices that some of the volumes don’t match and so it produces a plan to fix that.
I must admit I’m not very familiar with these particular features of the AWS provider, so I’m not sure if there is a way to tell the provider that the volume_tags are only intended for the root_block_device and should not also be applied to the other volumes that were attached later. Since this seems to be an AWS provider behavior thing, I’m going to move this topic over to the AWS provider’s category in the hope that someone there will have more direct experience with these features and will be able to make some suggestions about how to avoid this problem.
I see an old issue in the provider’s repository that seems like it might be related to what you are describing:
That issue seemed to be resolved by adding a new tags argument you can set insideroot_block_device to specify tags only for that one device, which seems like it might help with the situation you’re describing, but I don’t have any direct experience with it so I’m not sure if there are caveats with that I’m not considering.