Files
iac-opentofu-public/proxmox.tf
2025-08-20 18:15:27 +00:00

94 lines
2.5 KiB
HCL

provider "proxmox" {
endpoint = var.proxmox_server
api_token = var.proxmox_apikey
ssh {
agent = true
username = "terraform"
}
}
resource "proxmox_virtual_environment_download_file" "Fedora-iso" {
content_type = "iso" # tipo do arquivo
datastore_id = "local" # datastore do Proxmox onde o arquivo será guardado
node_name = "fenix" # nó do Proxmox onde será armazenado
file_name = "IAC-Fedora-Workstation-Live-x86_64-41-1.4.iso"
url = "https://download.fedoraproject.org/pub/fedora/linux/releases/41/Workstation/x86_64/iso/Fedora-Workstation-Live-x86_64-41-1.4.iso"
}
resource "proxmox_virtual_environment_vm" "proxmox-kubernetes-VM-template" {
depends_on = [proxmox_virtual_environment_download_file.Fedora-iso]
name = "proxmox-kubernetes-VM-template"
node_name = "fenix"
vm_id = 1002
template = true
started = false
agent {
enabled = true
}
tags = ["opentofu", "kubernetes", "fedora"]
machine = "q35"
bios = "seabios"
description = "kubernetes VM Template created via iac"
cpu {
cores = 2
}
memory {
dedicated = 4096
}
# Configuração do disco rígido
disk {
datastore_id = "local-lvm"
interface = "scsi0"
size = 64
}
# Configuração da interface de rede
network_device {
bridge = "vmbr0"
model = "virtio"
}
# Configuração do CD-ROM com a ISO
cdrom {
file_id = proxmox_virtual_environment_download_file.Fedora-iso.id
}
initialization {
ip_config {
ipv4 {
address = "192.168.1.24/24" # IP estático + máscara de rede
gateway = "192.168.1.1" # Gateway da rede
}
}
user_account {
password = "passexemplo"
username = "userexemplo"
}
}
}
resource "proxmox_virtual_environment_vm" "VM-Kubernetes-01" {
name = "VM-Kubernetes-01"
node_name = "fenix"
clone {
vm_id = proxmox_virtual_environment_vm.proxmox-kubernetes-VM-template.id
}
agent {
# NOTE: The agent is installed and enabled as part of the cloud-init configuration in the template VM, see cloud-config.tf
# The working agent is *required* to retrieve the VM IP addresses.
# If you are using a different cloud-init configuration, or a different clone source
# that does not have the qemu-guest-agent installed, you may need to disable the `agent` below and remove the `vm_ipv4_address` output.
# See https://registry.terraform.io/providers/bpg/proxmox/latest/docs/resources/virtual_environment_vm#qemu-guest-agent for more details.
enabled = false
}
}