PoC OpenTofu configuration works
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
||||
.envrc
|
||||
.terraform
|
||||
.terraform.*
|
||||
terraform*
|
||||
id_*
|
||||
|
||||
36
clone.tf
Normal file
36
clone.tf
Normal file
@@ -0,0 +1,36 @@
|
||||
resource "proxmox_virtual_environment_vm" "ubuntu_clone" {
|
||||
name = "ubuntu-clone"
|
||||
node_name = var.virtual_environment_node_name
|
||||
|
||||
clone {
|
||||
vm_id = proxmox_virtual_environment_vm.ubuntu_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://bpg.sh/docs/resources/virtual_environment_vm#qemu-guest-agent for more details.
|
||||
enabled = true
|
||||
}
|
||||
|
||||
memory {
|
||||
dedicated = 768
|
||||
}
|
||||
|
||||
initialization {
|
||||
dns {
|
||||
servers = ["1.1.1.1"]
|
||||
}
|
||||
ip_config {
|
||||
ipv4 {
|
||||
address = "dhcp"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
output "vm_ipv4_address" {
|
||||
value = proxmox_virtual_environment_vm.ubuntu_clone.ipv4_addresses[1][0]
|
||||
}
|
||||
37
cloud-conf.tf
Normal file
37
cloud-conf.tf
Normal file
@@ -0,0 +1,37 @@
|
||||
data "local_file" "ssh_public_key" {
|
||||
filename = "./id_ed25519_rocky.pub"
|
||||
}
|
||||
|
||||
resource "proxmox_virtual_environment_file" "user_data_cloud_config" {
|
||||
content_type = "snippets"
|
||||
datastore_id = "local"
|
||||
node_name = var.virtual_environment_node_name
|
||||
|
||||
source_raw {
|
||||
data = <<-EOF
|
||||
#cloud-config
|
||||
hostname: test-ubuntu
|
||||
timezone: Europe/Berlin
|
||||
users:
|
||||
- default
|
||||
- name: ubuntu
|
||||
groups:
|
||||
- sudo
|
||||
shell: /bin/bash
|
||||
ssh_authorized_keys:
|
||||
- ${trimspace(data.local_file.ssh_public_key.content)}
|
||||
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||
package_update: true
|
||||
packages:
|
||||
- qemu-guest-agent
|
||||
- net-tools
|
||||
- curl
|
||||
runcmd:
|
||||
- systemctl enable qemu-guest-agent
|
||||
- systemctl start qemu-guest-agent
|
||||
- echo "done" > /tmp/cloud-config.done
|
||||
EOF
|
||||
|
||||
file_name = "user-data-cloud-config.yaml"
|
||||
}
|
||||
}
|
||||
10
providers.tf
10
providers.tf
@@ -1,4 +1,14 @@
|
||||
provider "proxmox" {
|
||||
endpoint = "https://prox-console.tail1ad20b.ts.net/"
|
||||
# api_token read from PROXMOX_VE_API_TOKEN
|
||||
|
||||
ssh {
|
||||
agent = true
|
||||
username = "root"
|
||||
node {
|
||||
name = "pve"
|
||||
address = "pve.tail1ad20b.ts.net"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
48
template.tf
Normal file
48
template.tf
Normal file
@@ -0,0 +1,48 @@
|
||||
resource "proxmox_virtual_environment_vm" "ubuntu_template" {
|
||||
name = "ubuntu-template"
|
||||
node_name = var.virtual_environment_node_name
|
||||
|
||||
template = true
|
||||
started = false
|
||||
|
||||
machine = "q35"
|
||||
bios = "ovmf"
|
||||
description = "Managed by OpenTofu"
|
||||
|
||||
cpu {
|
||||
cores = 2
|
||||
}
|
||||
|
||||
memory {
|
||||
dedicated = 2048
|
||||
}
|
||||
|
||||
efi_disk {
|
||||
datastore_id = var.datastore_id
|
||||
type = "4m"
|
||||
}
|
||||
|
||||
disk {
|
||||
datastore_id = var.datastore_id
|
||||
file_id = "local:iso/jammy-server-cloudimg-amd64.img"
|
||||
interface = "virtio0"
|
||||
iothread = true
|
||||
discard = "on"
|
||||
size = 20
|
||||
}
|
||||
|
||||
initialization {
|
||||
ip_config {
|
||||
ipv4 {
|
||||
address = "dhcp"
|
||||
}
|
||||
}
|
||||
|
||||
user_data_file_id = proxmox_virtual_environment_file.user_data_cloud_config.id
|
||||
}
|
||||
|
||||
network_device {
|
||||
bridge = "vmbr0"
|
||||
}
|
||||
|
||||
}
|
||||
11
variables.tf
Normal file
11
variables.tf
Normal file
@@ -0,0 +1,11 @@
|
||||
variable "virtual_environment_node_name" {
|
||||
type = string
|
||||
description = "The node name for the Proxmox Virtual Environment API"
|
||||
default = "pve"
|
||||
}
|
||||
|
||||
variable "datastore_id" {
|
||||
type = string
|
||||
description = "Datastore for VM disks"
|
||||
default = "local-lvm"
|
||||
}
|
||||
Reference in New Issue
Block a user