security-groups.tf 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # Rather than pass in the aws security group, we just look it up. This will
  2. # probably be useful other places, as well.
  3. data "aws_security_group" "typical-host" {
  4. name = "typical-host"
  5. vpc_id = var.vpc_id
  6. }
  7. resource "aws_security_group" "instance" {
  8. # use name_prefix instead of name and create-before-destroy on security groups and alb target groups to make future changes easier,
  9. # otherwise, you get stuck in `destroying` during routine changes.
  10. name_prefix = "instance-${var.instance_name}"
  11. description = "Instances of type ${var.instance_name}"
  12. vpc_id = var.vpc_id
  13. tags = merge(var.standard_tags, var.tags)
  14. lifecycle {
  15. create_before_destroy = true
  16. }
  17. }
  18. resource "aws_security_group_rule" "instance-http-in-external" {
  19. description = "Web Interface from External ALB"
  20. type = "ingress"
  21. from_port = "3080"
  22. to_port = "3080"
  23. protocol = "tcp"
  24. source_security_group_id = aws_security_group.alb_server_external.id
  25. security_group_id = aws_security_group.instance.id
  26. }
  27. resource "aws_security_group_rule" "instance-http-in-internal" {
  28. description = "Web Interface from Internal ALB"
  29. type = "ingress"
  30. from_port = "3080"
  31. to_port = "3080"
  32. protocol = "tcp"
  33. source_security_group_id = aws_security_group.alb_server_internal.id
  34. security_group_id = aws_security_group.instance.id
  35. }
  36. resource "aws_security_group_rule" "instance-teleport-in-3023-3026" {
  37. description = "Teleport Proprietary Ports via NLB"
  38. type = "ingress"
  39. from_port = "3023"
  40. to_port = "3026"
  41. protocol = "tcp"
  42. cidr_blocks = [ "0.0.0.0/0" ]
  43. security_group_id = aws_security_group.instance.id
  44. }
  45. #resource "aws_security_group_rule" "instance-teleport-in-3026" {
  46. # description = "Teleport Proprietary Ports via NLB"
  47. # type = "ingress"
  48. # from_port = "3026"
  49. # to_port = "3026"
  50. # protocol = "tcp"
  51. # cidr_blocks = [ "0.0.0.0/0" ]
  52. # security_group_id = aws_security_group.instance.id
  53. #}
  54. #resource "aws_security_group_rule" "instance-teleport-proxy-in" {
  55. # description = "Teleport - Proxy web server"
  56. # type = "ingress"
  57. # from_port = "3080"
  58. # to_port = "3080"
  59. # protocol = "tcp"
  60. # cidr_blocks = [ "0.0.0.0/0" ]
  61. # security_group_id = aws_security_group.instance.id
  62. #}
  63. resource "aws_security_group_rule" "instance-teleport-out-ssh" {
  64. description = "Outbound SSH"
  65. type = "egress"
  66. from_port = "22"
  67. to_port = "22"
  68. protocol = "tcp"
  69. cidr_blocks = [ "0.0.0.0/0" ]
  70. security_group_id = aws_security_group.instance.id
  71. }
  72. resource "aws_security_group_rule" "instance-teleport-out-teleport" {
  73. description = "Outbound teleport"
  74. type = "egress"
  75. from_port = "3022"
  76. to_port = "3026"
  77. protocol = "tcp"
  78. cidr_blocks = [ "0.0.0.0/0" ]
  79. security_group_id = aws_security_group.instance.id
  80. }
  81. resource "aws_security_group_rule" "instance-teleport-out-https" {
  82. description = "Outbound HTTPS, required for dynamodb Streams (no vpc endpoint available)"
  83. type = "egress"
  84. from_port = "443"
  85. to_port = "443"
  86. protocol = "tcp"
  87. cidr_blocks = [ "0.0.0.0/0" ]
  88. security_group_id = aws_security_group.instance.id
  89. }