add variables related to the VM

This commit is contained in:
Vezpi 2025-03-21 22:47:25 +00:00
parent 753d5c38e4
commit 8e980d859c
3 changed files with 93 additions and 18 deletions

View File

@ -1,30 +1,30 @@
data "proxmox_virtual_environment_vms" "template" {
filter {
name = "name"
values = ["ubuntu-cloud"]
values = ["${var.vm_template}"]
}
}
resource "proxmox_virtual_environment_file" "cloud_config" {
content_type = "snippets"
datastore_id = "local"
node_name = "zenith"
node_name = var.node_name
source_raw {
file_name = "simple_vm.cloud-config.yaml"
file_name = "vm.cloud-config.yaml"
data = <<-EOF
#cloud-config
hostname: simple-vm
hostname: ${var.vm_name}
package_update: true
package_upgrade: true
packages:
- qemu-guest-agent
users:
- default
- name: vez
- name: ${var.vm_user}
groups: sudo
shell: /bin/bash
ssh-authorized-keys:
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID62LmYRu1rDUha3timAIcA39LtcIOny1iAgFLnxoBxm vez@bastion"
- "${var.vm_user_sshkey}"
sudo: ALL=(ALL) NOPASSWD:ALL
runcmd:
- systemctl enable qemu-guest-agent
@ -33,10 +33,10 @@ resource "proxmox_virtual_environment_file" "cloud_config" {
}
}
resource "proxmox_virtual_environment_vm" "simple_vm" {
name = "simple-vm"
node_name = "zenith"
tags = ["test"]
resource "proxmox_virtual_environment_vm" "vm" {
name = var.vm_name
node_name = var.node_name
tags = var.vm_tags
agent {
enabled = true
}
@ -44,23 +44,23 @@ resource "proxmox_virtual_environment_vm" "simple_vm" {
clone {
vm_id = data.proxmox_virtual_environment_vms.template.vms[0].vm_id
}
bios = "ovmf"
machine = "q35"
bios = var.vm_bios
machine = var.vm_machine
cpu {
cores = 2
cores = var.vm_cpu
type = "host"
}
memory {
dedicated = 2048
dedicated = var.vm_ram
}
disk {
datastore_id = "ceph-workload"
datastore_id = var.node_datastore
interface = "scsi0"
size = 4
}
initialization {
user_data_file_id = proxmox_virtual_environment_file.cloud_config.id
datastore_id = "ceph-workload"
datastore_id = var.node_datastore
interface = "scsi1"
ip_config {
ipv4 {
@ -70,7 +70,7 @@ resource "proxmox_virtual_environment_vm" "simple_vm" {
}
network_device {
bridge = "vmbr0"
vlan_id = 66
vlan_id = var.vm_vlan
}
operating_system {
type = "l26"
@ -81,7 +81,7 @@ resource "proxmox_virtual_environment_vm" "simple_vm" {
}
output "vm_ip" {
value = proxmox_virtual_environment_vm.simple_vm.ipv4_addresses[1][0]
value = proxmox_virtual_environment_vm.vm.ipv4_addresses[1][0]
description = "VM IP"
}

View File

@ -0,0 +1,5 @@
node_name = "zenith"
vm_name = "zenith-vm"
vm_cpu = 2
vm_ram = 2048
vm_vlan = 66

View File

@ -8,3 +8,73 @@ variable "proxmox_api_token" {
type = string
sensitive = true
}
variable "node_name" {
description = "Proxmox host for the VM"
type = string
}
variable "node_datastore" {
description = "Datastore used for VM storage"
type = string
default = "ceph-workload"
}
variable "vm_template" {
description = "Template of the VM"
type = string
default = "ubuntu-cloud"
}
variable "vm_name" {
description = "Hostname of the VM"
type = string
}
variable "vm_user" {
description = "Admin user of the VM"
type = string
default = "vez"
}
variable "vm_user_sshkey" {
description = "Admin user SSH key of the VM"
type = string
default = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID62LmYRu1rDUha3timAIcA39LtcIOny1iAgFLnxoBxm vez@bastion"
}
variable "vm_cpu" {
description = "Number of CPU cores of the VM"
type = number
default = 1
}
variable "vm_ram" {
description = "Number of RAM (MB) of the VM"
type = number
default = 2048
}
variable "vm_bios" {
description = "Type of BIOS used for the VM"
type = string
default = "ovmf"
}
variable "vm_machine" {
description = "Type of machine used for the VM"
type = string
default = "q35"
}
variable "vm_vlan" {
description = "VLAN of the VM"
type = number
default = 66
}
variable "vm_tags" {
description = "Tags for the VM"
type = list
default = ["test"]
}