test
This commit is contained in:
parent
8b2da9af19
commit
2845470fe6
30
lxc.tf
Normal file
30
lxc.tf
Normal file
@ -0,0 +1,30 @@
|
||||
resource "proxmox_lxc" "container" {
|
||||
for_each = var.containers
|
||||
|
||||
hostname = each.key
|
||||
target_node = var.target_node
|
||||
ostemplate = lookup(var.lxc_templates, each.value.template, each.value.template)
|
||||
unprivileged = each.value.privileged != true
|
||||
|
||||
cores = each.value.cores
|
||||
memory = each.value.memory
|
||||
swap = 512
|
||||
password = var.lxcrootPass
|
||||
rootfs {
|
||||
storage = var.default_storage
|
||||
size = each.value.disk_size
|
||||
}
|
||||
|
||||
network {
|
||||
name = "eth0"
|
||||
bridge = var.default_bridge
|
||||
tag = each.value.vlan_tag
|
||||
ip = each.value.ip
|
||||
gw = var.default_gateway
|
||||
}
|
||||
|
||||
nameserver = var.dns_servers
|
||||
|
||||
onboot = true
|
||||
start = true
|
||||
}
|
||||
9
output.tf
Normal file
9
output.tf
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
output "summary" {
|
||||
description = "Résumé de l'infrastructure"
|
||||
value = {
|
||||
node = var.target_node
|
||||
total_vms = length(var.vms)
|
||||
total_lxc = length(var.containers)
|
||||
}
|
||||
}
|
||||
6
provider.tf
Normal file
6
provider.tf
Normal file
@ -0,0 +1,6 @@
|
||||
provider "proxmox" {
|
||||
pm_api_url = var.proxmox_url
|
||||
pm_api_token_id = var.proxmox_token_id
|
||||
pm_api_token_secret = var.proxmox_token_secret
|
||||
pm_tls_insecure = var.proxmox_insecure_tls
|
||||
}
|
||||
125
terraform.tfstate
Normal file
125
terraform.tfstate
Normal file
@ -0,0 +1,125 @@
|
||||
{
|
||||
"version": 4,
|
||||
"terraform_version": "1.12.1",
|
||||
"serial": 2,
|
||||
"lineage": "35ee9084-4e94-9c69-d600-692b8a61814f",
|
||||
"outputs": {
|
||||
"summary": {
|
||||
"value": {
|
||||
"node": "pve",
|
||||
"total_lxc": 1,
|
||||
"total_vms": 0
|
||||
},
|
||||
"type": [
|
||||
"object",
|
||||
{
|
||||
"node": "string",
|
||||
"total_lxc": "number",
|
||||
"total_vms": "number"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"resources": [
|
||||
{
|
||||
"mode": "managed",
|
||||
"type": "proxmox_lxc",
|
||||
"name": "container",
|
||||
"provider": "provider[\"registry.terraform.io/telmate/proxmox\"]",
|
||||
"instances": [
|
||||
{
|
||||
"index_key": "testterraform",
|
||||
"schema_version": 0,
|
||||
"attributes": {
|
||||
"arch": "amd64",
|
||||
"bwlimit": 0,
|
||||
"clone": null,
|
||||
"clone_storage": null,
|
||||
"cmode": "tty",
|
||||
"console": true,
|
||||
"cores": 1,
|
||||
"cpulimit": 0,
|
||||
"cpuunits": 1024,
|
||||
"current_node": "pve",
|
||||
"description": "",
|
||||
"features": [],
|
||||
"force": false,
|
||||
"full": null,
|
||||
"hagroup": "",
|
||||
"hastate": "",
|
||||
"hookscript": "",
|
||||
"hostname": "testterraform",
|
||||
"id": "pve/lxc/134",
|
||||
"ignore_unpack_errors": false,
|
||||
"lock": "",
|
||||
"memory": 512,
|
||||
"mountpoint": [],
|
||||
"nameserver": "8.8.8.8 8.8.4.4",
|
||||
"network": [
|
||||
{
|
||||
"bridge": "vmbr0",
|
||||
"firewall": false,
|
||||
"gw": "192.168.1.1",
|
||||
"gw6": "",
|
||||
"hwaddr": "BC:24:11:09:CC:A0",
|
||||
"id": 0,
|
||||
"ip": "192.168.1.110/24",
|
||||
"ip6": "",
|
||||
"mtu": 0,
|
||||
"name": "eth0",
|
||||
"rate": 0,
|
||||
"tag": 0,
|
||||
"trunks": "",
|
||||
"type": "veth"
|
||||
}
|
||||
],
|
||||
"onboot": true,
|
||||
"ostemplate": "local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst",
|
||||
"ostype": "ubuntu",
|
||||
"password": "Test_123",
|
||||
"pool": null,
|
||||
"protection": false,
|
||||
"restore": false,
|
||||
"rootfs": [
|
||||
{
|
||||
"acl": false,
|
||||
"quota": false,
|
||||
"replicate": false,
|
||||
"ro": false,
|
||||
"shared": false,
|
||||
"size": "8G",
|
||||
"storage": "local",
|
||||
"volume": "local:134/vm-134-disk-0.raw"
|
||||
}
|
||||
],
|
||||
"searchdomain": "",
|
||||
"ssh_public_keys": null,
|
||||
"start": true,
|
||||
"startup": "",
|
||||
"swap": 512,
|
||||
"tags": "",
|
||||
"target_node": "pve",
|
||||
"template": false,
|
||||
"timeouts": null,
|
||||
"tty": 2,
|
||||
"unique": false,
|
||||
"unprivileged": true,
|
||||
"unused": [],
|
||||
"vmid": 134
|
||||
},
|
||||
"sensitive_attributes": [
|
||||
[
|
||||
{
|
||||
"type": "get_attr",
|
||||
"value": "password"
|
||||
}
|
||||
]
|
||||
],
|
||||
"identity_schema_version": 0,
|
||||
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxMjAwMDAwMDAwMDAwLCJkZWZhdWx0IjoxMjAwMDAwMDAwMDAwLCJkZWxldGUiOjEyMDAwMDAwMDAwMDAsInJlYWQiOjEyMDAwMDAwMDAwMDAsInVwZGF0ZSI6MTIwMDAwMDAwMDAwMH19"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"check_results": null
|
||||
}
|
||||
29
terraform.tfvars
Normal file
29
terraform.tfvars
Normal file
@ -0,0 +1,29 @@
|
||||
proxmox_url = "https://192.168.1.30:8006/api2/json"
|
||||
proxmox_token_id = "terra-prov@pve!mytoken"
|
||||
proxmox_token_secret = "882db24e-bb79-44cc-98da-b23f020a9a9d"
|
||||
proxmox_insecure_tls = true
|
||||
|
||||
target_node = "pve"
|
||||
default_gateway = "192.168.1.1"
|
||||
|
||||
vms = {
|
||||
# "web-server" = {
|
||||
# cores = 2
|
||||
# memory = 2048
|
||||
# disk_size = "20G"
|
||||
# ip = "192.168.1.200/24"
|
||||
# template = "template-ubuntu-cloud"
|
||||
# }
|
||||
}
|
||||
|
||||
# Containers LXC
|
||||
containers = {
|
||||
"testterraform" = {
|
||||
template = "ubuntu"
|
||||
cores = 1
|
||||
memory = 512
|
||||
disk_size = "8G"
|
||||
ip = "192.168.1.110/24"
|
||||
|
||||
}
|
||||
}
|
||||
95
variables.tf
Normal file
95
variables.tf
Normal file
@ -0,0 +1,95 @@
|
||||
variable "proxmox_url" {
|
||||
description = "URL de l'API Proxmox"
|
||||
type = string
|
||||
default = "https://proxmox.firewax.fr/api2/json"
|
||||
}
|
||||
|
||||
variable "proxmox_token_id" {
|
||||
description = "token ID"
|
||||
type = string
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "proxmox_token_secret" {
|
||||
description = "secret Token"
|
||||
type = string
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "proxmox_insecure_tls" {
|
||||
description = "Ignorer les erreurs de certificat SSL"
|
||||
type = bool
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "target_node" {
|
||||
description = "Nom du nœud Proxmox"
|
||||
type = string
|
||||
default = "pve"
|
||||
}
|
||||
|
||||
variable "default_storage" {
|
||||
description = "Storage par défaut pour les disques"
|
||||
type = string
|
||||
default = "local"
|
||||
}
|
||||
|
||||
variable "default_bridge" {
|
||||
description = "Bridge réseau par défaut"
|
||||
type = string
|
||||
default = "vmbr0"
|
||||
}
|
||||
|
||||
variable "default_gateway" {
|
||||
description = "Passerelle par défaut"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "dns_servers" {
|
||||
description = "Serveurs DNS"
|
||||
type = string
|
||||
default = "8.8.8.8 8.8.4.4"
|
||||
}
|
||||
|
||||
variable "vms" {
|
||||
description = "Configuration des machines virtuelles"
|
||||
type = map(object({
|
||||
cores = number
|
||||
memory = number
|
||||
disk_size = string
|
||||
ip = string
|
||||
vlan_tag = optional(number)
|
||||
template = optional(string)
|
||||
}))
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "lxc_templates" {
|
||||
description = "Templates disponibles pour les containers"
|
||||
type = map(string)
|
||||
default = {
|
||||
ubuntu = "local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst"
|
||||
debian = "local:vztmpl/debian-12-standard_12.7-1_amd64.tar.zst"
|
||||
}
|
||||
}
|
||||
|
||||
variable "containers" {
|
||||
description = "Configuration des containers LXC"
|
||||
type = map(object({
|
||||
template = string
|
||||
cores = number
|
||||
memory = number
|
||||
disk_size = string
|
||||
ip = string
|
||||
vlan_tag = optional(number)
|
||||
privileged = optional(bool)
|
||||
enable_docker = optional(bool)
|
||||
}))
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "lxcrootPass" {
|
||||
description = "mot de passe"
|
||||
type = string
|
||||
sensitive = true
|
||||
}
|
||||
8
versions.tf
Normal file
8
versions.tf
Normal file
@ -0,0 +1,8 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
proxmox = {
|
||||
source = "Telmate/proxmox"
|
||||
version = "3.0.1-rc9"
|
||||
}
|
||||
}
|
||||
}
|
||||
39
vm.tf
Normal file
39
vm.tf
Normal file
@ -0,0 +1,39 @@
|
||||
resource "proxmox_vm_qemu" "vms" {
|
||||
for_each = var.vms
|
||||
|
||||
name = each.key
|
||||
target_node = var.target_node
|
||||
|
||||
clone = each.value.clone != null ? each.value.clone : null
|
||||
|
||||
cores = each.value.cores
|
||||
sockets = 1
|
||||
memory = each.value.memory
|
||||
|
||||
disks {
|
||||
ide {
|
||||
ide0 {
|
||||
disk {
|
||||
size = each.value.disk_size
|
||||
storage = "local-lvm"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
network {
|
||||
id = 0
|
||||
model = "virtio"
|
||||
bridge = var.default_bridge
|
||||
tag = each.value.vlan_tag
|
||||
}
|
||||
|
||||
os_type = "cloud-init"
|
||||
ipconfig0 = "ip=${each.value.ip_address},gw=${var.default_gateway}"
|
||||
|
||||
|
||||
boot = "order=ide0"
|
||||
|
||||
tags = "terraform,vm,${each.key}"
|
||||
}
|
||||
42
vm.tf.save
Normal file
42
vm.tf.save
Normal file
@ -0,0 +1,42 @@
|
||||
resource "proxmox_vm_qemu" "vms" {
|
||||
for_each = var.vms
|
||||
|
||||
name = each.key
|
||||
target_node = var.target_node
|
||||
|
||||
clone = each.value.clone != null ? each.value.clone : null
|
||||
|
||||
cores = each.value.cores
|
||||
sockets = 1
|
||||
memory = each.value.memory
|
||||
|
||||
disks {
|
||||
ide {
|
||||
ide0 {
|
||||
disk {
|
||||
size = each.value.disk_size
|
||||
storage = "local"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
network {
|
||||
id = 0
|
||||
model = "virtio"
|
||||
bridge = var.default_bridge
|
||||
tag = each.value.vlan_tag
|
||||
}
|
||||
|
||||
os_type = "cloud-init"
|
||||
ipconfig0 = "ip=${each.value.ip_address},gw=${var.default_gateway}"
|
||||
|
||||
|
||||
boot = "order=ide0"
|
||||
|
||||
tags = "terraform,vm,${each.key}"
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user