-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.tf
86 lines (78 loc) · 2.11 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Fetch AWS subnet data
data "aws_subnet" "main" {
id = var.subnet_id
}
# SMTP instance
resource "aws_instance" "smtp" {
ami = var.ami_id
instance_type = var.instance_type
key_name = var.key_name
vpc_security_group_ids = [
aws_security_group.smtp.id,
]
subnet_id = var.subnet_id
tags = {
Name = var.name_prefix != "" ? "${var.name_prefix}_smtp" : "smtp"
Owner = var.owner != "" ? var.owner : "Terraform"
}
}
# SMTP security group
resource "aws_security_group" "smtp" {
name = var.name_prefix != "" ? "${var.name_prefix}_smtp_sg" : "smtp_sg"
description = "Security group for SMTP instance"
vpc_id = data.aws_subnet.main.vpc_id
tags = {
Name = var.name_prefix != "" ? "${var.name_prefix}_smtp_sg" : "smtp_sg"
Owner = var.owner != "" ? var.owner : "Terraform"
}
}
resource "aws_security_group_rule" "smtp_ingress_ssh" {
type = "ingress"
from_port = 22
to_port = 22
protocol = "tcp"
security_group_id = aws_security_group.smtp.id
cidr_blocks = [
"0.0.0.0/0",
]
}
resource "aws_security_group_rule" "smtp_ingress_controller" {
type = "ingress"
from_port = 25
to_port = 25
protocol = "tcp"
security_group_id = aws_security_group.smtp.id
cidr_blocks = [
data.aws_subnet.main.cidr_block,
]
}
resource "aws_security_group_rule" "smtp_ingress_http" {
type = "ingress"
from_port = 80
to_port = 80
protocol = "tcp"
security_group_id = aws_security_group.smtp.id
cidr_blocks = [
"0.0.0.0/0",
]
}
resource "aws_security_group_rule" "smtp_egress_http" {
type = "egress"
from_port = 80
to_port = 80
protocol = "tcp"
security_group_id = aws_security_group.smtp.id
cidr_blocks = [
"0.0.0.0/0",
]
}
resource "aws_security_group_rule" "smtp_egress_https" {
type = "egress"
from_port = 443
to_port = 443
protocol = "tcp"
security_group_id = aws_security_group.smtp.id
cidr_blocks = [
"0.0.0.0/0",
]
}