-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnetworking.tf
89 lines (83 loc) · 2.33 KB
/
networking.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
87
88
89
# As we need to provision a lot of resources into specific subnets,
# the approach taken here is to just setup a dedicated VPC so that the
# example can be reproduced safely, as long as VPC limits have not been
# reached in the given region.
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "5.0.0"
name = "${var.global_prefix}-vpc"
cidr = "10.0.0.0/16"
azs = ["${var.region}a", "${var.region}b", "${var.region}c"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
enable_nat_gateway = true
enable_vpn_gateway = false
}
# A secruity group for the Kafka cluster, to enable Kafka traffic from the bastion
# instance (public subnets) and other Kafka instances (private subnets), but block
# everything else.
resource "aws_security_group" "kafka" {
name = "${var.global_prefix}-kafka"
vpc_id = module.vpc.vpc_id
ingress {
from_port = 0
to_port = 9092
protocol = "TCP"
cidr_blocks = ["10.0.1.0/24",
"10.0.2.0/24",
"10.0.3.0/24"]
}
ingress {
from_port = 0
to_port = 9092
protocol = "TCP"
cidr_blocks = ["10.0.101.0/24",
"10.0.102.0/24",
"10.0.103.0/24"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "${var.global_prefix}-kafka"
}
}
# Note: This bastion host is configured to allow public SSH access.
# If you follow different conventions, change the bastion host setup
# to whatever works for your organsation.
resource "aws_security_group" "bastion_host" {
name = "${var.global_prefix}-bastion-host"
vpc_id = module.vpc.vpc_id
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "${var.global_prefix}-bastion-host"
}
}
# Connector only needs outgoing internet access, to upload to Ably
resource "aws_security_group" "connector" {
name = "${var.global_prefix}-connector"
vpc_id = module.vpc.vpc_id
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "${var.global_prefix}-connector"
}
}