82 lines
No EOL
1.8 KiB
HCL
82 lines
No EOL
1.8 KiB
HCL
terraform {
|
|
required_version = ">= 1.0"
|
|
required_providers {
|
|
proxmox = {
|
|
source = "bpg/proxmox"
|
|
version = "~> 0.84.1"
|
|
}
|
|
}
|
|
}
|
|
|
|
provider "proxmox" {
|
|
endpoint = var.proxmox_api_url
|
|
api_token = "${var.proxmox_token_id}=${var.proxmox_token_secret}"
|
|
insecure = var.proxmox_tls_insecure
|
|
}
|
|
|
|
data "proxmox_virtual_environment_vms" "all_vms" {
|
|
node_name = var.proxmox_node
|
|
}
|
|
|
|
#locals {
|
|
# template_vms = [
|
|
# for vm in data.proxmox_virtual_environment_vms.all_vms.vms : vm
|
|
# if vm.name == var.vm_template
|
|
# ]
|
|
# template_vm_id = length(local.template_vms) > 0 ? local.template_vms[0].vm_id : null
|
|
#}
|
|
|
|
resource "proxmox_virtual_environment_vm" "ubuntu_vm" {
|
|
name = var.vm_name
|
|
node_name = var.proxmox_node
|
|
|
|
clone {
|
|
vm_id = var.template_vm_id
|
|
full = true
|
|
}
|
|
|
|
# VM Hardware Configuration
|
|
cpu {
|
|
cores = var.vm_cores
|
|
sockets = var.vm_sockets
|
|
}
|
|
|
|
memory {
|
|
dedicated = var.vm_memory
|
|
}
|
|
|
|
disk {
|
|
datastore_id = var.vm_disk_storage
|
|
size = var.vm_disk_size
|
|
interface = var.vm_disk_type
|
|
}
|
|
|
|
agent {
|
|
enabled = false
|
|
}
|
|
|
|
# Network Configuration
|
|
network_device {
|
|
bridge = var.vm_network_bridge
|
|
model = var.vm_network_model
|
|
}
|
|
|
|
# Cloud-Init Configuration
|
|
initialization {
|
|
user_account {
|
|
username = var.vm_ci_user
|
|
password = var.vm_ci_password
|
|
keys = var.vm_ssh_keys != "" ? [file(var.vm_ssh_keys)] : []
|
|
}
|
|
|
|
ip_config {
|
|
ipv4 {
|
|
address = var.vm_ip_config != "" && var.vm_ip_config != "ip=dhcp" ? split(",", var.vm_ip_config)[0] : "dhcp"
|
|
gateway = var.vm_ip_config != "" && var.vm_ip_config != "ip=dhcp" ? split("=", split(",", var.vm_ip_config)[1])[1] : null
|
|
}
|
|
}
|
|
}
|
|
|
|
# Tags
|
|
tags = split(",", var.vm_tags)
|
|
} |