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 = "192.168.20.11"
54 variable "tg_mgmt_ip" {
56 default = "192.168.0.10"
58 variable "dut1_mgmt_ip" {
60 default = "192.168.0.11"
64 variable "instance_type" {
66 default = "c5n.2xlarge"
69 resource "aws_vpc" "CSIT" {
70 cidr_block = var.vpc_cidr_mgmt
73 resource "aws_security_group" "CSIT" {
75 description = "Allow inbound traffic"
76 vpc_id = aws_vpc.CSIT.id
82 cidr_blocks = ["0.0.0.0/0"]
96 cidr_blocks = ["0.0.0.0/0"]
99 depends_on = [aws_vpc.CSIT]
102 resource "aws_vpc_ipv4_cidr_block_association" "b" {
103 vpc_id = aws_vpc.CSIT.id
104 cidr_block = var.vpc_cidr_b
105 depends_on = [aws_vpc.CSIT]
107 resource "aws_vpc_ipv4_cidr_block_association" "c" {
108 vpc_id = aws_vpc.CSIT.id
109 cidr_block = var.vpc_cidr_c
110 depends_on = [aws_vpc.CSIT]
112 resource "aws_vpc_ipv4_cidr_block_association" "d" {
113 vpc_id = aws_vpc.CSIT.id
114 cidr_block = var.vpc_cidr_d
115 depends_on = [aws_vpc.CSIT]
118 resource "aws_subnet" "mgmt" {
119 vpc_id = aws_vpc.CSIT.id
120 cidr_block = var.vpc_cidr_mgmt
121 availability_zone = var.avail_zone
122 depends_on = [aws_vpc.CSIT]
125 resource "aws_subnet" "b" {
126 vpc_id = aws_vpc.CSIT.id
127 cidr_block = var.vpc_cidr_b
128 availability_zone = var.avail_zone
129 depends_on = [aws_vpc.CSIT, aws_vpc_ipv4_cidr_block_association.b]
132 resource "aws_subnet" "c" {
133 vpc_id = aws_vpc.CSIT.id
134 cidr_block = var.vpc_cidr_c
135 availability_zone = var.avail_zone
136 depends_on = [aws_vpc.CSIT, aws_vpc_ipv4_cidr_block_association.c]
139 resource "aws_subnet" "d" {
140 vpc_id = aws_vpc.CSIT.id
141 cidr_block = var.vpc_cidr_d
142 availability_zone = var.avail_zone
143 depends_on = [aws_vpc.CSIT, aws_vpc_ipv4_cidr_block_association.d]
146 resource "aws_internet_gateway" "CSIT" {
147 vpc_id = aws_vpc.CSIT.id
148 depends_on = [aws_vpc.CSIT]
151 resource "aws_key_pair" "CSIT" {
153 public_key = file("~/.ssh/id_rsa.pub")
156 data "aws_ami" "ubuntu" {
161 values = ["*hvm-ssd/ubuntu-bionic-18.04-amd64*"]
165 name = "virtualization-type"
169 owners = ["099720109477"] # Canonical
172 resource "aws_placement_group" "CSIT" {
177 resource "aws_instance" "tg" {
178 ami = data.aws_ami.ubuntu.id
179 instance_type = var.instance_type
180 # cpu_threads_per_core = 1
181 # cpu_core_count = 18
182 key_name = aws_key_pair.CSIT.key_name
183 associate_public_ip_address = true
184 subnet_id = aws_subnet.mgmt.id
188 private_ip = var.tg_mgmt_ip
189 vpc_security_group_ids = [aws_security_group.CSIT.id]
190 depends_on = [aws_vpc.CSIT, aws_placement_group.CSIT]
191 placement_group = aws_placement_group.CSIT.id
192 source_dest_check = false
195 resource "aws_instance" "dut1" {
196 ami = data.aws_ami.ubuntu.id
197 # cpu_threads_per_core = 1
198 # cpu_core_count = 18
199 instance_type = var.instance_type
200 key_name = aws_key_pair.CSIT.key_name
201 associate_public_ip_address = true
202 subnet_id = aws_subnet.mgmt.id
206 private_ip = var.dut1_mgmt_ip
207 vpc_security_group_ids = [aws_security_group.CSIT.id]
208 depends_on = [aws_vpc.CSIT, aws_placement_group.CSIT]
209 placement_group = aws_placement_group.CSIT.id
210 source_dest_check = false
213 resource "aws_route" "CSIT-igw" {
214 route_table_id = aws_vpc.CSIT.main_route_table_id
215 gateway_id = aws_internet_gateway.CSIT.id
216 destination_cidr_block = "0.0.0.0/0"
217 depends_on = [aws_vpc.CSIT, aws_internet_gateway.CSIT]
219 resource "aws_route" "dummy-trex-port-0" {
220 route_table_id = aws_vpc.CSIT.main_route_table_id
221 network_interface_id = aws_instance.tg.primary_network_interface_id
222 destination_cidr_block = var.trex_dummy_cidr_port_0
223 depends_on = [aws_vpc.CSIT, aws_instance.dut1]
225 resource "aws_route" "dummy-trex-port-1" {
226 route_table_id = aws_vpc.CSIT.main_route_table_id
227 network_interface_id = aws_instance.tg.primary_network_interface_id
228 destination_cidr_block = var.trex_dummy_cidr_port_1
229 depends_on = [aws_vpc.CSIT, aws_instance.dut1]
232 resource "null_resource" "deploy_tg" {
233 depends_on = [ aws_instance.tg ]
236 host = aws_instance.tg.public_ip
237 private_key = file("~/.ssh/id_rsa")
239 provisioner "ansible" {
242 file_path = "../../testbed-setup/ansible/site_aws.yaml"
243 force_handlers = true
247 ansible_python_interpreter = "/usr/bin/python3"
253 resource "null_resource" "deploy_dut1" {
254 depends_on = [ aws_instance.dut1 ]
257 host = aws_instance.dut1.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"
275 resource "null_resource" "deploy_topology" {
276 depends_on = [ aws_instance.tg, aws_instance.dut1 ]
277 provisioner "ansible" {
280 file_path = "../../testbed-setup/ansible/cloud_topology.yaml"
284 ansible_python_interpreter = "/usr/bin/python3"
285 cloud_topology = "2n_aws_c5n"
286 tg_if1_mac = data.aws_network_interface.tg_if1.mac_address
287 tg_if2_mac = data.aws_network_interface.tg_if2.mac_address
288 dut1_if1_mac = data.aws_network_interface.dut1_if1.mac_address
289 dut1_if2_mac = data.aws_network_interface.dut1_if2.mac_address
290 tg_public_ip = aws_instance.tg.public_ip
291 dut1_public_ip = aws_instance.dut1.public_ip
298 value = "TG IP: ${aws_instance.tg.public_ip}"
302 value = "DUT1 IP: ${aws_instance.dut1.public_ip}"