mirror of
https://gitea.fenix-dev.com/fenix-gitea-admin/iac-opentofu-private.git
synced 2025-10-27 23:57:59 +00:00
Merge pull request 'fenix-admin' (#131) from fenix-admin into main
Reviewed-on: fenix-gitea-admin/iac-teste#131
This commit is contained in:
23
documentation/Dockerfile
Normal file
23
documentation/Dockerfile
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
FROM ghcr.io/opentofu/opentofu:1.9-minimal AS tofu
|
||||||
|
|
||||||
|
FROM ubuntu:24.04
|
||||||
|
|
||||||
|
# Copy the tofu binary
|
||||||
|
COPY --from=tofu /usr/local/bin/tofu /usr/local/bin/tofu
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
RUN apt-get update && apt-get install -y \
|
||||||
|
git \
|
||||||
|
curl \
|
||||||
|
nodejs \
|
||||||
|
npm \
|
||||||
|
unzip \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
RUN curl -L -o /tmp/bw.zip https://github.com/bitwarden/cli/releases/download/v1.22.1/bw-linux-1.22.1.zip \
|
||||||
|
&& unzip /tmp/bw.zip -d /usr/local/bin \
|
||||||
|
&& chmod +x /usr/local/bin/bw \
|
||||||
|
&& rm /tmp/bw.zip
|
||||||
|
|
||||||
|
|
||||||
|
WORKDIR /workspace
|
||||||
82
proxmox.tf
82
proxmox.tf
@ -34,7 +34,7 @@ resource "proxmox_virtual_environment_file" "cloud_init_yaml" {
|
|||||||
#cloud-config
|
#cloud-config
|
||||||
users:
|
users:
|
||||||
- default
|
- default
|
||||||
- name: testeuser
|
- name: ${var.proxmox_VM_username}
|
||||||
groups: sudo
|
groups: sudo
|
||||||
shell: /bin/bash
|
shell: /bin/bash
|
||||||
sudo: ALL=(ALL) NOPASSWD:ALL
|
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||||
@ -43,7 +43,7 @@ resource "proxmox_virtual_environment_file" "cloud_init_yaml" {
|
|||||||
|
|
||||||
chpasswd:
|
chpasswd:
|
||||||
list: |
|
list: |
|
||||||
testeuser:testepassword
|
${var.proxmox_VM_username}:${var.proxmox_VM_password}
|
||||||
expire: false
|
expire: false
|
||||||
|
|
||||||
package_update: true
|
package_update: true
|
||||||
@ -86,11 +86,11 @@ resource "proxmox_virtual_environment_vm" "proxmox-kubernetes-VM-template" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Configuração do disco rígido
|
# Configuração do disco rígido
|
||||||
disk {
|
#disk {
|
||||||
datastore_id = "local-lvm"
|
# datastore_id = "local-lvm"
|
||||||
interface = "scsi1"
|
# interface = "scsi1"
|
||||||
size = 64
|
# size = 64
|
||||||
}
|
#}
|
||||||
|
|
||||||
disk {
|
disk {
|
||||||
datastore_id = "local-lvm"
|
datastore_id = "local-lvm"
|
||||||
@ -116,14 +116,76 @@ initialization {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
resource "proxmox_virtual_environment_vm" "VM-Kubernetes-01" {
|
resource "proxmox_virtual_environment_vm" "k8s_vms" {
|
||||||
|
for_each = { for vm in var.proxmox_k8s_vms : vm.name => vm }
|
||||||
depends_on = [proxmox_virtual_environment_vm.proxmox-kubernetes-VM-template]
|
depends_on = [proxmox_virtual_environment_vm.proxmox-kubernetes-VM-template]
|
||||||
name = "VM-Kubernetes-01"
|
name = each.value.name
|
||||||
node_name = "fenix"
|
node_name = each.value.node_name
|
||||||
|
vm_id = each.value.vm_id
|
||||||
|
|
||||||
|
cpu {
|
||||||
|
cores = each.value.cores
|
||||||
|
}
|
||||||
|
|
||||||
|
memory {
|
||||||
|
dedicated = each.value.memory
|
||||||
|
}
|
||||||
|
|
||||||
|
disk {
|
||||||
|
datastore_id = each.value.datastore
|
||||||
|
size = each.value.disk_size
|
||||||
|
interface = "scsi1"
|
||||||
|
}
|
||||||
|
|
||||||
clone {
|
clone {
|
||||||
vm_id = proxmox_virtual_environment_vm.proxmox-kubernetes-VM-template.id
|
vm_id = proxmox_virtual_environment_vm.proxmox-kubernetes-VM-template.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
initialization {
|
||||||
|
ip_config {
|
||||||
|
ipv4 {
|
||||||
|
address = each.value.ip
|
||||||
|
gateway = each.value.gateway
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
user_data = <<EOF
|
||||||
|
#cloud-config
|
||||||
|
package_update: true
|
||||||
|
packages:
|
||||||
|
%{ for pkg in each.value.packages ~}
|
||||||
|
- ${pkg}
|
||||||
|
%{ endfor ~}
|
||||||
|
|
||||||
|
users:
|
||||||
|
%{ if length(each.value.extra_users) > 0 ~}
|
||||||
|
|
||||||
|
%{ for u in each.value.extra_users ~}
|
||||||
|
- name: ${u.name}
|
||||||
|
groups: [${join(", ", u.groups)}]
|
||||||
|
shell: /bin/bash
|
||||||
|
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||||
|
%{ endfor ~}
|
||||||
|
|
||||||
|
chpasswd:
|
||||||
|
list: |
|
||||||
|
%{ for u in each.value.extra_users ~}
|
||||||
|
${u.name}:${u.password}
|
||||||
|
%{ endfor ~}
|
||||||
|
expire: false
|
||||||
|
|
||||||
|
%{ endif ~}
|
||||||
|
runcmd:
|
||||||
|
%{ if length(each.value.extra_runcmd) > 0 ~}
|
||||||
|
%{ for cmd in each.value.extra_runcmd ~}
|
||||||
|
- ${cmd}
|
||||||
|
%{ endfor ~}
|
||||||
|
%{ endif ~}
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
agent {
|
agent {
|
||||||
enabled = true
|
enabled = true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,3 +32,23 @@ variable "proxmox_apikey" {
|
|||||||
variable "node_name" {
|
variable "node_name" {
|
||||||
default = "fenix"
|
default = "fenix"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Lista de VMs (override de valores específicos)
|
||||||
|
variable "proxmox_k8s_vms" {
|
||||||
|
type = list(object({
|
||||||
|
name = string
|
||||||
|
vm_id = number
|
||||||
|
node_name = string
|
||||||
|
ip = string
|
||||||
|
cores = optional(number)
|
||||||
|
memory = optional(number)
|
||||||
|
disk_size = optional(number)
|
||||||
|
extra_users = optional(list(object({
|
||||||
|
name = string
|
||||||
|
password = string
|
||||||
|
groups = list(string)
|
||||||
|
})))
|
||||||
|
extra_packages = optional(list(string))
|
||||||
|
extra_runcmd = optional(list(string))
|
||||||
|
}))
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user