This repository was archived by the owner on Jul 11, 2023. It is now read-only.
File tree 5 files changed +74
-4
lines changed
5 files changed +74
-4
lines changed Original file line number Diff line number Diff line change
1
+ ## Single Port Security Group Rule
2
+
3
+ Create an ` aws_security_group_rule ` to allow ingress on some port.
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+
2
+ terraform {
3
+ required_version = " >= 0.12"
4
+ }
Original file line number Diff line number Diff line change 1
1
## Single Port Security Group Rule
2
2
3
3
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.
Original file line number Diff line number Diff line change 3
3
*
4
4
* Create an `aws_security_group_rule` to allow ingress on some port.
5
5
*
6
- * TODO: support both TCP and UDP, use count to enable/disable.
7
- *
8
6
*/
9
7
10
8
variable "security_group_id" {
You can’t perform that action at this time.
0 commit comments