Skip to content

Commit ff8bb5a

Browse files
committed
initial version
1 parent e52d58f commit ff8bb5a

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

main.tf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
resource "aws_security_group" "sg" {
2+
name = var.name
3+
description = var.description
4+
vpc_id = var.vpc_id
5+
6+
dynamic "ingress" {
7+
for_each = var.ingress_rules
8+
content {
9+
description = ingress.value.description
10+
from_port = ingress.value.from_port
11+
to_port = ingress.value.to_port
12+
protocol = ingress.value.protocol
13+
cidr_blocks = ingress.value.cidr_blocks
14+
}
15+
}
16+
17+
dynamic "egress" {
18+
for_each = var.egress_rules
19+
content {
20+
description = egress.value.description
21+
from_port = egress.value.from_port
22+
to_port = egress.value.to_port
23+
protocol = egress.value.protocol
24+
cidr_blocks = egress.value.cidr_blocks
25+
}
26+
}
27+
}

outputs.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
output "security_group_id" {
2+
value = aws_security_group.default.id
3+
description = "Security Group ID"
4+
}
5+
6+
output "security_group_arn" {
7+
value = aws_security_group.default.arn
8+
description = "ARN of the security group."
9+
}
10+
11+
output "ingress_rules" {
12+
value = aws_security_group.default.ingress
13+
description = "All your ingress rules."
14+
}
15+
16+
output "egress_rules" {
17+
value = aws_security_group.default.egress
18+
description = "All your egress rules."
19+
}

variables.tf

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
variable "vpc_id" {
2+
type = string
3+
description = "Your VPC ID"
4+
}
5+
6+
variable "name" {
7+
type = string
8+
description = "Your Security Group Name."
9+
}
10+
11+
variable "description" {
12+
type = string
13+
description = "Description for your Security Group"
14+
}
15+
16+
17+
variable "ingress_rules" {
18+
type = list(object({
19+
description = string
20+
from_port = number
21+
to_port = number
22+
protocol = string
23+
cidr_blocks = list(string)
24+
}))
25+
description = "List of objects like: {\"description\": \"\", \"from_port\": x, \"to_port\": x, \"protocol\": \"\", \"cidr_block\": \"\"}"
26+
}
27+
28+
variable "egress_rules" {
29+
type = list(object({
30+
description = string
31+
from_port = number
32+
to_port = number
33+
protocol = string
34+
cidr_blocks = list(string)
35+
}))
36+
description = "List of objects like: {\"description\": \"\", \"from_port\": x, \"to_port\": x, \"protocol\": \"\", \"cidr_block\": \"\",}"
37+
}

0 commit comments

Comments
 (0)