security.tf 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. resource "aws_security_group" "re" {
  2. name = "RedisEnterprise"
  3. description = "Redis Enterprise Security Group"
  4. vpc_id = var.vpc-id
  5. tags = merge({ Name = "RedisEnterprise-${var.vpc-name}" }, var.common-tags)
  6. }
  7. resource "aws_security_group_rule" "internal_rules" {
  8. count = length(var.internal-rules)
  9. type = lookup(var.internal-rules[count.index], "type")
  10. from_port = lookup(var.internal-rules[count.index], "from_port")
  11. to_port = lookup(var.internal-rules[count.index], "to_port")
  12. protocol = lookup(var.internal-rules[count.index], "protocol")
  13. cidr_blocks = [var.vpc-cidr]
  14. security_group_id = aws_security_group.re.id
  15. }
  16. resource "aws_security_group_rule" "external_rules" {
  17. count = length(var.external-rules)
  18. type = lookup(var.external-rules[count.index], "type")
  19. from_port = lookup(var.external-rules[count.index], "from_port")
  20. to_port = lookup(var.external-rules[count.index], "to_port")
  21. protocol = lookup(var.external-rules[count.index], "protocol")
  22. cidr_blocks = lookup(var.external-rules[count.index], "cidr")
  23. security_group_id = aws_security_group.re.id
  24. }
  25. resource "aws_security_group_rule" "open_nets" {
  26. type = "ingress"
  27. from_port = "0"
  28. to_port = "65535"
  29. protocol = "all"
  30. cidr_blocks = var.open-nets
  31. security_group_id = aws_security_group.re.id
  32. }
  33. resource "aws_security_group_rule" "allow_public_ssh" {
  34. count = var.allow-public-ssh
  35. type = "ingress"
  36. from_port = "22"
  37. to_port = "22"
  38. protocol = "all"
  39. cidr_blocks = ["0.0.0.0/0"]
  40. security_group_id = aws_security_group.re.id
  41. }