X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=resources%2Ftools%2Fterraform%2Fazure%2Fmain.tf;h=89f190580031e0978c6b112346ab36e8b0d0bd2b;hb=5d4c299d02072fd18ef175bfbf7c694e94db79a6;hp=79fa456d2344c99cf4c8f88099ade50605c10899;hpb=8605f3f406468f57bb9b2eac12a4421f65965300;p=csit.git diff --git a/resources/tools/terraform/azure/main.tf b/resources/tools/terraform/azure/main.tf index 79fa456d23..89f1905800 100644 --- a/resources/tools/terraform/azure/main.tf +++ b/resources/tools/terraform/azure/main.tf @@ -4,6 +4,11 @@ provider "azurerm" { # Variables +variable "vpc_addr_space_a" { + type = string + default = "172.16.0.0/16" +} + variable "vpc_cidr_a" { type = string default = "172.16.0.0/24" @@ -11,44 +16,42 @@ variable "vpc_cidr_a" { variable "vpc_cidr_b" { type = string - default = "192.168.10.0/24" + default = "172.16.10.0/24" } variable "vpc_cidr_c" { type = string - default = "200.0.0.0/24" + default = "172.16.200.0/24" } variable "vpc_cidr_d" { type = string - default = "192.168.20.0/24" + default = "172.16.20.0/24" } variable "trex_dummy_cidr_port_0" { type = string - default = "10.0.0.0/24" + default = "172.16.11.0/24" } variable "trex_dummy_cidr_port_1" { type = string - default = "20.0.0.0/24" + default = "172.16.21.0/24" } # Create resource group and resources resource "azurerm_resource_group" "CSIT" { - name = "CSIT_pm" - location = "North Europe" + name = "CSIT" + #location = "East US" + location = "UK South" } resource "azurerm_virtual_network" "CSIT" { name = "CSIT-network" resource_group_name = azurerm_resource_group.CSIT.name location = azurerm_resource_group.CSIT.location - address_space = [ var.vpc_cidr_a, - var.vpc_cidr_b, - var.vpc_cidr_c, - var.vpc_cidr_d ] + address_space = [ var.vpc_addr_space_a ] depends_on = [ azurerm_resource_group.CSIT ] } @@ -239,21 +242,21 @@ resource "azurerm_route_table" "b" { disable_bgp_route_propagation = false route { name = "route-10" - address_prefix = "10.0.0.0/24" + address_prefix = var.trex_dummy_cidr_port_0 next_hop_type = "VirtualAppliance" - next_hop_in_ip_address = "192.168.10.254" + next_hop_in_ip_address = data.azurerm_network_interface.tg_if1.private_ip_address } route { name = "route-20" - address_prefix = "20.0.0.0/24" + address_prefix = var.trex_dummy_cidr_port_1 next_hop_type = "VirtualAppliance" - next_hop_in_ip_address = "192.168.10.11" + next_hop_in_ip_address = data.azurerm_network_interface.dut1_if1.private_ip_address } route { name = "tg2" - address_prefix = "192.168.20.0/24" + address_prefix = var.vpc_cidr_d next_hop_type = "VirtualAppliance" - next_hop_in_ip_address = "192.168.10.11" + next_hop_in_ip_address = data.azurerm_network_interface.dut1_if1.private_ip_address } } @@ -266,27 +269,33 @@ resource "azurerm_route_table" "c" { disable_bgp_route_propagation = false route { name = "route-10" - address_prefix = "10.0.0.0/24" + address_prefix = var.trex_dummy_cidr_port_0 + next_hop_type = "VirtualAppliance" + next_hop_in_ip_address = data.azurerm_network_interface.dut1_if2.private_ip_address + } + route { + name = "route-100" + address_prefix = "100.0.0.0/8" next_hop_type = "VirtualAppliance" - next_hop_in_ip_address = "200.0.0.101" + next_hop_in_ip_address = data.azurerm_network_interface.dut1_if2.private_ip_address } route { name = "route-20" - address_prefix = "20.0.0.0/24" + address_prefix = var.trex_dummy_cidr_port_1 next_hop_type = "VirtualAppliance" - next_hop_in_ip_address = "200.0.0.102" + next_hop_in_ip_address = data.azurerm_network_interface.dut2_if1.private_ip_address } route { name = "tg1" - address_prefix = "192.168.10.0/24" + address_prefix = var.vpc_cidr_b next_hop_type = "VirtualAppliance" - next_hop_in_ip_address = "200.0.0.101" + next_hop_in_ip_address = data.azurerm_network_interface.dut1_if2.private_ip_address } route { name = "tg2" - address_prefix = "192.168.20.0/24" + address_prefix = var.vpc_cidr_d next_hop_type = "VirtualAppliance" - next_hop_in_ip_address = "200.0.0.102" + next_hop_in_ip_address = data.azurerm_network_interface.dut2_if1.private_ip_address } } @@ -299,21 +308,21 @@ resource "azurerm_route_table" "d" { disable_bgp_route_propagation = false route { name = "route-10" - address_prefix = "10.0.0.0/24" + address_prefix = var.trex_dummy_cidr_port_0 next_hop_type = "VirtualAppliance" - next_hop_in_ip_address = "192.168.20.11" + next_hop_in_ip_address = data.azurerm_network_interface.dut2_if2.private_ip_address } route { name = "route-20" - address_prefix = "20.0.0.0/24" + address_prefix = var.trex_dummy_cidr_port_1 next_hop_type = "VirtualAppliance" - next_hop_in_ip_address = "192.168.20.254" + next_hop_in_ip_address = data.azurerm_network_interface.tg_if2.private_ip_address } route { name = "tg1" - address_prefix = "192.168.10.0/24" + address_prefix = var.vpc_cidr_b next_hop_type = "VirtualAppliance" - next_hop_in_ip_address = "192.168.20.11" + next_hop_in_ip_address = data.azurerm_network_interface.dut2_if2.private_ip_address } } @@ -357,13 +366,12 @@ resource "azurerm_virtual_machine" "tg" { } os_profile { computer_name = "tg" - admin_username = "testuser" - admin_password = "Csit1234" + admin_username = "ubuntu" } os_profile_linux_config { - disable_password_authentication = false + disable_password_authentication = true ssh_keys { - path = "/home/testuser/.ssh/authorized_keys" + path = "/home/ubuntu/.ssh/authorized_keys" key_data = file("~/.ssh/id_rsa.pub") } } @@ -396,13 +404,12 @@ resource "azurerm_virtual_machine" "dut1" { } os_profile { computer_name = "dut1" - admin_username = "testuser" - admin_password = "Csit1234" + admin_username = "ubuntu" } os_profile_linux_config { - disable_password_authentication = false + disable_password_authentication = true ssh_keys { - path = "/home/testuser/.ssh/authorized_keys" + path = "/home/ubuntu/.ssh/authorized_keys" key_data = file("~/.ssh/id_rsa.pub") } } @@ -435,13 +442,12 @@ resource "azurerm_virtual_machine" "dut2" { } os_profile { computer_name = "dut2" - admin_username = "testuser" - admin_password = "Csit1234" + admin_username = "ubuntu" } os_profile_linux_config { - disable_password_authentication = false + disable_password_authentication = true ssh_keys { - path = "/home/testuser/.ssh/authorized_keys" + path = "/home/ubuntu/.ssh/authorized_keys" key_data = file("~/.ssh/id_rsa.pub") } } @@ -474,8 +480,9 @@ resource "null_resource" "deploy_tg" { azurerm_network_interface.tg_if1, azurerm_network_interface.tg_if2 ] connection { - user = "testuser" + user = "ubuntu" host = data.azurerm_public_ip.tg_public_ip.ip_address + private_key = file("~/.ssh/id_rsa") } provisioner "ansible" { plays { @@ -485,17 +492,8 @@ resource "null_resource" "deploy_tg" { } hosts = ["tg"] extra_vars = { - ansible_python_interpreter = "python3" + ansible_python_interpreter = "/usr/bin/python3" azure = true - remote_net = var.vpc_cidr_d - tg_if1_mac = azurerm_network_interface.tg_if1.mac_address - tg_if2_mac = azurerm_network_interface.tg_if2.mac_address - dut1_if1_mac = azurerm_network_interface.dut1_if1.mac_address - dut1_if2_mac = azurerm_network_interface.dut1_if2.mac_address - dut2_if1_mac = azurerm_network_interface.dut2_if1.mac_address - dut2_if2_mac = azurerm_network_interface.dut2_if2.mac_address - dut1_if1_ip = azurerm_network_interface.dut1_if1.private_ip_address - dut2_if2_ip = azurerm_network_interface.dut2_if2.private_ip_address } } } @@ -506,8 +504,9 @@ resource "null_resource" "deploy_dut1" { azurerm_network_interface.dut1_if1, azurerm_network_interface.dut1_if2 ] connection { - user = "testuser" + user = "ubuntu" host = data.azurerm_public_ip.dut1_public_ip.ip_address + private_key = file("~/.ssh/id_rsa") } provisioner "ansible" { plays { @@ -517,16 +516,8 @@ resource "null_resource" "deploy_dut1" { } hosts = ["sut"] extra_vars = { - ansible_python_interpreter = "python3" + ansible_python_interpreter = "/usr/bin/python3" azure = true - dut1_if1_ip = azurerm_network_interface.dut1_if1.private_ip_address - dut1_if1_mac = azurerm_network_interface.dut1_if1.mac_address - dut1_if2_ip = azurerm_network_interface.dut1_if2.private_ip_address - dut1_if2_mac = azurerm_network_interface.dut1_if2.mac_address - dut2_if2_ip = azurerm_network_interface.dut2_if1.private_ip_address - dut2_if1_gateway = azurerm_network_interface.dut2_if1.private_ip_address - traffic_if1 = var.trex_dummy_cidr_port_0 - traffic_if2 = var.trex_dummy_cidr_port_1 } } } @@ -537,8 +528,9 @@ resource "null_resource" "deploy_dut2" { azurerm_network_interface.dut2_if1, azurerm_network_interface.dut2_if2 ] connection { - user = "testuser" + user = "ubuntu" host = data.azurerm_public_ip.dut2_public_ip.ip_address + private_key = file("~/.ssh/id_rsa") } provisioner "ansible" { plays { @@ -548,16 +540,41 @@ resource "null_resource" "deploy_dut2" { } hosts = ["sut"] extra_vars = { - ansible_python_interpreter = "python3" + ansible_python_interpreter = "/usr/bin/python3" azure = true - dut2_if1_ip = azurerm_network_interface.dut2_if1.private_ip_address - dut2_if1_mac = azurerm_network_interface.dut2_if1.mac_address - dut2_if2_ip = azurerm_network_interface.dut2_if2.private_ip_address - dut2_if2_mac = azurerm_network_interface.dut2_if2.mac_address - dut1_if2_ip = azurerm_network_interface.dut1_if2.private_ip_address - dut1_if2_gateway = azurerm_network_interface.dut1_if2.private_ip_address - traffic_if1 = var.trex_dummy_cidr_port_0 - traffic_if2 = var.trex_dummy_cidr_port_1 + } + } + } +} + +resource "null_resource" "deploy_topology" { + depends_on = [ azurerm_virtual_machine.tg, + azurerm_network_interface.tg_if1, + azurerm_network_interface.tg_if2, + azurerm_virtual_machine.dut1, + azurerm_network_interface.dut1_if1, + azurerm_network_interface.dut1_if2, + azurerm_virtual_machine.dut2, + azurerm_network_interface.dut2_if1, + azurerm_network_interface.dut2_if2 ] + provisioner "ansible" { + plays { + playbook { + file_path = "../../testbed-setup/ansible/cloud_topology.yaml" + } + hosts = ["local"] + extra_vars = { + ansible_python_interpreter = "/usr/bin/python3" + cloud_topology = "azure" + tg_if1_mac = data.azurerm_network_interface.tg_if1.mac_address + tg_if2_mac = data.azurerm_network_interface.tg_if2.mac_address + dut1_if1_mac = data.azurerm_network_interface.dut1_if1.mac_address + dut1_if2_mac = data.azurerm_network_interface.dut1_if2.mac_address + dut2_if1_mac = data.azurerm_network_interface.dut2_if1.mac_address + dut2_if2_mac = data.azurerm_network_interface.dut2_if2.mac_address + tg_public_ip = data.azurerm_public_ip.tg_public_ip.ip_address + dut1_public_ip = data.azurerm_public_ip.dut1_public_ip.ip_address + dut2_public_ip = data.azurerm_public_ip.dut2_public_ip.ip_address } } }