Giter VIP home page Giter VIP logo

Comments (7)

coltonshipley avatar coltonshipley commented on August 9, 2024 1

@bpg ,

Actually, I think I got it figured out. I'm working though some other issues now for my particular use case (I'm totally new to terraform as well so I'm learning as I got) However, as of now I did get cloud-init working properly with the centos9 generic cloud image (mostly). I'll tinker some more in the coming days and update.

from terraform-provider-proxmox.

resnostyle avatar resnostyle commented on August 9, 2024

This documentation example here goes exactly into what you're looking to do.
https://registry.terraform.io/providers/bpg/proxmox/latest/docs/guides/cloud-init
I cant get the formating right, but you shouldn't have to upload the cloud config, terraform can do it all.

The specific parts are this.
initialization { ip_config { ipv4 { address = "dhcp" } } user_data_file_id = proxmox_virtual_environment_file.cloud_config.id }

`resource "proxmox_virtual_environment_file" "cloud_config" {
content_type = "snippets"
datastore_id = "local"
node_name = "pve"

source_raw {
data = <<EOF
#cloud-config
users:

  • default

  • name: ubuntu
    groups:

    • sudo
      shell: /bin/bash
      ssh_authorized_keys:
    • ${trimspace(data.local_file.ssh_public_key.content)}
      sudo: ALL=(ALL) NOPASSWD:ALL
      runcmd:
    • apt update
    • apt install -y qemu-guest-agent net-tools
    • timedatectl set-timezone America/Toronto
    • systemctl enable qemu-guest-agent
    • systemctl start qemu-guest-agent
    • echo "done" > /tmp/cloud-config.done
      EOF

    file_name = "cloud-config.yaml"
    }
    }`

from terraform-provider-proxmox.

coltonshipley avatar coltonshipley commented on August 9, 2024

Thanks, I was hoping there was a way without having to upload it. I understand terraform can do the upload for me, but the file still lives on the proxmox box. So, then it becomes hard to determine which node needs the file, lets say you want 3 instances and you have 5 nodes, but you don't really care where the vm ends up. Although I think I might have ideas on how to tackle that.

from terraform-provider-proxmox.

coltonshipley avatar coltonshipley commented on August 9, 2024

So I tried the example and it doesn't seem to be taking any of the cloud config. Also to add to this, if you use user_account in the initialization block, it doesn't work along with the user-data.

Here is my main.tf

data "proxmox_virtual_environment_nodes" "available_nodes" {}

resource "proxmox_virtual_environment_vm" "virtual_machine" {
  count = 1
  name        = "${format("nomadagent%02d.localdomain", count.index + 4)}"
  node_name   = element(data.proxmox_virtual_environment_nodes.available_nodes.names, count.index)
  tags        = ["terraform"]
  description = "Managed by Terraform."

  agent {
    enabled = true
  }

  initialization {
    datastore_id = "unraid"

    user_data_file_id = proxmox_virtual_environment_file.cloud_config.id

    ip_config {
      ipv4 {
        address = "dhcp"
      }
    }
  }

  cpu {
    cores = 8
    numa  = true
    type  = "host"    
  }

  memory {
    dedicated = 32768
  }  

  disk {
    datastore_id = "pve-storage-ssd-ceph"
    file_id      = proxmox_virtual_environment_download_file.centos9_cloud_image.id
    interface    = "scsi0"
    iothread     = false
    discard      = "on"
    size         = 80
    ssd          = "true"
  }

  network_device {
    bridge = "vmbr0"
  }  
}

resource "proxmox_virtual_environment_file" "cloud_config" {
  content_type = "snippets"
  datastore_id = "unraid"
  node_name    = "pve1"

  source_raw {
    data = <<EOF
#cloud-config
password: securepassword
chpasswd: { expire: False }
ssh_pwauth: True

repo_update: true
repo_upgrade: all
repos:
  saltstack:
    baseurl: https://repo.saltproject.io/py3/redhat/9/x86_64/latest/
    gpgcheck: true
    gpgkey: https://repo.saltproject.io/py3/redhat/9/x86_64/latest/SALTSTACK-GPG-KEY.pub
    enabled: true

packages:
  - salt-minion
    EOF

    file_name = "cloud-config.yaml"
  }
}

resource "proxmox_virtual_environment_download_file" "centos9_cloud_image" {
  content_type = "iso"
  datastore_id = "unraid"
  node_name    = "pve1"
  url          = "https://cloud.centos.org/centos/9-stream/x86_64/images/CentOS-Stream-GenericCloud-9-latest.x86_64.qcow2"
  file_name    = "CentOS-Stream-GenericCloud-9-latest.x86_x64.img"
}

from terraform-provider-proxmox.

bpg avatar bpg commented on August 9, 2024

Hi @coltonshipley! 👋🏼

Thanks, I was hoping there was a way without having to upload it. I understand terraform can do the upload for me, but the file still lives on the proxmox box. So, then it becomes hard to determine which node needs the file, lets say you want 3 instances and you have 5 nodes, but you don't really care where the vm ends up. Although I think I might have ideas on how to tackle that.

Unfortunately, Proxmox does not provide an API for that. It can either generate the cloud-init "on-the-fly" from individual parameters (username, password, keys, etc), or take it as a whole when referenced by a file ID from a datastore. So in the clustered environment a shared datastore (cephfs, NFS, etc) is the most convenient way to manage that file.

Also to add to this, if you use user_account in the initialization block, it doesn't work along with the user-data.

This is a known limitation of the available PVE API as explained above, documented here.

So I tried the example and it doesn't seem to be taking any of the cloud config.

The cloud-init processing on the VM is a sole responsibility of the OS it bootstraps with. I've seen a number of issues with different version of CentOS and Ubuntu where the same cloud init worked on one version but did not work on another.

I'm regularly testing the Ubuntu cloud-init example, so I have a bit of confidence that it works. I know other people successfully used centos8 with cloud-init.

How do you check if cloud init is applied or not? Could you provide some additional details?
Perhaps check cloud init logs on the VM, if there anything relevant there?

One thing I noted, your template has agent enabled, which means the OS you're provisioning must have the qemu agent package installed, but it is missing from your cloud-init config.

And lastly, you can check #586 if anything from there is applicable to your use case.

from terraform-provider-proxmox.

bpg avatar bpg commented on August 9, 2024

Hey @coltonshipley, do you need any more help with your configuration?

from terraform-provider-proxmox.

EugenMayer avatar EugenMayer commented on August 9, 2024

@coltonshipley just wanted to second @bpg that cloud-init and the support is massively determined by the OS used.

Usually, ubuntu, plays out the best du the the roots of cloud init (AFAICS canonical spawned cloud-init and is one of the main drivers).
For example, debian, even though ubuntu is based on debian, does not support half of the cloud-init things. Network and even user, ssh key management fails to properly work.

But, that said, proxmox (not the the tf provider here) plays a role too and generally does a rather mediocre job. So my cloud-init experiences with debian under openstack are much better then with proxmox, just due to the reason that openstack does use own tools base on DHCP and other things (metdata server) to fix network and ssh keys.

All that said, terraform-provider-proxmox is entirely un-involved in the process. I tried cloud-init on proxmox for years now, and it slowly got better.

from terraform-provider-proxmox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.