-
Notifications
You must be signed in to change notification settings - Fork 0
/
lxc_main.tf
96 lines (84 loc) · 2.08 KB
/
lxc_main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
terraform {
required_providers {
proxmox = {
source = "Telmate/proxmox"
version = "2.9.14"
}
random = {
source = "hashicorp/random"
version = "3.5.1"
}
}
}
provider "proxmox" {
pm_api_url = var.pm_api_url
pm_debug = true
pm_parallel = 10
}
resource "random_password" "password" {
length = 16
special = true
override_special = "!#-_=+?"
}
resource "tls_private_key" "dev_key" {
algorithm = "RSA"
rsa_bits = 4096
}
resource "proxmox_lxc" "basic" {
target_node = var.node
hostname = var.hostname
ostemplate = var.ostemplate
pool = var.pool_name
password = random_password.password.result
unprivileged = var.unprivileged
memory = var.memory
cores = var.cores
start = var.start
# auto create ssh key pair
provisioner "local-exec" {
command = <<-EOT
echo '${tls_private_key.dev_key.private_key_pem}' > ./'${var.generated_key_name}'.pem
chmod 400 ./'${var.generated_key_name}'.pem
EOT
}
ssh_public_keys = tls_private_key.dev_key.public_key_openssh
rootfs {
storage = var.storage
size = var.storage_size
}
network {
name = var.nic_name
bridge = var.bridge_name
gw = var.gateway_address
ip = var.ipv4_address
ip6 = "auto"
firewall = var.firewall
}
# a bind mountpoint requires high privileges. use the root@pam password authentication to work
# mountpoint {
# key = "100"
# slot = 0
# storage = "HDD-Data"
# mp = "/sharedstorage"
# volume = "/mnt/pve/HDD-Shared/shared"
# size = "12G"
# shared = true
# }
# storage mountpoint for additional space
# mountpoint {
# key = "100"
# slot = 0
# storage = "HDD-Data"
# mp = "/mnt/container/device-mount-point"
# size = "32G"
# }
}
# root password of the container
output "password" {
value = nonsensitive(random_password.password.result)
sensitive = false
}
# ssh pub key of the container
output "public-key" {
value = tls_private_key.dev_key.public_key_openssh
}