Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit b2032c1

Browse files
Magicloudketzacoatl
authored andcommitted
New module single-port-sg-src
This is a fork version of single-port-sg module to support source_security_group.
1 parent 6568da4 commit b2032c1

File tree

5 files changed

+74
-4
lines changed

5 files changed

+74
-4
lines changed

modules/single-port-sg-src/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Single Port Security Group Rule
2+
3+
Create an `aws_security_group_rule` to allow ingress on some port.

modules/single-port-sg-src/main.tf

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* ## Single Port Security Group Rule
3+
*
4+
* Create an `aws_security_group_rule` to allow ingress on some port.
5+
*
6+
*/
7+
8+
variable "security_group_id" {
9+
description = "security group to attach the ingress rules to"
10+
type = string
11+
}
12+
13+
variable "source_security_group_id" {
14+
description = "The SG that this SG allows ingress from"
15+
type = string
16+
}
17+
18+
variable "description" {
19+
description = "Use this string to add a description for the SG rule"
20+
type = string
21+
}
22+
23+
variable "port" {
24+
description = "The port to open"
25+
type = string
26+
}
27+
28+
variable "tcp" {
29+
description = "true/false to enables the tcp ingress"
30+
default = "true"
31+
type = string
32+
}
33+
34+
variable "udp" {
35+
description = "true/false to enables the udp ingress"
36+
default = "false"
37+
type = string
38+
}
39+
40+
locals {
41+
tcp = "${var.tcp ? 1 : 0}"
42+
udp = "${var.udp ? 1 : 0}"
43+
}
44+
45+
# ingress rule for tcp, if enabled
46+
resource "aws_security_group_rule" "tcp_ingress" {
47+
count = local.tcp
48+
type = "ingress"
49+
description = "${var.description} (tcp)"
50+
from_port = var.port
51+
to_port = var.port
52+
protocol = "tcp"
53+
security_group_id = var.security_group_id
54+
source_security_group_id = var.source_security_group_id
55+
}
56+
57+
# ingress rule for udp, if enabled
58+
resource "aws_security_group_rule" "udp_ingress" {
59+
count = local.udp
60+
type = "ingress"
61+
description = "${var.description} (udp)"
62+
from_port = var.port
63+
to_port = var.port
64+
protocol = "udp"
65+
security_group_id = var.security_group_id
66+
source_security_group_id = var.source_security_group_id
67+
}
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
terraform {
3+
required_version = ">= 0.12"
4+
}

modules/single-port-sg/README.md

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
## Single Port Security Group Rule
22

33
Create an `aws_security_group_rule` to allow ingress on some port.
4-
5-
TODO: support both TCP and UDP, use count to enable/disable.

modules/single-port-sg/main.tf

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
*
44
* Create an `aws_security_group_rule` to allow ingress on some port.
55
*
6-
* TODO: support both TCP and UDP, use count to enable/disable.
7-
*
86
*/
97

108
variable "security_group_id" {

0 commit comments

Comments
 (0)