Comments (7)
@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.
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"
}
}` - sudo
from terraform-provider-proxmox.
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.
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.
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.
Hey @coltonshipley, do you need any more help with your configuration?
from terraform-provider-proxmox.
@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)
- Cannot use cloudinit with initialization HOT 1
- Disk resize for VM not updated in terraform state HOT 14
- CD-ROM is not attached when creating a VM from scratch HOT 1
- Not sure why I have these issue HOT 2
- Cannot Set Disk Passthrough Serial
- Terraform unable to set CIUPGRADE config, regardless of running as root or not, using API token HOT 3
- proxmox_virtual_environment_user_token is not idempotent if no expiration_date is set HOT 1
- Idempotence issues in "proxmox_virtual_environment_vm" after cloning from another VM HOT 3
- Support provider_override HOT 4
- Document which is the latest compatible version for Proxmox 7.4 HOT 1
- Align Defaults with Proxmox Defaults HOT 1
- Error: unknown time zone HOT 3
- HTTP 596 response Connection timed out in proxmox_virtual_environment_file HOT 1
- disk resize fails: error waiting for VM disk resize: All attempts fail: HOT 2
- Allow VM clone to pass with warnings HOT 3
- Missing "none" and "VirGL" to VGA type in proxmox_vm proxmox_virtual_environment_vm HOT 1
- Container volume mount backup flag defaults to true in provider but false in Proxmox, so volume mounts are created with the flag missing. HOT 1
- 0.58.0 VM resource: `expected clipboard to be one of ["vnc"], got .` HOT 1
- Selection of the components you want to be hotpluggable HOT 1
- error creating clonr vm linked clone HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terraform-provider-proxmox.