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

Cannot get IP address via cloudinit . #1166

Open
mgrkisiek opened this issue Nov 22, 2024 · 2 comments
Open

Cannot get IP address via cloudinit . #1166

mgrkisiek opened this issue Nov 22, 2024 · 2 comments

Comments

@mgrkisiek
Copy link

mgrkisiek commented Nov 22, 2024

Hi
I can't get IP address if cloud_init_disk was created by me and attached to OS .

I followed documentation
https://registry.terraform.io/providers/Telmate/proxmox/latest/docs/resources/cloud_init_disk
and
https://registry.terraform.io/providers/Telmate/proxmox/latest/docs/resources/vm_qemu

Terraform version v1.9.8

Part of code responsible for creating CI disk

`
resource "proxmox_cloud_init_disk" "ci" {
name = "${var.vm_name}-ansible-controler"
pve_node = "${var.proxmox_cluster}"
storage = "${var.iso_storage_pool}"

meta_data = yamlencode({
instance_id = "sha1${var.vm_name}-ansible-controler"
local-hostname = "${var.vm_name}-ansible-controler"
})

user_data = <<-EOT
#cloud-config
users:
- name: kisiek
gecos: Name here
primary_group: kisiek
groups: wheel
sudo: ALL=(ALL) NOPASSWD:ALL
lock_passwd: false
passwd: passwordhere
ssh_authorized_keys:
- ssh-rsa Key here
packages:
- git
- mc
- qemu-guest-agent
EOT
vendor_data = <<-EOT
#cloud-config
ssh_pwauth: true

EOT
network_config = yamlencode({
version = 1
config = [{
type = "physical"
name = "eth0"
subnets = [{
type = "dhcp"
}]
}]
})

}
`

Part of Code to create machine

`
resource "proxmox_vm_qemu" "ansible_nat_controller" {
name = "${var.vm_name}-ansible-controler"
desc = "tf description"
target_node = "${var.proxmox_cluster}"
vmid = "7010"

clone = "Rocky-9-Template"

The destination resource pool for the new VM

#pool = "pool0"
agent = 1
os_type = "cloud-init"
cores = 3
sockets = 1
memory = 2560
scsihw = "virtio-scsi-pci"
full_clone = "true"

serial {
id = 0
}

disks {
scsi {
scsi0 {
disk {
storage = "local"
size = "50G"
format = "qcow2"
}
}
scsi1 {
cdrom {
iso = "${proxmox_cloud_init_disk.ci.id}"
}
}
}

}

Mac adrress required to get static IP

network {
model = "virtio"
bridge = "vmbr1"
macaddr = "a6:1a:55:9f:e7:10"
}
}
`

Part of generating IP addresses

resource "local_file" "hosts_cfg" { content = templatefile("inventory.tmpl", { node_hosts = proxmox_vm_qemu.cloudinit.*.default_ipv4_address ansible_nat_controller = proxmox_vm_qemu.ansible_nat_controller.*.default_ipv4_address } ) filename = "./install/inventory.ini"

Result is that
local_file.hosts_cfg: Creating... local_file.hosts_cfg: Creation complete after 0s [id=ecb4fc8d75daadf00e4d30a598184ae366057263] ╷ │ Warning: Cloud-init is enabled but no IP config is set │ │ with proxmox_vm_qemu.ansible_nat_controller, │ on main.tf line 115, in resource "proxmox_vm_qemu" "ansible_nat_controller": │ 115: resource "proxmox_vm_qemu" "ansible_nat_controller" { │ │ Cloud-init is enabled in your configuration but no static IP address is │ set, nor is the DHCP option enabled ╵

@TomyLobo
Copy link

I have a similar issue (although without ever doing anything with cloud-init).
I just went up an down the source code to figure this out.
It has something to do with that warning about Cloud-init being enabled with no IP config set.
That code path pre-empts the IP from the agent, so that even if the web UI shows the IP, the terraform provider cannot see it.

@TomyLobo
Copy link

I fixed my issue with ipconfig0 = "ip=dhcp"

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

No branches or pull requests

2 participants