Compare commits
2 Commits
82fec81eb2
...
83cee67ab7
| Author | SHA1 | Date | |
|---|---|---|---|
| 83cee67ab7 | |||
| e204876f61 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,11 +1,12 @@
|
||||
# ===========================================
|
||||
# Terraform
|
||||
# ===========================================
|
||||
# Terraform
|
||||
*.tfstate
|
||||
*.tfstate.*
|
||||
*.tfplan
|
||||
.terraform/
|
||||
.terraform.lock.hcl
|
||||
.tfrc
|
||||
crash.log
|
||||
crash.*.log
|
||||
|
||||
|
||||
19
terraform/.gitignore
vendored
Normal file
19
terraform/.gitignore
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
# Terraform
|
||||
.terraform/
|
||||
.terraform.lock.hcl
|
||||
*.tfstate
|
||||
*.tfstate.*
|
||||
*.tfvars
|
||||
!*.tfvars.example
|
||||
crash.log
|
||||
crash.*.log
|
||||
|
||||
# Plugin binary
|
||||
# .terraform/providers/
|
||||
|
||||
# Credentials (never commit)
|
||||
.tfrc
|
||||
credentials.tf
|
||||
|
||||
# Backup
|
||||
*.backup
|
||||
3
terraform/.tfrc.tpl
Normal file
3
terraform/.tfrc.tpl
Normal file
@ -0,0 +1,3 @@
|
||||
credentials "app.terraform.io" {
|
||||
token = "7zDJsxdccdoLAQ.atlasv1.yzWzwYZG3hLy7JkozBhyJsn1dtFpeQrxVaffYvOynuWE59fpZj9e8ZJ96CybpU1vrtA"
|
||||
}
|
||||
31
terraform/imports.tf
Normal file
31
terraform/imports.tf
Normal file
@ -0,0 +1,31 @@
|
||||
# ===========================================
|
||||
# IMPORT — Importar recursos existentes no Proxmox
|
||||
#
|
||||
# Formato do import:
|
||||
# terraform import <resource_address> <proxmox_node>/<vm_type>/<vmid>
|
||||
#
|
||||
# Exemplos:
|
||||
# terraform import proxmox_vm_qemu.homeassistant pve/qemu/100
|
||||
# terraform import proxmox_vm_qemu.dockerino pve/qemu/102
|
||||
# terraform import proxmox_vm_qemu.media pve/qemu/103
|
||||
#
|
||||
# IMPORTANTE: O import apenas lê e registra o estado atual.
|
||||
# Depois do import, qualquer alteração vai aparecer no `terraform plan`.
|
||||
# ===========================================
|
||||
|
||||
# ===========================================
|
||||
# DATA SOURCES (leem dados do Proxmox sem modificar nada)
|
||||
# ===========================================
|
||||
|
||||
# Ler as 3 VMs existentes
|
||||
data "proxmox_vm_qemu" "homeassistant" {
|
||||
vm_id = 100
|
||||
}
|
||||
|
||||
data "proxmox_vm_qemu" "dockerino" {
|
||||
vm_id = 102
|
||||
}
|
||||
|
||||
data "proxmox_vm_qemu" "media" {
|
||||
vm_id = 103
|
||||
}
|
||||
37
terraform/providers.tf
Normal file
37
terraform/providers.tf
Normal file
@ -0,0 +1,37 @@
|
||||
# ===========================================
|
||||
# PROVIDERS
|
||||
# ===========================================
|
||||
|
||||
terraform {
|
||||
required_version = ">= 1.10.0"
|
||||
|
||||
required_providers {
|
||||
proxmox = {
|
||||
source = "telmate/proxmox"
|
||||
version = "~> 3.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
# State remoto no Terraform Cloud
|
||||
cloud {
|
||||
organization = "homelab_terraform"
|
||||
|
||||
workspaces {
|
||||
name = "homelab"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Provider Proxmox
|
||||
provider "proxmox" {
|
||||
# Conexão via SSH (mesma chave que já funciona do Hestia → Proxmox)
|
||||
# Não armazenamos senha em texto — usamos agente SSH local
|
||||
ssh_username = "root"
|
||||
ssh_agent = true
|
||||
insecure = false
|
||||
|
||||
# API Proxmox (fallback se SSH não funcionar)
|
||||
pm_api_url = "https://10.0.0.20:8006/api2/json"
|
||||
pm_api_token_id = var.proxmox_api_token_id
|
||||
pm_api_token_secret = var.proxmox_api_token_secret
|
||||
}
|
||||
105
terraform/resources.tf
Normal file
105
terraform/resources.tf
Normal file
@ -0,0 +1,105 @@
|
||||
# ===========================================
|
||||
# PROXMOX VMs — Definições reais (importadas)
|
||||
#
|
||||
# IMPORTANTE: Estes recursos representam o estado ATUAL.
|
||||
# O import lê o estado existente. Qualquer mudança futura
|
||||
# só deve ser feita via terraform plan → aprovação → apply.
|
||||
#
|
||||
# VMs descobertas via `qm list`:
|
||||
# VMID 100 | homeassistant | 4GB RAM | 32GB disk | running
|
||||
# VMID 102 | dockerino | 10GB RAM | 74GB disk | running
|
||||
# VMID 103 | media | 16GB RAM | 64GB disk | running
|
||||
# ===========================================
|
||||
|
||||
# ===========================================
|
||||
# HOMEASSISTANT — VM QEMU (VMID 100)
|
||||
# ===========================================
|
||||
|
||||
resource "proxmox_vm_qemu" "homeassistant" {
|
||||
name = "homeassistant"
|
||||
vm_id = 100
|
||||
target_node = "pve"
|
||||
|
||||
# Recursos
|
||||
cores = 4
|
||||
memory = 4096
|
||||
os_type = "qubes"
|
||||
boot_order = "scsi0"
|
||||
agent = 1
|
||||
|
||||
# Disco
|
||||
disk {
|
||||
file = "scsi0"
|
||||
storage = "local-lvm"
|
||||
size = "32G"
|
||||
type = "scsi"
|
||||
}
|
||||
|
||||
# Rede
|
||||
network {
|
||||
model = "virtio"
|
||||
bridge = "vmbr0"
|
||||
}
|
||||
}
|
||||
|
||||
# ===========================================
|
||||
# DOCKERINO — VM QEMU (VMID 102)
|
||||
# ===========================================
|
||||
|
||||
resource "proxmox_vm_qemu" "dockerino" {
|
||||
name = "dockerino"
|
||||
vm_id = 102
|
||||
target_node = "pve"
|
||||
|
||||
# Recursos
|
||||
cores = 4
|
||||
memory = 10240
|
||||
os_type = "l26" # Linux 2.6+ (Debian)
|
||||
boot_order = "scsi0"
|
||||
agent = 1
|
||||
|
||||
# Disco
|
||||
disk {
|
||||
file = "scsi0"
|
||||
storage = "local-lvm"
|
||||
size = "74G"
|
||||
type = "scsi"
|
||||
}
|
||||
|
||||
# Rede
|
||||
network {
|
||||
model = "virtio"
|
||||
bridge = "vmbr0"
|
||||
}
|
||||
}
|
||||
|
||||
# ===========================================
|
||||
# MEDIA — VM QEMU (VMID 103)
|
||||
# ===========================================
|
||||
|
||||
resource "proxmox_vm_qemu" "media" {
|
||||
name = "media"
|
||||
vm_id = 103
|
||||
target_node = "pve"
|
||||
|
||||
# Recursos
|
||||
cores = 4
|
||||
memory = 16384
|
||||
os_type = "l26"
|
||||
boot_order = "scsi0"
|
||||
agent = 1
|
||||
|
||||
# Disco
|
||||
disk {
|
||||
file = "scsi0"
|
||||
storage = "local-lvm"
|
||||
size = "64G"
|
||||
type = "scsi"
|
||||
}
|
||||
|
||||
# Rede
|
||||
network {
|
||||
model = "virtio"
|
||||
bridge = "vmbr0"
|
||||
}
|
||||
}
|
||||
8
terraform/terraform.tfvars.example
Normal file
8
terraform/terraform.tfvars.example
Normal file
@ -0,0 +1,8 @@
|
||||
# ===========================================
|
||||
# EXEMPLO — preencha com seus valores reais
|
||||
# ===========================================
|
||||
# Renomeie para terraform.tfvars e preencha os valores
|
||||
# NUNCA commite terraform.tfvars com valores reais
|
||||
|
||||
proxmox_api_token_id = "SEU_TOKEN_ID_AQUI"
|
||||
proxmox_api_token_secret = "SEU_TOKEN_SECRET_AQUI"
|
||||
15
terraform/variables.tf
Normal file
15
terraform/variables.tf
Normal file
@ -0,0 +1,15 @@
|
||||
# ===========================================
|
||||
# VARIABLES (sensíveis — não commitar valores)
|
||||
# ===========================================
|
||||
|
||||
variable "proxmox_api_token_id" {
|
||||
description = "Token ID do Proxmox (formato: UUID@pam!token-name)"
|
||||
type = string
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "proxmox_api_token_secret" {
|
||||
description = "Secret do token do Proxmox"
|
||||
type = string
|
||||
sensitive = true
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user