2 region = "eu-central-1"
5 variable "avail_zone" {
7 default = "eu-central-1a"
10 variable "vpc_cidr_mgmt" {
12 default = "192.168.0.0/24"
14 variable "vpc_cidr_b" {
16 default = "192.168.10.0/24"
18 variable "vpc_cidr_c" {
20 default = "200.0.0.0/24"
22 variable "vpc_cidr_d" {
24 default = "192.168.20.0/24"
28 variable "trex_dummy_cidr_port_0" {
30 default = "10.0.0.0/24"
32 variable "trex_dummy_cidr_port_1" {
34 default = "20.0.0.0/24"
38 variable "tg_if1_ip" {
40 default = "192.168.10.254"
42 variable "tg_if2_ip" {
44 default = "192.168.20.254"
46 variable "dut1_if1_ip" {
48 default = "192.168.10.11"
50 variable "dut1_if2_ip" {
52 default = "200.0.0.101"
54 variable "dut2_if1_ip" {
56 default = "200.0.0.102"
58 variable "dut2_if2_ip" {
60 default = "192.168.20.11"
62 variable "tg_mgmt_ip" {
64 default = "192.168.0.10"
66 variable "dut1_mgmt_ip" {
68 default = "192.168.0.11"
70 variable "dut2_mgmt_ip" {
72 default = "192.168.0.12"
76 variable "instance_type" {
78 default = "c5n.9xlarge"
81 resource "aws_vpc" "CSIT" {
82 cidr_block = var.vpc_cidr_mgmt
85 resource "aws_security_group" "CSIT" {
87 description = "Allow inbound traffic"
88 vpc_id = aws_vpc.CSIT.id
94 cidr_blocks = ["0.0.0.0/0"]
108 cidr_blocks = ["0.0.0.0/0"]
111 depends_on = [aws_vpc.CSIT]
114 resource "aws_vpc_ipv4_cidr_block_association" "b" {
115 vpc_id = aws_vpc.CSIT.id
116 cidr_block = var.vpc_cidr_b
117 depends_on = [aws_vpc.CSIT]
119 resource "aws_vpc_ipv4_cidr_block_association" "c" {
120 vpc_id = aws_vpc.CSIT.id
121 cidr_block = var.vpc_cidr_c
122 depends_on = [aws_vpc.CSIT]
124 resource "aws_vpc_ipv4_cidr_block_association" "d" {
125 vpc_id = aws_vpc.CSIT.id
126 cidr_block = var.vpc_cidr_d
127 depends_on = [aws_vpc.CSIT]
130 resource "aws_subnet" "mgmt" {
131 vpc_id = aws_vpc.CSIT.id
132 cidr_block = var.vpc_cidr_mgmt
133 availability_zone = var.avail_zone
134 depends_on = [aws_vpc.CSIT]
137 resource "aws_subnet" "b" {
138 vpc_id = aws_vpc.CSIT.id
139 cidr_block = var.vpc_cidr_b
140 availability_zone = var.avail_zone
141 depends_on = [aws_vpc.CSIT, aws_vpc_ipv4_cidr_block_association.b]
144 resource "aws_subnet" "c" {
145 vpc_id = aws_vpc.CSIT.id
146 cidr_block = var.vpc_cidr_c
147 availability_zone = var.avail_zone
148 depends_on = [aws_vpc.CSIT, aws_vpc_ipv4_cidr_block_association.c]
151 resource "aws_subnet" "d" {
152 vpc_id = aws_vpc.CSIT.id
153 cidr_block = var.vpc_cidr_d
154 availability_zone = var.avail_zone
155 depends_on = [aws_vpc.CSIT, aws_vpc_ipv4_cidr_block_association.d]
158 resource "aws_internet_gateway" "CSIT" {
159 vpc_id = aws_vpc.CSIT.id
160 depends_on = [aws_vpc.CSIT]
163 resource "aws_key_pair" "CSIT" {
165 public_key = file("~/.ssh/id_rsa.pub")
168 data "aws_ami" "ubuntu" {
173 values = ["*hvm-ssd/ubuntu-bionic-18.04-amd64*"]
177 name = "virtualization-type"
181 owners = ["099720109477"] # Canonical
184 resource "aws_placement_group" "CSIT" {
189 resource "aws_instance" "tg" {
190 ami = data.aws_ami.ubuntu.id
191 instance_type = var.instance_type
192 # cpu_threads_per_core = 1
193 # cpu_core_count = 18
194 key_name = aws_key_pair.CSIT.key_name
195 associate_public_ip_address = true
196 subnet_id = aws_subnet.mgmt.id
197 private_ip = var.tg_mgmt_ip
198 vpc_security_group_ids = [aws_security_group.CSIT.id]
199 depends_on = [aws_vpc.CSIT, aws_placement_group.CSIT]
200 placement_group = aws_placement_group.CSIT.id
201 source_dest_check = false
204 resource "aws_instance" "dut1" {
205 ami = data.aws_ami.ubuntu.id
206 # cpu_threads_per_core = 1
207 # cpu_core_count = 18
208 instance_type = var.instance_type
209 key_name = aws_key_pair.CSIT.key_name
210 associate_public_ip_address = true
211 subnet_id = aws_subnet.mgmt.id
212 private_ip = var.dut1_mgmt_ip
213 vpc_security_group_ids = [aws_security_group.CSIT.id]
214 depends_on = [aws_vpc.CSIT, aws_placement_group.CSIT]
215 placement_group = aws_placement_group.CSIT.id
216 source_dest_check = false
219 resource "aws_instance" "dut2" {
220 ami = data.aws_ami.ubuntu.id
221 # cpu_threads_per_core = 1
222 # cpu_core_count = 18
223 instance_type = var.instance_type
224 key_name = aws_key_pair.CSIT.key_name
225 associate_public_ip_address = true
226 subnet_id = aws_subnet.mgmt.id
227 private_ip = var.dut2_mgmt_ip
228 vpc_security_group_ids = [aws_security_group.CSIT.id]
229 depends_on = [aws_vpc.CSIT, aws_placement_group.CSIT]
230 placement_group = aws_placement_group.CSIT.id
231 source_dest_check = false
234 resource "aws_route" "CSIT-igw" {
235 route_table_id = aws_vpc.CSIT.main_route_table_id
236 gateway_id = aws_internet_gateway.CSIT.id
237 destination_cidr_block = "0.0.0.0/0"
238 depends_on = [aws_vpc.CSIT, aws_internet_gateway.CSIT]
240 resource "aws_route" "dummy-trex-port-0" {
241 route_table_id = aws_vpc.CSIT.main_route_table_id
242 network_interface_id = aws_instance.tg.primary_network_interface_id
243 destination_cidr_block = var.trex_dummy_cidr_port_0
244 depends_on = [aws_vpc.CSIT, aws_instance.dut1]
246 resource "aws_route" "dummy-trex-port-1" {
247 route_table_id = aws_vpc.CSIT.main_route_table_id
248 network_interface_id = aws_instance.tg.primary_network_interface_id
249 destination_cidr_block = var.trex_dummy_cidr_port_1
250 depends_on = [aws_vpc.CSIT, aws_instance.dut2]
253 resource "null_resource" "deploy_tg" {
254 depends_on = [ aws_instance.tg ]
257 host = aws_instance.tg.public_ip
258 private_key = file("~/.ssh/id_rsa")
260 provisioner "ansible" {
263 file_path = "../../testbed-setup/ansible/site_aws.yaml"
264 force_handlers = true
268 ansible_python_interpreter = "/usr/bin/python3"
274 resource "null_resource" "deploy_dut1" {
275 depends_on = [ aws_instance.dut1 ]
278 host = aws_instance.dut1.public_ip
279 private_key = file("~/.ssh/id_rsa")
281 provisioner "ansible" {
284 file_path = "../../testbed-setup/ansible/site_aws.yaml"
285 force_handlers = true
289 ansible_python_interpreter = "/usr/bin/python3"
295 resource "null_resource" "deploy_dut2" {
296 depends_on = [ aws_instance.dut2 ]
299 host = aws_instance.dut2.public_ip
300 private_key = file("~/.ssh/id_rsa")
302 provisioner "ansible" {
305 file_path = "../../testbed-setup/ansible/site_aws.yaml"
306 force_handlers = true
310 ansible_python_interpreter = "/usr/bin/python3"
317 resource "null_resource" "deploy_topology" {
318 depends_on = [ aws_instance.tg, aws_instance.dut1, aws_instance.dut2 ]
319 provisioner "ansible" {
322 file_path = "../../testbed-setup/ansible/cloud_topology.yaml"
326 ansible_python_interpreter = "/usr/bin/python3"
327 cloud_topology = "aws"
328 tg_if1_mac = data.aws_network_interface.tg_if1.mac_address
329 tg_if2_mac = data.aws_network_interface.tg_if2.mac_address
330 dut1_if1_mac = data.aws_network_interface.dut1_if1.mac_address
331 dut1_if2_mac = data.aws_network_interface.dut1_if2.mac_address
332 dut2_if1_mac = data.aws_network_interface.dut2_if1.mac_address
333 dut2_if2_mac = data.aws_network_interface.dut2_if2.mac_address
334 tg_public_ip = aws_instance.tg.public_ip
335 dut1_public_ip = aws_instance.dut1.public_ip
336 dut2_public_ip = aws_instance.dut2.public_ip
343 value = "TG IP: ${aws_instance.tg.public_ip}"
347 value = "DUT1 IP: ${aws_instance.dut1.public_ip}"
351 value = "DUT2 IP: ${aws_instance.dut2.public_ip}"