This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a fork version of single-port-sg module to support source_security_group.
- Loading branch information
Showing
5 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" { | ||
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 = var.source_security_group | ||
} | ||
|
||
# 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 = var.source_security_group | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
terraform { | ||
required_version = ">= 0.12" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters