add package upgrades and output of VM IP

This commit is contained in:
Vezpi 2025-03-21 21:57:26 +00:00
parent a39d0ceacb
commit 753d5c38e4
3 changed files with 28 additions and 19 deletions

View File

@ -1,8 +1,8 @@
data "proxmox_virtual_environment_vms" "template" { data "proxmox_virtual_environment_vms" "template" {
filter { filter {
name = "name" name = "name"
values = ["ubuntu-cloud"] values = ["ubuntu-cloud"]
} }
} }
resource "proxmox_virtual_environment_file" "cloud_config" { resource "proxmox_virtual_environment_file" "cloud_config" {
@ -11,9 +11,11 @@ resource "proxmox_virtual_environment_file" "cloud_config" {
node_name = "zenith" node_name = "zenith"
source_raw { source_raw {
file_name = "simple_vm.cloud-config.yaml" file_name = "simple_vm.cloud-config.yaml"
data = <<-EOF data = <<-EOF
#cloud-config #cloud-config
hostname: simple-vm hostname: simple-vm
package_update: true
package_upgrade: true
packages: packages:
- qemu-guest-agent - qemu-guest-agent
users: users:
@ -25,7 +27,8 @@ resource "proxmox_virtual_environment_file" "cloud_config" {
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID62LmYRu1rDUha3timAIcA39LtcIOny1iAgFLnxoBxm vez@bastion" - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID62LmYRu1rDUha3timAIcA39LtcIOny1iAgFLnxoBxm vez@bastion"
sudo: ALL=(ALL) NOPASSWD:ALL sudo: ALL=(ALL) NOPASSWD:ALL
runcmd: runcmd:
- systemctl enable --now qemu-guest-agent - systemctl enable qemu-guest-agent
- reboot
EOF EOF
} }
} }
@ -41,24 +44,24 @@ resource "proxmox_virtual_environment_vm" "simple_vm" {
clone { clone {
vm_id = data.proxmox_virtual_environment_vms.template.vms[0].vm_id vm_id = data.proxmox_virtual_environment_vms.template.vms[0].vm_id
} }
bios = "ovmf" bios = "ovmf"
machine = "q35" machine = "q35"
cpu { cpu {
cores = 2 cores = 2
type = "host" type = "host"
} }
memory { memory {
dedicated = 2048 dedicated = 2048
} }
disk { disk {
datastore_id = "ceph-workload" datastore_id = "ceph-workload"
interface = "scsi0" interface = "scsi0"
size = 4 size = 4
} }
initialization { initialization {
user_data_file_id = proxmox_virtual_environment_file.cloud_config.id user_data_file_id = proxmox_virtual_environment_file.cloud_config.id
datastore_id = "ceph-workload" datastore_id = "ceph-workload"
interface = "scsi1" interface = "scsi1"
ip_config { ip_config {
ipv4 { ipv4 {
address = "dhcp" address = "dhcp"
@ -66,7 +69,7 @@ resource "proxmox_virtual_environment_vm" "simple_vm" {
} }
} }
network_device { network_device {
bridge = "vmbr0" bridge = "vmbr0"
vlan_id = 66 vlan_id = 66
} }
operating_system { operating_system {
@ -76,3 +79,9 @@ resource "proxmox_virtual_environment_vm" "simple_vm" {
type = "std" type = "std"
} }
} }
output "vm_ip" {
value = proxmox_virtual_environment_vm.simple_vm.ipv4_addresses[1][0]
description = "VM IP"
}

View File

@ -1,18 +1,18 @@
terraform { terraform {
required_providers { required_providers {
proxmox = { proxmox = {
source = "bpg/proxmox" source = "bpg/proxmox"
} }
} }
} }
provider "proxmox" { provider "proxmox" {
endpoint = var.proxmox_endpoint endpoint = var.proxmox_endpoint
api_token = var.proxmox_api_token api_token = var.proxmox_api_token
insecure = false insecure = false
ssh { ssh {
agent = false agent = false
private_key = file("~/.ssh/id_ed25519") private_key = file("~/.ssh/id_ed25519")
username = "root" username = "root"
} }
} }

View File

@ -6,5 +6,5 @@ variable "proxmox_endpoint" {
variable "proxmox_api_token" { variable "proxmox_api_token" {
description = "Proxmox API token" description = "Proxmox API token"
type = string type = string
sensitive = true sensitive = true
} }