dmacvicar / terraform-provider-libvirt

Terraform provider to provision infrastructure with Linux's KVM using libvirt
Apache License 2.0
1.54k stars 457 forks source link

How to enable inbound/outbound traffic with no restrictions to a VM #1006

Closed LavBU closed 1 year ago

LavBU commented 1 year ago

System Information

Linux distribution

Centos7

Terraform version

terraform -v

Terraform v1.3.9
on linux_amd64
+ provider registry.terraform.io/dmacvicar/libvirt v0.7.1
+ provider registry.terraform.io/hashicorp/template v2.2.0

Provider and libvirt versions

terraform-provider-libvirt -version

libvirtd (libvirt) 4.5.0

__

Description of Issue/Question

I deploy a VM with no issues. but have issues with the network connection to it as follows:

When using Bridge mode:

When using NAT mode:

I notice that when using "nat" mode, the physical host gets iptables roles which block the connections. but even if deleting iptables rules, the connections are still blocked.

Setup

Relevant main.tf part (in nat mode):

resource "libvirt_network" "vm_main_network" {
  name = "${var.VM_HOSTNAME}_network"
  mode = "nat"
  domain = "${var.VM_HOSTNAME}.local"
  addresses = ["${var.VM_MAIN_RANGE}"]
  dhcp {
   enabled = false
  }
  dns {
   enabled = true
  }
}

resource "libvirt_domain" "vm" {
  count = var.VM_COUNT
  name = "${var.VM_HOSTNAME}-${count.index}"
  memory = var.VMEM
  vcpu = var.VCPU
  cloudinit = "${libvirt_cloudinit_disk.cloudinit.id}"
  network_interface {
    network_id = "${libvirt_network.vm_main_network.id}"
    network_name = "${libvirt_network.vm_main_network.name}"
    addresses      = ["${var.IP_MAIN}"]
  }

Additional information:

I'm trying to find a way, which will allows me to reach the new deployed VM from any server on my network (which has a route to the VM physical host) as well to be able to connect any server from inside the VM.

Appreciate any help.

Thanks, Lavi

LavBU commented 1 year ago

I used a wrong default gateway. in bridge mode inbound and outbound traffic is working with no restrictions.