Renamed folder

This commit is contained in:
Littlefoot
2025-05-19 14:09:59 +00:00
parent e2b5b2bf18
commit 05944e9445
2 changed files with 0 additions and 0 deletions

112
cloud-init-vm/main.tf Normal file
View File

@@ -0,0 +1,112 @@
# Initializes a new Proxmox VM given a specific cloud-init image, and attempts to enroll it in FreeIPA
terraform {
required_providers {
proxmox = {
source = "bpg/proxmox"
version = "0.78.0"
}
}
}
provider "proxmox" {
endpoint = var.api_url
api_token = "${var.proxmox_token_id}=${var.proxmox_token_secret}"
insecure = true
# Needed for snippet upload
ssh {
agent = false
username = var.proxmox_ssh_username
password = var.proxmox_ssh_password
}
}
# Cloud-init user config snippet
resource "proxmox_virtual_environment_file" "user_data_cloud_config" {
content_type = "snippets"
datastore_id = "local"
node_name = var.proxmox_node_name
source_raw {
data = <<-EOF
#cloud-config
hostname: ${var.vm_hostname}
fqdn: ${var.vm_hostname}
prefer_fqdn_over_hostname: true
package_update: true
packages:
- qemu-guest-agent
- net-tools
- curl
- freeipa-client
runcmd:
- systemctl enable qemu-guest-agent
- systemctl start qemu-guest-agent
- ipa-client-install --mkhomedir --unattended --principal ${var.freeipa_enrollment_principal} --password ${var.freeipa_enrollment_password}
- echo "done" > /tmp/cloud-config.done
EOF
file_name = "user-data-cloud-config.yaml"
}
}
# Downloads a given cloud image file to use, and uploads it to proxmox
resource "proxmox_virtual_environment_download_file" "vm_cloud_image" {
content_type = "iso"
datastore_id = "local"
node_name = var.proxmox_node_name
url = var.image_url
file_name = var.image_file_name
}
# Provisions a new VM using the above image and cloud-init snippet
resource "proxmox_virtual_environment_vm" "cloud_vm" {
name = var.vm_hostname
node_name = var.proxmox_node_name
# Enables qemu agent
agent {
enabled = true
}
cpu {
cores = var.cores
# Should speed up CPU
type ="x86-64-v2-AES"
}
memory {
dedicated = var.memory
}
disk {
datastore_id = var.disk_storage
file_id = proxmox_virtual_environment_download_file.vm_cloud_image.id
interface = "scsi0"
iothread = false
discard = "ignore"
size = var.disk_size
}
initialization {
ip_config {
ipv4 {
address = var.ipv4_address
gateway = var.ipv4_gateway
}
}
dns {
domain = var.dns_domain
servers = var.dns_servers
}
user_data_file_id = proxmox_virtual_environment_file.user_data_cloud_config.id
}
network_device {
bridge = var.network_bridge_device
}
}