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

Setting ebs_volume_count to more than 1 results in terraform error #48

Open
gsefanof opened this issue Mar 11, 2023 · 0 comments
Open
Labels
bug 🐛 An issue with the system

Comments

@gsefanof
Copy link

Found a bug? Maybe our Slack Community can help.

Describe the Bug

When set ebs_volume_count = 2 (more than 1), it will result in terraform error

╷
│ Error: Invalid index
│ 
│   on modules/cp-ec2-group/main.tf line 163, in resource "aws_volume_attachment" "default":
│  163:   instance_id = aws_instance.default.*.id[count.index]
│     ├────────────────
│     │ aws_instance.default is tuple with 1 element
│     │ count.index is 1
│ 
│ The given key does not identify an element in this collection value: the given index is greater than or equal to the length of the collection.

Expected Behavior

Create and attach two additional ebs volumes

Steps to Reproduce

for example

module "instance" {
  source = "./modules/cp-ec2-group"

  namespace                   = "eg"
  stage                       = "prod"
  name                        = "app"
  ami                         = "ami-a4dc46db"
  ami_owner                   = "099720109477"
  ssh_key_pair                = var.ssh_key_pair
  instance_type               = var.instance_type
  vpc_id                      = var.vpc_id
  security_groups             = var.security_groups
  subnet                      = var.subnet
  instance_count              = 3
  ebs_volume_count            = 2
}

Environment (please complete the following information):

  • OS: Linux, Mint 20.3, 5.4.0-139-generic
  • Terraform v1.3.7

Additional Context

Could be solved by replace string in main.tf, at line 162.
e.g.:
instance_id = element(aws_instance.default.*.id, floor(count.index / max(var.ebs_volume_count, 1)))

p.s.
there is a limitation, changing the number of EBS will lead to reattaching disks to different instances

@gsefanof gsefanof added the bug 🐛 An issue with the system label Mar 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An issue with the system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant