1
Error: Invalid index

  on .terraform/modules/database-security-group/main.tf line 70, in resource "aws_security_group_rule" "ingress_rules":
  70:   to_port   = var.rules[var.ingress_rules[count.index]][1]
    |----------------
    | count.index is 0
    | var.ingress_rules is list of string with 1 element
    | var.rules is map of list of string with 119 elements

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

.


It's all Greek to me. We could use the help..

module "database-security-group" {
  source = "terraform-aws-modules/security-group/aws"
  name        = "database-security"
  description = "Security group for Database on database subnet."
  vpc_id      = module.vpc.vpc_id
  ingress_cidr_blocks = ["0.0.0.0/0"]
  ingress_rules       = [ "http-3306-tcp"]
  egress_rules        = ["all-all"]
  tags = {
    Name        = "Database"
    Environment = "spoon"
  }
}
loanshark
  • 105
  • 2
  • 8
  • You probably need to file a bug with the third-party Terraform module you are using: https://github.com/terraform-aws-modules/terraform-aws-security-group/issues or dig into the source to figure out what the issue is. Or you could save yourself a lot of time by just creating the security group yourself instead of using this module. I don't see the value in using a module like this to perform such a small task, especially if it has bugs. – Mark B Oct 18 '20 at 15:05

1 Answers1

0

I believe the intention of this particular module is that you select from its table of predefined rules when specifying ingress_rules and egress_rules.

At the time I write this I don't see a definition for a rule "http-3306-tcp", and so I think that's the cause of your error. If your intent was to allow TCP port 3306 for MySQL then it seems the rule key for that is "mysql-tcp".

Martin Atkins
  • 62,420
  • 8
  • 120
  • 138