Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions modules/single-port-sg-src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Single Port Security Group Rule

Create an `aws_security_group_rule` to allow ingress on some port.
67 changes: 67 additions & 0 deletions modules/single-port-sg-src/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* ## Single Port Security Group Rule
*
* Create an `aws_security_group_rule` to allow ingress on some port.
*
*/

variable "security_group_id" {
description = "security group to attach the ingress rules to"
type = string
}

variable "source_security_group_id" {
description = "The SG that this SG allows ingress from"
type = string
}

variable "description" {
description = "Use this string to add a description for the SG rule"
type = string
}

variable "port" {
description = "The port to open"
type = string
}

variable "tcp" {
description = "true/false to enables the tcp ingress"
default = "true"
type = string
}

variable "udp" {
description = "true/false to enables the udp ingress"
default = "false"
type = string
}

locals {
tcp = "${var.tcp ? 1 : 0}"
udp = "${var.udp ? 1 : 0}"
}

# ingress rule for tcp, if enabled
resource "aws_security_group_rule" "tcp_ingress" {
count = local.tcp
type = "ingress"
description = "${var.description} (tcp)"
from_port = var.port
to_port = var.port
protocol = "tcp"
security_group_id = var.security_group_id
source_security_group_id = var.source_security_group_id
}

# ingress rule for udp, if enabled
resource "aws_security_group_rule" "udp_ingress" {
count = local.udp
type = "ingress"
description = "${var.description} (udp)"
from_port = var.port
to_port = var.port
protocol = "udp"
security_group_id = var.security_group_id
source_security_group_id = var.source_security_group_id
}
4 changes: 4 additions & 0 deletions modules/single-port-sg-src/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

terraform {
required_version = ">= 0.12"
}
2 changes: 0 additions & 2 deletions modules/single-port-sg/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
## Single Port Security Group Rule

Create an `aws_security_group_rule` to allow ingress on some port.

TODO: support both TCP and UDP, use count to enable/disable.
2 changes: 0 additions & 2 deletions modules/single-port-sg/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
*
* Create an `aws_security_group_rule` to allow ingress on some port.
*
* TODO: support both TCP and UDP, use count to enable/disable.
*
*/

variable "security_group_id" {
Expand Down