mirror of
https://gitea.fenix-dev.com/fenix-gitea-admin/iac-opentofu-private.git
synced 2025-10-27 15:53:06 +00:00
Compare commits
94 Commits
fc2b08a458
...
fenix-admi
| Author | SHA1 | Date | |
|---|---|---|---|
| a4b33a570b | |||
| c7c1388112 | |||
| b875d6428b | |||
| e1b0d702c5 | |||
| a7f3b6d7e1 | |||
| fcc7c9814a | |||
| cc441d8ad8 | |||
| e71295794f | |||
| 7c46db0253 | |||
| 218ca3fc2f | |||
| 58d080dadd | |||
| f797aa6d8b | |||
| 8b16085acf | |||
| 47102e563d | |||
| d9f9620123 | |||
| 905b749a09 | |||
| 992a949b6d | |||
| 387702c3c3 | |||
| 1bf18d13a3 | |||
| de1ea64e04 | |||
| 9edc3fe55d | |||
| fd0763593f | |||
| fc5ae6402f | |||
| 5412e499f2 | |||
| fa25d7073b | |||
| 2e81ffcdb1 | |||
| 8d7636a925 | |||
| 49c5457547 | |||
| 9b00c6d3f4 | |||
| 7c1d265e75 | |||
| b6c3b5e80f | |||
| 1f41c3dd53 | |||
| 461c145e39 | |||
| aa106310ea | |||
| 3d0a49f4fe | |||
| f0823e5716 | |||
| 3c6731405d | |||
| 0f346a4c73 | |||
| 916944a150 | |||
| 69150c506f | |||
| 0304eb6927 | |||
| 46da80161a | |||
| 337f1f573c | |||
| 6d3ca1edb3 | |||
| d300e27f9e | |||
| 06b3f73d8d | |||
| be6e459be5 | |||
| 9e6e9bd147 | |||
| fe60e4d672 | |||
| 585bda0bd2 | |||
| 21e645a72c | |||
| 9e0efc4f59 | |||
| 13c30fa900 | |||
| 7513e9f600 | |||
| 4d3492c94a | |||
| c7bf70d14c | |||
| a045a6593e | |||
| ef49235842 | |||
| 7ade4e335c | |||
| 82faecd162 | |||
| 250b5ec5a0 | |||
| c6db073f7e | |||
| 525490ac84 | |||
| 97aefe288a | |||
| cce724f9d7 | |||
| 3cf575d2d1 | |||
| e9abf54677 | |||
| 04e1cb7c9a | |||
| 0d510e4941 | |||
| a7ad7a0338 | |||
| 2ee2d36f16 | |||
| 46cc36b013 | |||
| 16878eec71 | |||
| f45492d630 | |||
| a594314bb1 | |||
| 4e36161371 | |||
| 8ecd94f08c | |||
| 67dd8b490c | |||
| 468a7c0d78 | |||
| 035427e956 | |||
| 27132cf022 | |||
| ce73cf8a9a | |||
| 9e5efb3a90 | |||
| df4b2d1255 | |||
| 54a6b90307 | |||
| d8e3ed45b9 | |||
| f9a02d0a3b | |||
| 58ec08c79a | |||
| a84c0de09f | |||
| 4d6491ff24 | |||
| b5e2fd76a9 | |||
| d04cc7477c | |||
| a9213a040c | |||
| 0b0e3db854 |
@ -2,7 +2,7 @@ name: IAC
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main ]
|
branches: [ dev ]
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
@ -17,6 +17,7 @@ jobs:
|
|||||||
BW_PASSWORD: ${{ secrets.BW_PASSWORD }}
|
BW_PASSWORD: ${{ secrets.BW_PASSWORD }}
|
||||||
BW_CLIENTID: ${{ secrets.BW_CLIENTID }}
|
BW_CLIENTID: ${{ secrets.BW_CLIENTID }}
|
||||||
BW_CLIENTSECRET: ${{ secrets.BW_CLIENTSECRET }}
|
BW_CLIENTSECRET: ${{ secrets.BW_CLIENTSECRET }}
|
||||||
|
VAULTWARDEN_LINK: ${{secrets.VAULTWARDEN_LINK }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
@ -34,6 +35,11 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
apt-get update -y
|
apt-get update -y
|
||||||
|
|
||||||
|
- name: Install setup
|
||||||
|
run: |
|
||||||
|
apt install -y curl jq
|
||||||
|
curl -fsSL https://deb.nodesource.com/setup_18.x
|
||||||
|
|
||||||
- name: Cloning iac repository
|
- name: Cloning iac repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
@ -59,7 +65,8 @@ jobs:
|
|||||||
|
|
||||||
- name: Install dante-server
|
- name: Install dante-server
|
||||||
run: |
|
run: |
|
||||||
apt-get install -y dante-server
|
apt-get install -y dante-server openssl
|
||||||
|
#libssl1.1
|
||||||
|
|
||||||
|
|
||||||
- name: Configure dante-server
|
- name: Configure dante-server
|
||||||
@ -82,16 +89,32 @@ jobs:
|
|||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|
||||||
|
- name: vaultwarden urls as secrets
|
||||||
|
run: |
|
||||||
|
echo "config"
|
||||||
|
echo "$VAULTWARDEN_LINK"
|
||||||
|
bw config server $VAULTWARDEN_LINK
|
||||||
|
echo "login"
|
||||||
|
bw login --apikey
|
||||||
|
echo "session"
|
||||||
|
BW_SESSION=$(bw unlock "$BW_PASSWORD" --raw)
|
||||||
|
echo "$BW_SESSION"
|
||||||
|
echo "getting item"
|
||||||
|
bw get item "iac.proxmox.ssh.link" --session "$BW_SESSION"
|
||||||
|
bw get item "iac.proxmox.ssh.link" --session "$BW_SESSION" | jq -r '.notes' > "proxmox-ssh-link.txt"
|
||||||
|
|
||||||
- name: Start cloudflared Access TCP -> SOCKS5 (background)
|
- name: Start cloudflared Access TCP -> SOCKS5 (background)
|
||||||
env:
|
env:
|
||||||
CF_SVC_ID: ${{ secrets.CF_SVC_ID }}
|
CF_SVC_ID: ${{ secrets.CF_SVC_ID }}
|
||||||
CF_SVC_SECRET: ${{ secrets.CF_SVC_SECRET }}
|
CF_SVC_SECRET: ${{ secrets.CF_SVC_SECRET }}
|
||||||
HOSTNAME: "proxmox-ssh.fenix-dev.com"
|
|
||||||
run: |
|
run: |
|
||||||
|
Hostname=$(cat proxmox-ssh-link.txt)
|
||||||
|
|
||||||
# Inicia cloudflared access tcp/ssh com service token e listener socks local
|
# Inicia cloudflared access tcp/ssh com service token e listener socks local
|
||||||
# O binário 'cloudflared' tem variações de flags entre versões; estes flags funcionam nas versões recentes.
|
# O binário 'cloudflared' tem variações de flags entre versões; estes flags funcionam nas versões recentes.
|
||||||
nohup cloudflared access tcp \
|
nohup cloudflared access tcp \
|
||||||
--hostname "$HOSTNAME" \
|
--hostname "$Hostname" \
|
||||||
--listener "tcp://127.0.0.1:1081" \
|
--listener "tcp://127.0.0.1:1081" \
|
||||||
--service-token-id "$CF_SVC_ID" \
|
--service-token-id "$CF_SVC_ID" \
|
||||||
--service-token-secret "$CF_SVC_SECRET" \
|
--service-token-secret "$CF_SVC_SECRET" \
|
||||||
@ -122,21 +145,12 @@ jobs:
|
|||||||
sleep 3
|
sleep 3
|
||||||
cat dante.log
|
cat dante.log
|
||||||
|
|
||||||
#- name: vaultwarden login
|
|
||||||
# working-directory: infra/iac
|
|
||||||
# run: |
|
|
||||||
# bw config server https://vaultwarden.fenix-dev.com
|
|
||||||
# #BW_SESSION=$(bw login)
|
|
||||||
# bw login --apikey
|
|
||||||
# BW_SESSION=$(bw unlock "$BW_PASSWORD" --raw)
|
|
||||||
|
|
||||||
|
|
||||||
- name: vaultwarden getsecrets
|
- name: vaultwarden getsecrets
|
||||||
working-directory: infra/iac
|
working-directory: infra/iac
|
||||||
run: |
|
run: |
|
||||||
bw config server https://vaultwarden.fenix-dev.com
|
|
||||||
bw login --apikey
|
|
||||||
BW_SESSION=$(bw unlock "$BW_PASSWORD" --raw)
|
BW_SESSION=$(bw unlock "$BW_PASSWORD" --raw)
|
||||||
|
echo "$BW_SESSION"
|
||||||
|
|
||||||
# Ler o arquivo de referência
|
# Ler o arquivo de referência
|
||||||
for secret in $(jq -c '.secrets[]' secrets/vault-secrets-map.json); do
|
for secret in $(jq -c '.secrets[]' secrets/vault-secrets-map.json); do
|
||||||
@ -154,6 +168,7 @@ jobs:
|
|||||||
elif [ "$type" == "note" ]; then
|
elif [ "$type" == "note" ]; then
|
||||||
echo "note get"
|
echo "note get"
|
||||||
bw get item "$name" --session "$BW_SESSION" | jq -r '.notes' > "$output"
|
bw get item "$name" --session "$BW_SESSION" | jq -r '.notes' > "$output"
|
||||||
|
#cat $output
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
1
README.md
Normal file
1
README.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
the most stable branch is main, dev is where tests are made, and the remaining branches are personal and can undergo changes at any time
|
||||||
@ -5,19 +5,27 @@ FROM ubuntu:24.04
|
|||||||
# Copy the tofu binary
|
# Copy the tofu binary
|
||||||
COPY --from=tofu /usr/local/bin/tofu /usr/local/bin/tofu
|
COPY --from=tofu /usr/local/bin/tofu /usr/local/bin/tofu
|
||||||
|
|
||||||
# Install dependencies
|
|
||||||
|
# Atualizar pacotes e instalar dependências básicas
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y \
|
||||||
git \
|
|
||||||
curl \
|
curl \
|
||||||
nodejs \
|
git \
|
||||||
npm \
|
|
||||||
unzip \
|
unzip \
|
||||||
|
jq \
|
||||||
|
gnupg \
|
||||||
|
ca-certificates \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& 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 \
|
# Instalar Node.js 18 via NodeSource
|
||||||
&& unzip /tmp/bw.zip -d /usr/local/bin \
|
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
|
||||||
&& chmod +x /usr/local/bin/bw \
|
apt-get install -y nodejs
|
||||||
&& rm /tmp/bw.zip
|
|
||||||
|
|
||||||
|
# Verificar versões (opcional para debug)
|
||||||
|
RUN node -v && npm -v
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
RUN npm install -g @bitwarden/cli
|
||||||
|
|
||||||
WORKDIR /workspace
|
WORKDIR /workspace
|
||||||
2
main.tf
2
main.tf
@ -6,7 +6,7 @@ terraform {
|
|||||||
}
|
}
|
||||||
bitwarden = {
|
bitwarden = {
|
||||||
source = "maxlaverse/bitwarden"
|
source = "maxlaverse/bitwarden"
|
||||||
version = ">= 0.15.0"
|
version = ">= 0.16.0"
|
||||||
}
|
}
|
||||||
proxmox = {
|
proxmox = {
|
||||||
source = "bpg/proxmox"
|
source = "bpg/proxmox"
|
||||||
|
|||||||
@ -120,7 +120,7 @@ resource "proxmox_virtual_environment_vm" "proxmox-kubernetes-VM-template" {
|
|||||||
|
|
||||||
# Configuração da interface de rede
|
# Configuração da interface de rede
|
||||||
network_device {
|
network_device {
|
||||||
bridge = "vmbr0"
|
bridge = "vmbr0" # rede de gestão para comunicação com Cluster A
|
||||||
}
|
}
|
||||||
|
|
||||||
initialization {
|
initialization {
|
||||||
@ -132,6 +132,7 @@ initialization {
|
|||||||
address = "dhcp"
|
address = "dhcp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
user_data_file_id = proxmox_virtual_environment_file.cloud_init_yaml.id
|
user_data_file_id = proxmox_virtual_environment_file.cloud_init_yaml.id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,6 +40,8 @@ variable "proxmox_k8s_vms" {
|
|||||||
vm_id = number
|
vm_id = number
|
||||||
node_name = string
|
node_name = string
|
||||||
ip = string
|
ip = string
|
||||||
|
ip2 = string
|
||||||
|
ip3 = string
|
||||||
cores = optional(number)
|
cores = optional(number)
|
||||||
memory = optional(number)
|
memory = optional(number)
|
||||||
data_store = optional(string)
|
data_store = optional(string)
|
||||||
|
|||||||
13
secrets-output/iac.ansible.hosts.ini
Normal file
13
secrets-output/iac.ansible.hosts.ini
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
[master]
|
||||||
|
master1 ansible_host=192.168.1.99 ansible_user=user ansible_ssh_pass=pass ansible_ssh_common_args='-o StrictHostKeyChecking=no'
|
||||||
|
|
||||||
|
[workers]
|
||||||
|
|
||||||
|
|
||||||
|
worker-192-168-1-101 ansible_host=192.168.1.101 ansible_user=user ansible_ssh_pass=pass ansible_ssh_common_args='-o StrictHostKeyChecking=no'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
1
secrets/iac.proxmox.ssh.link
Normal file
1
secrets/iac.proxmox.ssh.link
Normal file
@ -0,0 +1 @@
|
|||||||
|
proxmox-ssh.example.com
|
||||||
1
secrets/iac.vaultwarden-link
Normal file
1
secrets/iac.vaultwarden-link
Normal file
@ -0,0 +1 @@
|
|||||||
|
https://vaultwarden.example.com
|
||||||
@ -1,6 +1,6 @@
|
|||||||
proxmox_server = "proxmox.example.com"
|
#proxmox_server = "proxmox.example.com"
|
||||||
PM_API_TOKEN_ID = "tokenid"
|
#PM_API_TOKEN_ID = "tokenid"
|
||||||
PM_API_TOKEN_SECRET = "tokensecret"
|
#PM_API_TOKEN_SECRET = "tokensecret"
|
||||||
# tokenid is read automatically from PM_API_TOKEN_ID
|
# tokenid is read automatically from PM_API_TOKEN_ID
|
||||||
# token is read automatically from PM_API_TOKEN_SECRET
|
# token is read automatically from PM_API_TOKEN_SECRET
|
||||||
|
|
||||||
@ -20,6 +20,7 @@ proxmox_k8s_vms = [
|
|||||||
vm_id = 3001
|
vm_id = 3001
|
||||||
node_name = "node"
|
node_name = "node"
|
||||||
ip = "192.168.1.99/24"
|
ip = "192.168.1.99/24"
|
||||||
|
ip3 = "192.168.1.199/24"
|
||||||
cores = 2
|
cores = 2
|
||||||
memory = 2000
|
memory = 2000
|
||||||
disk_size = 32
|
disk_size = 32
|
||||||
@ -33,13 +34,14 @@ proxmox_k8s_vms = [
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
extra_packages = []
|
extra_packages = []
|
||||||
extra_runcmd = []
|
extra_runcmd = ["sudo ip addr add 192.168.1.199/24 dev eth0"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name = "k8s-worker-01"
|
name = "k8s-worker-01"
|
||||||
vm_id = 3002
|
vm_id = 3002
|
||||||
node_name = "node"
|
node_name = "node"
|
||||||
ip = "192.168.1.101/24"
|
ip = "192.168.1.101/24"
|
||||||
|
ip3 = "192.168.1.201/24"
|
||||||
cores = 1
|
cores = 1
|
||||||
memory = 2000
|
memory = 2000
|
||||||
disk_size = 32
|
disk_size = 32
|
||||||
@ -53,6 +55,6 @@ proxmox_k8s_vms = [
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
extra_packages = []
|
extra_packages = []
|
||||||
extra_runcmd = []
|
extra_runcmd = ["sudo ip addr add 192.168.1.201/24 dev eth0"]
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@ -16,6 +16,13 @@ resource "vaultwarden_account_register" "vaultwarden-acount-fenix" {
|
|||||||
password = var.vaultwarden_master_password
|
password = var.vaultwarden_master_password
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resource "bitwarden_item_login" "administrative-user" {
|
||||||
|
name = "teste"
|
||||||
|
username = "teste"
|
||||||
|
password = "teste"
|
||||||
|
collection_ids = [vaultwarden_organization_collection.vaultwarden-collection-iac.id]
|
||||||
|
}
|
||||||
|
|
||||||
resource "vaultwarden_organization" "vaultwarden-organization-fenix-iac" {
|
resource "vaultwarden_organization" "vaultwarden-organization-fenix-iac" {
|
||||||
name = "fenix-iac"
|
name = "fenix-iac"
|
||||||
}
|
}
|
||||||
@ -26,9 +33,28 @@ resource "vaultwarden_organization_collection" "vaultwarden-collection-iac" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
resource "bitwarden_item_login" "administrative-user" {
|
resource "bitwarden_item_secure_note" "hosts-ini" {
|
||||||
name = "teste"
|
name = "iac.ansible.hosts.ini"
|
||||||
username = "teste"
|
notes = <<EOT
|
||||||
password = "teste"
|
${local.hosts_ini}
|
||||||
|
EOT
|
||||||
|
organization_id = vaultwarden_organization.vaultwarden-organization-fenix-iac.id
|
||||||
collection_ids = [vaultwarden_organization_collection.vaultwarden-collection-iac.id]
|
collection_ids = [vaultwarden_organization_collection.vaultwarden-collection-iac.id]
|
||||||
|
reprompt = true
|
||||||
|
}
|
||||||
|
|
||||||
|
locals{
|
||||||
|
hosts_ini = <<EOT
|
||||||
|
|
||||||
|
[master]
|
||||||
|
master1 ansible_host=${split("/", var.proxmox_k8s_vms[0].ip)[0]} ansible_user=${var.proxmox_k8s_vms[0].extra_users[0].name} ansible_ssh_pass=${var.proxmox_k8s_vms[0].extra_users[0].password} ansible_ssh_common_args='-o StrictHostKeyChecking=no'
|
||||||
|
|
||||||
|
[workers]
|
||||||
|
%{ for i, vm in var.proxmox_k8s_vms ~}
|
||||||
|
%{ if i != 0 }
|
||||||
|
worker-${replace(split("/", vm.ip)[0], ".", "-")} ansible_host=${split("/", vm.ip)[0]} ansible_user=${vm.extra_users[0].name} ansible_ssh_pass=${vm.extra_users[0].password} ansible_ssh_common_args='-o StrictHostKeyChecking=no'
|
||||||
|
%{ endif }
|
||||||
|
%{ endfor }
|
||||||
|
|
||||||
|
EOT
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user