Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multi network interface in initialization/ip_config/ipv4 #184

Closed
kaje783 opened this issue Dec 13, 2022 · 3 comments
Closed
Labels
✨ enhancement New feature or request

Comments

@kaje783
Copy link
Contributor

kaje783 commented Dec 13, 2022

Describe the bug
In the part "initialization/ip_config/ipv4" we can only configure 1 network.

The problem now arises when the VM has multiple networks and we want to configure them, this is currently not possible.

For information only:
Proxmox currently sets all other interfaces in the cloud-init part to static and the IP address remains empty.

To Reproduce

  1. terraform plan:

var.tf

variable "pve" {
	type = object({
		address    = string
		username   = string
		password   = string	
		insecure   = string	
	})
	sensitive = true
}

variable "vms" {
	type = list(object({
	  id          = number
	  name        = string
          node        = optional(string)
	  description = string
          type        = string
          config      = object({
		  template_name = string
	  })
          interfaces  = list(object({
		  id        		= number
                 name      		= string
                 network_id 		= number
                 ipv4_address  	= optional(string)
                 mac_address   	= optional(string)
          }))	
	}))
}

main.tf

terraform {
	required_providers {
        proxmox = {
            source = "bpg/proxmox"
            version = "0.8.0"
        }
	}
}

provider "proxmox" {
  virtual_environment {
    endpoint = var.pve.address
    username = var.pve.username
    password = var.pve.password
    insecure = var.pve.insecure
  }
}

resource "proxmox_virtual_environment_vm" "vms" {
    for_each            = { for vm in var.vms : vm.name => vm}

    name                = each.key
    node_name      = "proxmox01"
    started              = true
    timeout_shutdown_vm = 10


    dynamic "network_device" {
        for_each          = { for network in each.value.interfaces : network.id => network}
        content {
            model       = "e1000"
            mac_address = network_device.value.mac_address != null ? network_device.value.mac_address : ""
            bridge      = "vmbr0"
        }
    }

    initialization {
            ip_config {
                dynamic "ipv4" {
                    for_each = { for network in each.value.interfaces : network.id => network}
                    content {
                        address = ipv4.value.ipv4_address != null ? ipv4.value.ipv4_address : "dhcp"
                    }
                }
            }
    }
}
  1. See error
 Error: Too many ipv4 blocks
│ 
│   on main.tf line 106, in resource "proxmox_virtual_environment_vm" "vms":
│  106:                     content {
│ 
│ No more than 1 "ipv4" blocks are allowed

Expected behavior
Allow to configure as many ip-addresses as network interface are available.

@kaje783 kaje783 added the 🐛 bug Something isn't working label Dec 13, 2022
@bpg
Copy link
Owner

bpg commented Dec 13, 2022

@kaje783 thanks for the report. I'm going to re-label this as "enhancement" though, as this behaviour doesn't indicate a bug in the existing functionality.

@bpg bpg added ✨ enhancement New feature or request and removed 🐛 bug Something isn't working labels Dec 13, 2022
@bpg
Copy link
Owner

bpg commented Jan 1, 2023

Hey @kaje783, I'm closing this in favour of #197. You can find more details about the cloud-init network configuration here: https://cloudinit.readthedocs.io/en/latest/topics/network-config-format-v2.html

Feel free to re-open, if you think that approach won't work for you, or there are some other use cases that we should consider.

@bpg bpg closed this as completed Jan 1, 2023
@groggemans
Copy link
Contributor

groggemans commented Jan 2, 2023

I've actually had this use case working before by specifying multiple ip_config blocks instead of multiple ipv4 blocks within a single ip_config block. So @kaje783 you might want to give that a try. (it was a static config, so not sure if it will actually work in a dynamic block)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants