target_groups optional param is not optional : terraform

113 views Asked by At
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"
  }
}
1

There are 1 answers

0
Martin Atkins On BEST ANSWER

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".