dacodev / terraform-module-proxmox-lxc Goto Github PK
View Code? Open in Web Editor NEWTF modules for Proxmox built on top of bgp's provider: https://registry.terraform.io/providers/bpg/proxmox/latest
License: MIT License
TF modules for Proxmox built on top of bgp's provider: https://registry.terraform.io/providers/bpg/proxmox/latest
License: MIT License
Hi,
I tried your module out and it helped me understand Terraform modules. So thank you.
As I got further along I realized I could just use for_each and locals instead.
Have you considered doing that? Perhaps I was using this module for a different purpose than you intended.
https://developer.hashicorp.com/terraform/language/meta-arguments/for_each
Here's my example of creating 2 containers using for_each with the out of the box bpg/proxmox provider:
terraform {
required_providers {
proxmox = {
source = "bpg/proxmox"
}
}
}
locals {
container_template_file = "http://download.proxmox.com/images/system/debian-12-standard_12.2-1_amd64.tar.zst"
container_template_checksum = "761b3b52ba296c3e396b79f89bdb30fed121d2353a641f84d633a87897ed6d19"
container_distro = "debian"
network_bridge = "vmbr0"
node_name = "proxmox1"
containers = {
"test1" = {
ram_MiB = 4096
swap_MiB = 512
vm_id = 1000
cpu_cores = 2
container_template_id = proxmox_virtual_environment_file.container_template.id
}
"test2" = {
ram_MiB = 8192
swap_MiB = 0
vm_id = 1001
cpu_cores = 4
container_template_id = proxmox_virtual_environment_file.container_template.id
}
}
}
resource "proxmox_virtual_environment_file" "container_template" {
content_type = "vztmpl"
datastore_id = "local"
node_name = "proxmox1"
source_file {
path = local.container_template_file
insecure = true
checksum = local.container_template_checksum
}
}
resource "proxmox_virtual_environment_container" "proxmox_lxc" {
description = "Managed by Terraform"
for_each = local.containers
node_name = local.node_name
vm_id = each.value.vm_id
unprivileged = true
initialization {
hostname = each.key
ip_config {
ipv4 {
address = "dhcp"
}
}
user_account {
keys = [
trimspace(tls_private_key.lxc_container_key.public_key_openssh)
]
password = random_password.lxc_password.result
}
}
cpu {
architecture = "amd64"
cores = each.value.cpu_cores
}
memory {
dedicated = each.value.ram_MiB
swap = each.value.swap_MiB
}
disk {
datastore_id = "local-zfs"
size = "10"
}
network_interface {
name = "veth0"
bridge = local.network_bridge
}
operating_system {
template_file_id = proxmox_virtual_environment_file.container_template.id
type = local.container_distro
}
}
resource "random_password" "lxc_password" {
length = 16
override_special = "_%@"
special = true
}
resource "tls_private_key" "lxc_container_key" {
algorithm = "RSA"
rsa_bits = 2048
}
output "container_password" {
value = random_password.lxc_password.result
sensitive = true
}
output "container_private_key" {
value = tls_private_key.lxc_container_key.private_key_pem
sensitive = true
}
output "container_public_key" {
value = tls_private_key.lxc_container_key.public_key_openssh
}
module "proxmox-lxc-debian-remote" {
source = "DacoDev/proxmox-lxc/module"
container_name = "debian"
container_template_file = "http://download.proxmox.com/images/system/debian-12-standard_12.2-1_amd64.tar.zst"
cpu_cores = 2
distro = "debian"
node_name = "test"
memory_dedicated = 512
vm_id = 1001
disk_size = 20
}
module "proxmox-lxc-debian-remote2" {
source = "DacoDev/proxmox-lxc/module"
container_name = "debian"
container_template_file = "http://download.proxmox.com/images/system/debian-12-standard_12.2-1_amd64.tar.zst"
cpu_cores = 2
distro = "debian"
node_name = "test"
memory_dedicated = 512
vm_id = 1002
disk_size = 20
}
results in:
Error: File already exists in a datastore, it was created outside of Terraform or is managed by another resource.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.