forked from futurice/terraform-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecurity.tf
72 lines (63 loc) · 2.21 KB
/
security.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
# Create an SSH key pair for accessing the EC2 instance
resource "aws_key_pair" "this" {
public_key = "${file("${var.ssh_public_key_path}")}"
}
# Create our default security group to access the instance, over specific protocols
resource "aws_security_group" "this" {
vpc_id = "${data.aws_vpc.this.id}"
tags = "${merge(var.tags, map("Name", "${var.hostname}"))}"
}
# Incoming SSH & outgoing ANY needs to be allowed for provisioning to work
resource "aws_security_group_rule" "outgoing_any" {
security_group_id = "${aws_security_group.this.id}"
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "incoming_ssh" {
security_group_id = "${aws_security_group.this.id}"
type = "ingress"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# The rest of the security rules are opt-in
resource "aws_security_group_rule" "incoming_http" {
count = "${var.allow_incoming_http ? 1 : 0}"
security_group_id = "${aws_security_group.this.id}"
type = "ingress"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "incoming_https" {
count = "${var.allow_incoming_https ? 1 : 0}"
security_group_id = "${aws_security_group.this.id}"
type = "ingress"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "incoming_dns_tcp" {
count = "${var.allow_incoming_dns ? 1 : 0}"
security_group_id = "${aws_security_group.this.id}"
type = "ingress"
from_port = 53
to_port = 53
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "incoming_dns_udp" {
count = "${var.allow_incoming_dns ? 1 : 0}"
security_group_id = "${aws_security_group.this.id}"
type = "ingress"
from_port = 53
to_port = 53
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
}