1 data "vault_aws_access_credentials" "creds" {
2 backend = "${var.vault-name}-path"
3 role = "${var.vault-name}-role"
6 resource "aws_vpc" "CSITVPC" {
7 assign_generated_ipv6_cidr_block = false
8 enable_dns_hostnames = false
9 enable_dns_support = true
10 cidr_block = var.vpc_cidr_mgmt
11 instance_tenancy = "default"
14 "Name" = "${var.resources_name_prefix}_${var.testbed_name}-vpc"
15 "Environment" = var.environment_name
19 resource "aws_security_group" "CSITSG" {
23 description = "Allow inbound traffic"
24 name = "${var.resources_name_prefix}_${var.testbed_name}-sg"
25 revoke_rules_on_delete = false
26 vpc_id = aws_vpc.CSITVPC.id
32 cidr_blocks = ["0.0.0.0/0"]
48 cidr_blocks = ["0.0.0.0/0"]
53 "Name" = "${var.resources_name_prefix}_${var.testbed_name}-sg"
54 "Environment" = var.environment_name
58 resource "aws_vpc_ipv4_cidr_block_association" "b" {
62 cidr_block = var.vpc_cidr_b
63 vpc_id = aws_vpc.CSITVPC.id
66 resource "aws_vpc_ipv4_cidr_block_association" "c" {
70 cidr_block = var.vpc_cidr_c
71 vpc_id = aws_vpc.CSITVPC.id
74 resource "aws_vpc_ipv4_cidr_block_association" "d" {
78 cidr_block = var.vpc_cidr_d
79 vpc_id = aws_vpc.CSITVPC.id
83 resource "aws_subnet" "mgmt" {
84 availability_zone = var.avail_zone
85 assign_ipv6_address_on_creation = false
86 cidr_block = var.vpc_cidr_mgmt
90 map_public_ip_on_launch = false
91 vpc_id = aws_vpc.CSITVPC.id
94 "Environment" = var.environment_name
98 resource "aws_subnet" "b" {
99 availability_zone = var.avail_zone
100 assign_ipv6_address_on_creation = false
101 cidr_block = var.vpc_cidr_b
104 aws_vpc_ipv4_cidr_block_association.b
106 map_public_ip_on_launch = false
107 vpc_id = aws_vpc.CSITVPC.id
110 "Environment" = var.environment_name
114 resource "aws_subnet" "c" {
115 availability_zone = var.avail_zone
116 assign_ipv6_address_on_creation = false
117 cidr_block = var.vpc_cidr_c
120 aws_vpc_ipv4_cidr_block_association.c
122 map_public_ip_on_launch = false
123 vpc_id = aws_vpc.CSITVPC.id
126 "Environment" = var.environment_name
130 resource "aws_subnet" "d" {
131 availability_zone = var.avail_zone
132 assign_ipv6_address_on_creation = false
133 cidr_block = var.vpc_cidr_d
136 aws_vpc_ipv4_cidr_block_association.d
138 map_public_ip_on_launch = false
139 vpc_id = aws_vpc.CSITVPC.id
142 "Environment" = var.environment_name
146 resource "aws_internet_gateway" "CSITGW" {
150 vpc_id = aws_vpc.CSITVPC.id
153 "Environment" = var.environment_name
158 # Temporary key for provisioning only
159 resource "tls_private_key" "CSITTLS" {
165 resource "aws_key_pair" "CSITKP" {
166 key_name = "${var.resources_name_prefix}_${var.testbed_name}-key"
167 public_key = "${tls_private_key.CSITTLS.public_key_openssh}"
170 resource "aws_placement_group" "CSITPG" {
171 name = "${var.resources_name_prefix}_${var.testbed_name}-pg"
176 resource "aws_network_interface" "dut1_if1" {
182 private_ip = var.dut1_if1_ip
183 private_ips = [var.dut1_if1_ip]
184 security_groups = [aws_security_group.CSITSG.id]
185 source_dest_check = false
186 subnet_id = aws_subnet.b.id
189 instance = aws_instance.dut1.id
194 "Environment" = var.environment_name
198 resource "aws_network_interface" "dut1_if2" {
204 private_ip = var.dut1_if2_ip
205 private_ips = [var.dut1_if2_ip]
206 security_groups = [aws_security_group.CSITSG.id]
207 source_dest_check = false
208 subnet_id = aws_subnet.d.id
211 instance = aws_instance.dut1.id
216 "Environment" = var.environment_name
220 resource "aws_network_interface" "tg_if1" {
226 private_ip = var.tg_if1_ip
227 private_ips = [var.tg_if1_ip]
228 security_groups = [aws_security_group.CSITSG.id]
229 source_dest_check = false
230 subnet_id = aws_subnet.b.id
233 instance = aws_instance.tg.id
238 "Environment" = var.environment_name
242 resource "aws_network_interface" "tg_if2" {
248 private_ip = var.tg_if2_ip
249 private_ips = [var.tg_if2_ip]
250 security_groups = [aws_security_group.CSITSG.id]
251 source_dest_check = false
252 subnet_id = aws_subnet.d.id
255 instance = aws_instance.tg.id
260 "Environment" = var.environment_name
264 data "aws_network_interface" "dut1_if1" {
265 id = aws_network_interface.dut1_if1.id
268 data "aws_network_interface" "dut1_if2" {
269 id = aws_network_interface.dut1_if2.id
272 data "aws_network_interface" "tg_if1" {
273 id = aws_network_interface.tg_if1.id
276 data "aws_network_interface" "tg_if2" {
277 id = aws_network_interface.tg_if2.id
281 resource "aws_instance" "tg" {
284 aws_placement_group.CSITPG,
285 aws_security_group.CSITSG
287 ami = var.ami_image_tg
288 availability_zone = var.avail_zone
289 associate_public_ip_address = true
290 instance_initiated_shutdown_behavior = var.instance_initiated_shutdown_behavior
291 instance_type = var.instance_type
292 key_name = aws_key_pair.CSITKP.key_name
293 placement_group = aws_placement_group.CSITPG.id
294 private_ip = var.tg_mgmt_ip
295 source_dest_check = false
296 subnet_id = aws_subnet.mgmt.id
297 vpc_security_group_ids = [aws_security_group.CSITSG.id]
300 # root_block_device {
305 "Name" = "${var.resources_name_prefix}_${var.testbed_name}-tg"
306 "Environment" = var.environment_name
310 resource "aws_instance" "dut1" {
313 aws_placement_group.CSITPG,
314 aws_security_group.CSITSG,
317 ami = var.ami_image_sut
318 availability_zone = var.avail_zone
319 associate_public_ip_address = true
320 instance_initiated_shutdown_behavior = var.instance_initiated_shutdown_behavior
321 instance_type = var.instance_type
322 key_name = aws_key_pair.CSITKP.key_name
323 placement_group = aws_placement_group.CSITPG.id
324 private_ip = var.dut1_mgmt_ip
325 source_dest_check = false
326 subnet_id = aws_subnet.mgmt.id
327 vpc_security_group_ids = [aws_security_group.CSITSG.id]
330 # root_block_device {
335 "Name" = "${var.resources_name_prefix}_${var.testbed_name}-dut1"
336 "Environment" = var.environment_name
341 resource "aws_route" "CSIT-igw" {
344 aws_internet_gateway.CSITGW
346 destination_cidr_block = "0.0.0.0/0"
347 gateway_id = aws_internet_gateway.CSITGW.id
348 route_table_id = aws_vpc.CSITVPC.main_route_table_id
351 resource "aws_route" "dummy-trex-port-0" {
356 destination_cidr_block = var.trex_dummy_cidr_port_0
357 network_interface_id = aws_instance.tg.primary_network_interface_id
358 route_table_id = aws_vpc.CSITVPC.main_route_table_id
361 resource "aws_route" "dummy-trex-port-1" {
366 destination_cidr_block = var.trex_dummy_cidr_port_1
367 network_interface_id = aws_instance.tg.primary_network_interface_id
368 route_table_id = aws_vpc.CSITVPC.main_route_table_id
372 resource "null_resource" "deploy_tg" {
375 aws_network_interface.tg_if1,
376 aws_network_interface.tg_if2,
378 aws_network_interface.dut1_if1,
379 aws_network_interface.dut1_if2
384 host = aws_instance.tg.public_ip
385 private_key = tls_private_key.CSITTLS.private_key_pem
388 provisioner "remote-exec" {
389 inline = var.first_run_commands
392 # provisioner "ansible" {
395 # file_path = var.ansible_file_path
396 # force_handlers = true
400 # ansible_ssh_pass = var.ansible_provision_pwd
401 # ansible_python_interpreter = var.ansible_python_executable
407 # provisioner "remote-exec" {
408 # on_failure = continue
409 # inline = ["sudo reboot"]
413 resource "null_resource" "deploy_dut1" {
416 aws_network_interface.tg_if1,
417 aws_network_interface.tg_if2,
419 aws_network_interface.dut1_if1,
420 aws_network_interface.dut1_if2
425 host = aws_instance.dut1.public_ip
426 private_key = tls_private_key.CSITTLS.private_key_pem
429 provisioner "remote-exec" {
430 inline = var.first_run_commands
433 # provisioner "ansible" {
436 # file_path = var.ansible_file_path
437 # force_handlers = true
439 # hosts = ["sut_aws"]
441 # ansible_ssh_pass = var.ansible_provision_pwd
442 # ansible_python_interpreter = var.ansible_python_executable
448 # provisioner "remote-exec" {
449 # on_failure = continue
450 # inline = ["sudo reboot"]
454 resource "null_resource" "deploy_topology" {
460 provisioner "ansible" {
463 file_path = var.ansible_topology_path
467 ansible_python_interpreter = var.ansible_python_executable
468 testbed_name = var.testbed_name
469 cloud_topology = var.topology_name
470 tg_if1_mac = data.aws_network_interface.tg_if1.mac_address
471 tg_if2_mac = data.aws_network_interface.tg_if2.mac_address
472 dut1_if1_mac = data.aws_network_interface.dut1_if1.mac_address
473 dut1_if2_mac = data.aws_network_interface.dut1_if2.mac_address
474 tg_public_ip = aws_instance.tg.public_ip
475 dut1_public_ip = aws_instance.dut1.public_ip
476 public_ip_list = "${aws_instance.tg.public_ip},${aws_instance.dut1.public_ip}"