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

allow using dynamic list for ipconfig instead of hardcoding the index in the key #866

Merged
merged 2 commits into from
Dec 6, 2023

Conversation

spettinichi
Copy link
Contributor

When trying to use this provider it is difficult to create a variable amount of static IP addresses which are unknown until install time. The quantity of network interfaces can be handled variably but the accompanying static IP addresses does not work to go along with that.
I have modified this to allow dynamic IP addresses to be created while maintaining backwards compatibility for the current way of explicitly setting ipconfig0, ipconfig1, etc.

To give an example of my desired usage:

variables.tf:

variable "networks" {
  description = "defines NICs for the vm"
  type = list(object({
    model           = optional(string)
    bridge          = optional(string)
    vlan_tag        = optional(number)
    gateway         = optional(string)
    ip_address      = optional(string)
    cidr_annotation = optional(string)
  }))
  default = [{
    model           = "virtio"
    bridge          = "vmbr0"
    vlan_tag        = null
    gateway         = "10.0.0.1"
    cidr_annotation = "20"
    ip_address      = null
  }]
}

main.tf

dynamic "network" {
    for_each = var.networks
    content {
      model  = network.value.model
      bridge = network.value.bridge
      tag    = network.value.vlan_tag
    }
  }

  dynamic "ipconfig" {
    for_each = var.networks
    content {
      config = "ip=${network.value.ip_address}/${network.value.cidr_annotation},gw=${network.value.gateway}"
    }
  }

@spettinichi spettinichi marked this pull request as draft November 20, 2023 19:20
@glloyd-awetomaton
Copy link

This functionality would be great! It makes it much easier to use this resource type within a module.

@spettinichi spettinichi marked this pull request as ready for review November 21, 2023 12:54
@mleone87 mleone87 merged commit d02bb5d into Telmate:master Dec 6, 2023
1 check passed
spettinichi added a commit to spettinichi/terraform-provider-proxmox that referenced this pull request Mar 12, 2024
… in the key (Telmate#866)

* allow using dynamic list for ipconfig instead of hardcoding the index in the key

* adding documentation

---------

Co-authored-by: sammy <sammy@email.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants