Skip to content

proxmox_virtual_environment_container managing mount_points #1392

@GuillaumeSeren

Description

@GuillaumeSeren

Hey,
thank you for this great project I really enjoy it,
I think it is very usefull.

Describe the bug
When you try to add anonymous (non pre-created) mount_points (as documented here),
in a container like so you get an error:

# Here an example of the variable of a host list I got in my variable list
  "mycontainer" = {
    .. basic container params ..
    mount_points = [
      {
        path = "/mysql3"
        volume = "local"
        size   = "10G"
      }
    ]
  },
# Here the terrafrom plan / apply
└─> terraform plan
      - mount_point {
...
          - path          = "/mysql3" -> null
...
          - size          = "105G" -> null
          - volume        = "local:105/vm-105-disk-2.raw" -> null
        }

        # (8 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
...
# Here as the plan was fine, let's try to apply
└─> terraform apply
...
Terraform will perform the following actions:
...
      - mount_point {
          - acl           = false -> null
          - backup        = true -> null
          - mount_options = [] -> null
          - path          = "/mysql3" -> null
          - quota         = false -> null
          - read_only     = false -> null
          - replicate     = true -> null
          - shared        = false -> null
          - size          = "105G" -> null
          - volume        = "local:105/vm-105-disk-2.raw" -> null
        }

        # (8 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
...
  Enter a value: yes
...
Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

# If we try to plan again the same diff is as before is still here:
└─> terraform plan
...
  ~ update in-place

Terraform will perform the following actions:
...
      - mount_point {
          - acl           = false -> null
          - backup        = true -> null
          - mount_options = [] -> null
          - path          = "/mysql3" -> null
          - quota         = false -> null
          - read_only     = false -> null
          - replicate     = true -> null
          - shared        = false -> null
          - size          = "105G" -> null
          - volume        = "local:105/vm-105-disk-2.raw" -> null
        }

        # (8 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
...

To Reproduce
Here the code I use to manage that:

resource "proxmox_virtual_environment_container" "container" {
  for_each      = var.containers
  description   = each.value.description
  node_name     = var.node_name
  start_on_boot = true
  tags          = each.value.tags
  unprivileged  = true

  cpu {
    architecture = "amd64"
    cores        = each.value.cpu_cores
  }

  disk {
    datastore_id = var.ct_datastore_storage_location
    size         = each.value.disk_size
  }

  dynamic "mount_point" {
    for_each = each.value.mount_points != null ? each.value.mount_points : []

    content {
      size      = mount_point.value.size
      volume    = mount_point.value.volume
      path      = mount_point.value.path
      read_only = mount_point.value.read_only
    }
  }

  memory {
    dedicated = each.value.memory_dedicated
    swap      = each.value.memory_swap
  }

  operating_system {
    template_file_id = proxmox_virtual_environment_file.debian_container_template.id
    type             = var.os_type
  }

  initialization {
    hostname = each.value.hostname

    dns {
      domain = var.dns_domain
      server = var.dns_server
    }

    ip_config {
      ipv4 {
        address = each.value.ipv4_address
        gateway = each.value.ipv4_gateway
      }
    }

    user_account {
      keys     = var.ssh_keys
      password = random_password.container_root_password.result
    }
  }

  dynamic "network_interface" {
    for_each = each.value.network_interfaces
    content {
      name       = network_interface.value.name
      bridge     = network_interface.value.bridge
      rate_limit = network_interface.value.rate_limit
      firewall   = network_interface.value.firewall
    }
  }

  features {
    nesting = true
    fuse    = false
  }
}

Additional context

  • Single or clustered Proxmox:
  • Proxmox version:
  • Provider version (ideally it should be the latest version):
  • Terraform/OpenTofu version:
  • OS (where you run Terraform/OpenTofu from):
  • Debug logs (TF_LOG=DEBUG terraform apply):
# Here something interresting in the debug log
2024-06-14T17:01:56.485+0200 [WARN]  Provider "provider[\"registry.terraform.io/bpg/proxmox\"]" produced an unexpected new value for module.containers.proxmox_virtual_environment_container.container["mycontainer"], but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .mount_point: block count changed from 1 to 2
module.containers.proxmox_virtual_environment_container.container["mycontainer"]: Modifications complete after 0s [id=105]

Best,
Guillaume

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    📥 Inbox

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions