Error: Invalid index

Hi,

Actually I have this problem, to execute terraform plan, and I not have idea to solve, I review all configurations and is correct and the code I not have problems, is desesperating beucause not exists more information for this problems.

Any idea to solve, please?? and Thank you for helm me.


Error: Invalid index

on .terraform/modules/eks/terraform-aws-modules-terraform-aws-eks-1be1a02/cluster.tf line 52, in resource “aws_security_group_rule” “cluster_egress_internet”:
52: security_group_id = aws_security_group.cluster[0].id
|----------------
| aws_security_group.cluster is empty tuple

The given key does not identify an element in this collection value.


It means that there is nothing in the aws_security_group.cluster[0] variable, because it’s not been created, and so there is no id attribute.
Probably because you’re missing a parameter in the call to the module, so check the variables defined inside it.
Is it a module you wrote yourself?

I had similar issue and for me I was working in test environment. So I did a complete cleanup:

  1. Deleted the .terraform folder
  2. Deleted the S3 state file
  3. Delete the DynamoDB state lock record.

Then did terraform init and terraform plan and it finally worked for me.

For me the issue was that I changed the state file and the dynamoDB record which was probably causing the issue.