From bf87080e33e9eb9f5d15c4797e33f88e03fb1d4e Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Tue, 12 Dec 2023 19:34:05 +0530 Subject: [PATCH] feat: use macvtap to make VM accessible to CI machine --- terraform/mcaptcha/ci.tfvars | 9 +++++---- terraform/mcaptcha/mcaptcha.tf | 12 ++++++++---- terraform/mcaptcha/network_config.cfg | 1 + terraform/mcaptcha/output.tf | 2 +- terraform/mcaptcha/variables.tf | 12 ++++++++++++ 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/terraform/mcaptcha/ci.tfvars b/terraform/mcaptcha/ci.tfvars index 06edb9f..f1617d3 100644 --- a/terraform/mcaptcha/ci.tfvars +++ b/terraform/mcaptcha/ci.tfvars @@ -1,4 +1,5 @@ -libvirt_uri = "qemu+ssh://mcaptcha-ci@192.168.0.102/system?keyfile=/tmp/ci-ssh-id&sshauth=privkey&no_verify=1" -#known_hosts_verify=ignore&keyfile=/tmp/ssh-key&sshauth=privkey&no_verify=1" -libvirt_pool_path = "/home/mcaptcha-ci/libvirt/pool/mcaptcha_basic" -libvirt_debian_src = "http://192.168.0.102/debian-12-generic-amd64.qcow2" +libvirt_uri = "qemu+ssh://mcaptcha-ci@192.168.0.102/system?keyfile=/tmp/ci-ssh-id&sshauth=privkey&no_verify=1" +libvirt_pool_path = "/home/mcaptcha-ci/libvirt/pool/mcaptcha_basic" +libvirt_debian_src = "http://192.168.0.102/debian-12-generic-amd64.qcow2" +macvtap_ethernet_interface = "enp2s0" +ssh_public_key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBCYagT9/PXoeaUae7Z3BKOPKBiEvJsCTUIhPCcRp5fb mcaptcha-ci@hellbat.batsense.net" diff --git a/terraform/mcaptcha/mcaptcha.tf b/terraform/mcaptcha/mcaptcha.tf index 0c19bd5..26889c1 100644 --- a/terraform/mcaptcha/mcaptcha.tf +++ b/terraform/mcaptcha/mcaptcha.tf @@ -13,9 +13,10 @@ resource "libvirt_volume" "mcaptcha_volume" { resource "libvirt_domain" "mcaptcha_mcaptcha" { count = var.mcaptcha_vm_count - name = "mcaptcha_mcaptcha_${count.index}" - memory = var.mcaptcha_vm_memory - vcpu = var.mcaptcha_vm_vcpu + name = "mcaptcha_mcaptcha_${count.index}" + memory = var.mcaptcha_vm_memory + vcpu = var.mcaptcha_vm_vcpu + qemu_agent = true cloudinit = libvirt_cloudinit_disk.commoninit.id @@ -31,8 +32,9 @@ resource "libvirt_domain" "mcaptcha_mcaptcha" { target_port = "1" } + network_interface { - network_name = "default" + macvtap = var.macvtap_ethernet_interface wait_for_lease = true } @@ -41,6 +43,8 @@ resource "libvirt_domain" "mcaptcha_mcaptcha" { } } + + locals { mcaptcha_vm_ips = [for i in libvirt_domain.mcaptcha_mcaptcha : i.network_interface.0.addresses[0]] mcaptcha_vm_names = [for i in libvirt_domain.mcaptcha_mcaptcha : i.name] diff --git a/terraform/mcaptcha/network_config.cfg b/terraform/mcaptcha/network_config.cfg index 5b2cbca..4223aaa 100644 --- a/terraform/mcaptcha/network_config.cfg +++ b/terraform/mcaptcha/network_config.cfg @@ -2,3 +2,4 @@ version: 2 ethernets: ens3: dhcp4: true +# ip: 192.168.0.115 diff --git a/terraform/mcaptcha/output.tf b/terraform/mcaptcha/output.tf index 688a67e..4093d9c 100644 --- a/terraform/mcaptcha/output.tf +++ b/terraform/mcaptcha/output.tf @@ -12,7 +12,7 @@ resource "local_file" "hosts_yml" { { mcaptcha_vms_ips = local.mcaptcha_vm_ips, mcaptcha_vms_names = local.mcaptcha_vm_names, - mcaptcha_vms = local.mcaptcha_vm_map + mcaptcha_vms = local.mcaptcha_vm_map }) diff --git a/terraform/mcaptcha/variables.tf b/terraform/mcaptcha/variables.tf index 6bbfab4..246f128 100644 --- a/terraform/mcaptcha/variables.tf +++ b/terraform/mcaptcha/variables.tf @@ -44,3 +44,15 @@ variable "mcaptcha_vm_vcpu" { type = number default = 4 } + +variable "macvtap_ethernet_interface" { + description = "Ethernet interface on the host machine that can be used as macvtap" + type = string + default = "enp2s0" +} + +variable "ssh_public_key" { + description = "Set up SSH login for this public key" + type = string + default = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC/wXdHpwpY/4ubhYTmuNdGepQpj1kchvTUTApxMZyfyVW4uzrPRTYsle1y9QbTBV35qLkNajRC/wmC5/xPchdXpsJpuD9st1HMhLeR8qwaPyptiYJYT+z/WisWw2k6oWhG3QKvPoRtBdW9nhZnkG+O6zkuGXiRHpS7j2VVboDPpWEe1UdELQFVCwfraRal2g3ENFZ/9V1UrW/4ahRnQnSxERplZUm/fgSxQtmXubTkW68ut7yasBsrKFffMm8JztW0tWgTlTKONd3LCjv4juM0t5+cJDotNDnUR86Tq2PG8io7no/h8BWtazmjdpfGgn02ibX26BkdU0LDEYbJt5q9/Fh9TGk2ZwcMQeyepO1AWQgkmHXZWZELqu6MLQpqdtsOjHp9k0MeSpuIbdwzgf10Ydy7vK1z8irS24tVNNnJaMBwOlVOPwfyztHRADPkFcv2lKSjS1uyKR0FIkV8Kvs4txaIjmwv2LfMg6lF5W6j3ZPLyeE4cplJP0DDjzorSanu31xVnqVb3A8V9awsJ/4H7d59bI99c7QHL4K3fBVP3O0gqd31xAVRsdGs5Tj2P+RpiI6o5JJiOa1+DuBdWzrVIXYchQ30ZjaJp1wTNsYLmAsjeYuQZE2tf1xvywdzD4MB4avugDEWikzRWN9V5PHDZr1bamTCCjOrb2PRCd7eSQ== aravinth7820@gmail.com" +}