5 resource "aws_vpc" "CSITVPC" {
6 cidr_block = var.vpc_cidr_mgmt
9 "Name" = "${var.resources_name_prefix}_${var.testbed_name}-vpc"
10 "Environment" = var.environment_name
14 resource "aws_security_group" "CSITSG" {
15 name = "${var.resources_name_prefix}_${var.testbed_name}-sg"
16 description = "Allow inbound traffic"
17 vpc_id = aws_vpc.CSITVPC.id
18 depends_on = [aws_vpc.CSITVPC]
24 cidr_blocks = ["0.0.0.0/0"]
38 cidr_blocks = ["0.0.0.0/0"]
42 "Name" = "${var.resources_name_prefix}_${var.testbed_name}-sg"
43 "Environment" = var.environment_name
47 resource "aws_vpc_ipv4_cidr_block_association" "b" {
48 vpc_id = aws_vpc.CSITVPC.id
49 cidr_block = var.vpc_cidr_b
50 depends_on = [aws_vpc.CSITVPC]
52 resource "aws_vpc_ipv4_cidr_block_association" "c" {
53 vpc_id = aws_vpc.CSITVPC.id
54 cidr_block = var.vpc_cidr_c
55 depends_on = [aws_vpc.CSITVPC]
57 resource "aws_vpc_ipv4_cidr_block_association" "d" {
58 vpc_id = aws_vpc.CSITVPC.id
59 cidr_block = var.vpc_cidr_d
60 depends_on = [aws_vpc.CSITVPC]
64 resource "aws_subnet" "mgmt" {
65 vpc_id = aws_vpc.CSITVPC.id
66 cidr_block = var.vpc_cidr_mgmt
67 availability_zone = var.avail_zone
68 depends_on = [aws_vpc.CSITVPC]
71 "Environment" = var.environment_name
74 resource "aws_subnet" "b" {
75 vpc_id = aws_vpc.CSITVPC.id
76 cidr_block = var.vpc_cidr_b
77 availability_zone = var.avail_zone
78 depends_on = [aws_vpc.CSITVPC, aws_vpc_ipv4_cidr_block_association.b]
81 "Environment" = var.environment_name
84 resource "aws_subnet" "c" {
85 vpc_id = aws_vpc.CSITVPC.id
86 cidr_block = var.vpc_cidr_c
87 availability_zone = var.avail_zone
88 depends_on = [aws_vpc.CSITVPC, aws_vpc_ipv4_cidr_block_association.c]
91 "Environment" = var.environment_name
94 resource "aws_subnet" "d" {
95 vpc_id = aws_vpc.CSITVPC.id
96 cidr_block = var.vpc_cidr_d
97 availability_zone = var.avail_zone
98 depends_on = [aws_vpc.CSITVPC, aws_vpc_ipv4_cidr_block_association.d]
101 "Environment" = var.environment_name
105 resource "aws_internet_gateway" "CSITGW" {
106 vpc_id = aws_vpc.CSITVPC.id
107 depends_on = [aws_vpc.CSITVPC]
110 "Environment" = var.environment_name
115 # Temporary key for provisioning only
116 resource "tls_private_key" "CSITTLS" {
120 resource "aws_key_pair" "CSITKP" {
121 key_name = "CSIT_3n_aws_c5n_${var.testbed_name}-key"
122 public_key = tls_private_key.CSITTLS.public_key_openssh
125 resource "aws_placement_group" "CSITPG" {
126 name = "${var.resources_name_prefix}_${var.testbed_name}-pg"
131 resource "aws_network_interface" "dut1_if1" {
132 subnet_id = aws_subnet.b.id
133 source_dest_check = false
134 private_ip = var.dut1_if1_ip
135 private_ips = [var.dut1_if1_ip]
136 security_groups = [aws_security_group.CSITSG.id]
137 depends_on = [aws_vpc.CSITVPC, aws_subnet.b]
140 instance = aws_instance.dut1.id
145 "Environment" = var.environment_name
149 resource "aws_network_interface" "dut1_if2" {
150 subnet_id = aws_subnet.c.id
151 source_dest_check = false
152 private_ip = var.dut1_if2_ip
153 private_ips = [var.dut1_if2_ip]
154 security_groups = [aws_security_group.CSITSG.id]
155 depends_on = [aws_vpc.CSITVPC]
158 instance = aws_instance.dut1.id
163 "Environment" = var.environment_name
167 resource "aws_network_interface" "dut2_if1" {
168 subnet_id = aws_subnet.c.id
169 source_dest_check = false
170 private_ip = var.dut2_if1_ip
171 private_ips = [var.dut2_if1_ip]
172 security_groups = [aws_security_group.CSITSG.id]
173 depends_on = [aws_vpc.CSITVPC, aws_subnet.c]
176 instance = aws_instance.dut2.id
181 "Environment" = var.environment_name
185 resource "aws_network_interface" "dut2_if2" {
186 subnet_id = aws_subnet.d.id
187 source_dest_check = false
188 private_ip = var.dut2_if2_ip
189 private_ips = [var.dut2_if2_ip]
190 security_groups = [aws_security_group.CSITSG.id]
191 depends_on = [aws_vpc.CSITVPC, aws_subnet.d]
194 instance = aws_instance.dut2.id
199 "Environment" = var.environment_name
203 resource "aws_network_interface" "tg_if1" {
204 subnet_id = aws_subnet.b.id
205 source_dest_check = false
206 private_ip = var.tg_if1_ip
207 private_ips = [var.tg_if1_ip]
208 security_groups = [aws_security_group.CSITSG.id]
209 depends_on = [aws_vpc.CSITVPC, aws_subnet.b]
212 instance = aws_instance.tg.id
217 "Environment" = var.environment_name
221 resource "aws_network_interface" "tg_if2" {
222 subnet_id = aws_subnet.d.id
223 source_dest_check = false
224 private_ip = var.tg_if2_ip
225 private_ips = [var.tg_if2_ip]
226 security_groups = [aws_security_group.CSITSG.id]
227 depends_on = [aws_vpc.CSITVPC, aws_subnet.d]
230 instance = aws_instance.tg.id
235 "Environment" = var.environment_name
239 data "aws_network_interface" "dut1_if1" {
240 id = aws_network_interface.dut1_if1.id
243 data "aws_network_interface" "dut1_if2" {
244 id = aws_network_interface.dut1_if2.id
247 data "aws_network_interface" "dut2_if1" {
248 id = aws_network_interface.dut2_if1.id
251 data "aws_network_interface" "dut2_if2" {
252 id = aws_network_interface.dut2_if2.id
255 data "aws_network_interface" "tg_if1" {
256 id = aws_network_interface.tg_if1.id
259 data "aws_network_interface" "tg_if2" {
260 id = aws_network_interface.tg_if2.id
264 resource "aws_instance" "tg" {
265 depends_on = [aws_vpc.CSITVPC, aws_placement_group.CSITPG]
267 availability_zone = var.avail_zone
268 instance_type = var.instance_type
269 key_name = aws_key_pair.CSITKP.key_name
270 associate_public_ip_address = true
271 subnet_id = aws_subnet.mgmt.id
272 private_ip = var.tg_mgmt_ip
273 vpc_security_group_ids = [aws_security_group.CSITSG.id]
274 placement_group = aws_placement_group.CSITPG.id
275 source_dest_check = false
283 "Name" = "${var.resources_name_prefix}_${var.testbed_name}-tg"
284 "Environment" = var.environment_name
288 resource "aws_instance" "dut1" {
289 depends_on = [aws_vpc.CSITVPC, aws_placement_group.CSITPG]
291 availability_zone = var.avail_zone
292 instance_type = var.instance_type
293 key_name = aws_key_pair.CSITKP.key_name
294 associate_public_ip_address = true
295 subnet_id = aws_subnet.mgmt.id
296 private_ip = var.dut1_mgmt_ip
297 vpc_security_group_ids = [aws_security_group.CSITSG.id]
298 placement_group = aws_placement_group.CSITPG.id
299 source_dest_check = false
307 "Name" = "${var.resources_name_prefix}_${var.testbed_name}-dut1"
308 "Environment" = var.environment_name
312 resource "aws_instance" "dut2" {
313 depends_on = [aws_vpc.CSITVPC, aws_placement_group.CSITPG]
315 availability_zone = var.avail_zone
316 instance_type = var.instance_type
317 key_name = aws_key_pair.CSITKP.key_name
318 associate_public_ip_address = true
319 subnet_id = aws_subnet.mgmt.id
320 private_ip = var.dut2_mgmt_ip
321 vpc_security_group_ids = [aws_security_group.CSITSG.id]
322 placement_group = aws_placement_group.CSITPG.id
323 source_dest_check = false
331 "Name" = "${var.resources_name_prefix}_${var.testbed_name}-dut2"
332 "Environment" = var.environment_name
337 resource "aws_route" "CSIT-igw" {
338 route_table_id = aws_vpc.CSITVPC.main_route_table_id
339 gateway_id = aws_internet_gateway.CSITGW.id
340 destination_cidr_block = "0.0.0.0/0"
341 depends_on = [aws_vpc.CSITVPC, aws_internet_gateway.CSITGW]
343 resource "aws_route" "dummy-trex-port-0" {
344 route_table_id = aws_vpc.CSITVPC.main_route_table_id
345 network_interface_id = aws_instance.tg.primary_network_interface_id
346 destination_cidr_block = var.trex_dummy_cidr_port_0
347 depends_on = [aws_vpc.CSITVPC, aws_instance.dut1]
349 resource "aws_route" "dummy-trex-port-1" {
350 route_table_id = aws_vpc.CSITVPC.main_route_table_id
351 network_interface_id = aws_instance.tg.primary_network_interface_id
352 destination_cidr_block = var.trex_dummy_cidr_port_1
353 depends_on = [aws_vpc.CSITVPC, aws_instance.dut1]
357 resource "null_resource" "deploy_tg" {
360 aws_network_interface.tg_if1,
361 aws_network_interface.tg_if2
366 host = aws_instance.tg.public_ip
367 private_key = tls_private_key.CSITTLS.private_key_pem
370 provisioner "remote-exec" {
371 inline = var.first_run_commands
374 provisioner "ansible" {
377 file_path = var.ansible_file_path
378 force_handlers = true
382 ansible_ssh_pass = var.ansible_provision_pwd
383 ansible_python_interpreter = var.ansible_python_executable
390 resource "null_resource" "deploy_dut1" {
393 aws_network_interface.dut1_if1,
394 aws_network_interface.dut1_if2
399 host = aws_instance.dut1.public_ip
400 private_key = tls_private_key.CSITTLS.private_key_pem
403 provisioner "remote-exec" {
404 inline = var.first_run_commands
407 provisioner "ansible" {
410 file_path = var.ansible_file_path
411 force_handlers = true
415 ansible_ssh_pass = var.ansible_provision_pwd
416 ansible_python_interpreter = var.ansible_python_executable
423 resource "null_resource" "deploy_dut2" {
426 aws_network_interface.dut2_if1,
427 aws_network_interface.dut2_if2
432 host = aws_instance.dut2.public_ip
433 private_key = tls_private_key.CSITTLS.private_key_pem
436 provisioner "remote-exec" {
437 inline = var.first_run_commands
440 provisioner "ansible" {
443 file_path = var.ansible_file_path
444 force_handlers = true
448 ansible_ssh_pass = var.ansible_provision_pwd
449 ansible_python_interpreter = var.ansible_python_executable
456 resource "null_resource" "deploy_topology" {
457 depends_on = [ aws_instance.tg, aws_instance.dut1, aws_instance.dut2 ]
459 provisioner "ansible" {
462 file_path = var.ansible_topology_path
466 ansible_python_interpreter = var.ansible_python_executable
467 testbed_name = var.testbed_name
468 cloud_topology = var.topology_name
469 tg_if1_mac = data.aws_network_interface.tg_if1.mac_address
470 tg_if2_mac = data.aws_network_interface.tg_if2.mac_address
471 dut1_if1_mac = data.aws_network_interface.dut1_if1.mac_address
472 dut1_if2_mac = data.aws_network_interface.dut1_if2.mac_address
473 dut2_if1_mac = data.aws_network_interface.dut2_if1.mac_address
474 dut2_if2_mac = data.aws_network_interface.dut2_if2.mac_address
475 tg_public_ip = aws_instance.tg.public_ip
476 dut1_public_ip = aws_instance.dut1.public_ip
477 dut2_public_ip = aws_instance.dut2.public_ip
478 public_ip_list = "${aws_instance.tg.public_ip},${aws_instance.dut1.public_ip},${aws_instance.dut2.public_ip}"