security-group.tf 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # The Magic Machine is dependent on this Security Group
  2. data "aws_vpc" "this" {
  3. id = var.vpc_id
  4. }
  5. data "aws_subnet" "this" {
  6. id = var.public_subnets[0]
  7. }
  8. #----------------------------------------------------------------------------
  9. # LCP Magic Machine Security Group
  10. #----------------------------------------------------------------------------
  11. resource "aws_security_group" "this" {
  12. # checkov:skip=CKV2_AWS_5: this SG is attached to Magic Machine
  13. name = "${var.name}_magic_machine_security_group"
  14. description = "Security Group for magic machine ${var.name}"
  15. tags = merge(local.standard_tags, var.tags)
  16. vpc_id = data.aws_vpc.this.id
  17. }
  18. #----------------------------------------------------------------------------
  19. # INGRESS
  20. #----------------------------------------------------------------------------
  21. resource "aws_security_group_rule" "this" {
  22. type = "ingress"
  23. description = "Allows Codebuild to access Magic Machine and for troubleshooting"
  24. cidr_blocks = ["10.0.0.0/8"]
  25. from_port = 22
  26. to_port = 22
  27. protocol = "tcp"
  28. security_group_id = aws_security_group.this.id
  29. }
  30. #----------------------------------------------------------------------------
  31. # EGRESS
  32. #----------------------------------------------------------------------------
  33. resource "aws_security_group_rule" "allow_outbound_mm" {
  34. type = "egress"
  35. description = "HTTPS - Outbound - Allow Magic Machine"
  36. cidr_blocks = ["0.0.0.0/0"] # tfsec:ignore:aws-vpc-no-public-egress-sgr
  37. from_port = 443
  38. to_port = 443
  39. protocol = "tcp"
  40. security_group_id = aws_security_group.this.id
  41. }
  42. #----------------------------------------------------------------------------
  43. # Codebuild Security Group
  44. #----------------------------------------------------------------------------
  45. resource "aws_security_group" "codebuild" {
  46. # checkov:skip=CKV2_AWS_5: this SG is attached to Codebuild
  47. name = "${var.name}_codebuild_security_group"
  48. description = "Security Group for codebuild ${var.name}"
  49. tags = merge(local.standard_tags, var.tags)
  50. vpc_id = data.aws_vpc.this.id
  51. }
  52. #----------------------------------------------------------------------------
  53. # EGRESS
  54. #----------------------------------------------------------------------------
  55. resource "aws_security_group_rule" "allow_outbound" {
  56. type = "egress"
  57. description = "HTTPS - Outbound - Allow Codebuild"
  58. cidr_blocks = ["0.0.0.0/0"] # tfsec:ignore:aws-vpc-no-public-egress-sgr
  59. from_port = 443
  60. to_port = 443
  61. protocol = "tcp"
  62. security_group_id = aws_security_group.codebuild.id
  63. }
  64. resource "aws_security_group_rule" "allow_ssh_outbound" {
  65. type = "egress"
  66. description = "SSH - Outbound - Allow Codebuild"
  67. cidr_blocks = ["10.0.0.0/8"]
  68. from_port = 22
  69. to_port = 22
  70. protocol = "tcp"
  71. security_group_id = aws_security_group.codebuild.id
  72. }