Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional EBS volumes are re-attached when an instance is recreated #116

Closed
BernhardBerbuir opened this issue Jul 29, 2019 · 3 comments
Closed

Comments

@BernhardBerbuir
Copy link

When tainting an EC2 Instance which belongs to a group of instances with externally attached volumes then all externally attached volumes are re-attached.

How to reproduce:

  • create multiple EC2 instances with this module
  • create for each instance an additional EBS volume and an attachment (see comment )
  • taint one of the instances
  • execute terraform apply

As a result Terraform re-creates the volume attachments for all instances

aws_volume_attachment.data[0] must be replaced
-/+ resource "aws_volume_attachment" "data" {
...
  instance_id = "i-09223024b168b857c" -> (known after apply) # forces replacement
...
aws_volume_attachment.data[1] must be replaced
-/+ resource "aws_volume_attachment" "data" {
...
  instance_id = "i-07144ca24f14bc773" -> (known after apply) # forces replacement
...

I assume that this happens because the additional EBS volumes are created and attached outside of the module.
I could create a pull request which creates aws_ebs_volume and aws_volume_attachment inside the module, if it's ok.

@BernhardBerbuir
Copy link
Author

I have done some further analysis of the bug.
The statefile contains the ebs_block_device two times:

  1. there are separate aws_ebs_volume and aws_volume_attachment (as expected)
  2. each aws_instance contains also an ebs_block_device (instead of an empty array)

=> the aws_instance "hijacks" the separately created and attached ebs_block_device.

@antonbabenko
Copy link
Member

@BernhardBerbuir I think you can try to use for_each instead of count for this situation and loop through ids instead of count indexes. This will solve half of the issues you are describing.

Check this for more details - https://www.terraform.io/docs/configuration/resources.html#when-to-use-for_each-instead-of-count

Unfortunately, it is not possible to specify variables inside ignore_changes, so we can't have ebs_block_device ignored for some but not for all.

There is nothing we can do in the module, so I am closing this issue.

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants