feat: use macvtap to make VM accessible to CI machine

This commit is contained in:
Aravinth Manivannan 2023-12-12 19:34:05 +05:30
parent 0306798bad
commit bf87080e33
Signed by: realaravinth
GPG Key ID: F8F50389936984FF
5 changed files with 27 additions and 9 deletions

View File

@ -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"

View File

@ -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]

View File

@ -2,3 +2,4 @@ version: 2
ethernets:
ens3:
dhcp4: true
# ip: 192.168.0.115

View File

@ -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
})

View File

@ -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"
}