146 Commits

Author SHA1 Message Date
d04cc7477c [deploy-opentofu] 2025-09-10 22:01:24 +00:00
0b0e3db854 [deploy-opentofu] 2025-09-10 20:35:02 +00:00
fe6663673e LICENSE MIT
LICENSE MIT
2025-09-10 20:09:50 +00:00
2fcac46684 Update secrets/vaultwarden.secrets.tfvars 2025-09-08 16:14:59 +00:00
041f77429e Update secrets/proxmox.secrets.tfvars 2025-09-08 16:14:14 +00:00
88ab62e984 remove cat 2025-09-08 14:56:14 +00:00
df781f735e [deploy-opentofu] bw unlock correction 2025-09-08 14:50:29 +00:00
1b1b393991 [deploy-opentofu] bw unlock correction 2025-09-08 14:46:55 +00:00
2264ff0488 [deploy-opentofu] bw unlock correction 2025-09-08 14:40:10 +00:00
306b5eb9e7 [deploy-opentofu] bw unlock correction 2025-09-08 14:34:36 +00:00
ac1960d922 [deploy-opentofu] 2025-09-08 14:30:13 +00:00
70950eadb6 Update .gitea/workflows/ci-test.yaml 2025-09-07 23:28:23 +00:00
774001b5aa [deploy-opentofu] 2025-09-07 23:23:10 +00:00
c5d5cf2a10 [deploy-opentofu] 2025-09-07 23:15:36 +00:00
40007ba35f [deploy-opentofu] 2025-09-07 23:03:42 +00:00
c83f0f4aaa [deploy-opentofu] 2025-09-07 22:57:44 +00:00
82eddfd517 [deploy-opentofu] 2025-09-07 22:52:17 +00:00
727809dd6c [deploy-opentofu] 2025-09-07 22:49:02 +00:00
10e9475483 Update secrets/vault-secrets-map.json 2025-09-07 22:41:55 +00:00
0aad474652 [deploy-opentofu] 2025-09-07 22:37:17 +00:00
ba9652301a [deploy-opentofu] 2025-09-07 22:33:20 +00:00
e24dcb720e [deploy-opentofu] 2025-09-07 22:25:29 +00:00
b96751a4ce Update .gitea/workflows/ci-test.yaml 2025-09-07 22:17:55 +00:00
db2568ba7e [deploy-opentofu] 2025-09-07 22:11:57 +00:00
70d52b9784 [deploy-opentofu] 2025-09-07 22:03:48 +00:00
f96803b9be [deploy-opentofu] 2025-09-07 21:54:18 +00:00
b196c2ffd2 Update main.tf 2025-09-07 21:40:24 +00:00
cc06ed6c09 Update .gitea/workflows/ci-test.yaml 2025-09-07 21:29:58 +00:00
2155c97a3c [deploy-opentofu] 2025-09-07 21:22:08 +00:00
79397d70f1 [deploy-opentofu] 2025-09-07 21:15:48 +00:00
c3b3e828b0 [deploy-opentofu] 2025-09-07 21:10:00 +00:00
239313d556 Update secrets/vault-secrets-map.json 2025-09-07 21:08:36 +00:00
34c3ed14d6 [deploy-opentofu] 2025-09-07 21:03:20 +00:00
ea6271cd50 [deploy-opentofu] 2025-09-07 20:45:51 +00:00
65f6deccda [deploy-opentofu] 2025-09-07 20:39:19 +00:00
a04643f51e [deploy-opentofu] 2025-09-07 20:34:59 +00:00
493cae1f9a Update secrets/vault-secrets-map.json 2025-09-07 20:31:32 +00:00
419496ec3c Update .gitea/workflows/ci-test.yaml 2025-09-07 20:30:39 +00:00
0785512528 [deploy-opentofu] 2025-09-07 20:24:28 +00:00
6f6cff06e1 get via vaultwarden 2025-09-07 19:47:42 +01:00
f55b0d07b0 Update .gitea/workflows/ci-test.yaml 2025-09-01 16:48:52 +00:00
ab48730a54 Update .gitea/workflows/ci-test.yaml 2025-09-01 16:46:14 +00:00
e7dad50119 Update secrets/vaultwarden.secrets.tfvars 2025-09-01 16:16:53 +00:00
dc278c3dad Update .gitea/workflows/ci-test.yaml 2025-08-29 09:35:33 +00:00
a25012c4d9 testando o [deploy-opentofu] 2025-08-28 21:01:47 +00:00
0df8fc03a0 Update proxmox.tf 2025-08-28 17:10:29 +00:00
021ab2b057 Update proxmox.tf 2025-08-28 17:01:47 +00:00
37f5c52cc0 Update cloud-init-base.yaml 2025-08-28 16:57:04 +00:00
492bfc9519 Update proxmox.tf 2025-08-28 16:56:09 +00:00
db3fdaa087 Add cloud-init-wrapper.yaml.tftpl 2025-08-28 16:52:38 +00:00
9c0adce319 Update .gitea/workflows/ci-test.yaml 2025-08-28 16:51:11 +00:00
f071302722 revert 0d2aa11fca
revert Update .gitea/workflows/ci-test.yaml
2025-08-28 16:50:07 +00:00
cb04a5aa5c Update proxmox.tf 2025-08-28 16:12:25 +00:00
937231e815 Update proxmox.tf 2025-08-27 23:39:21 +00:00
31f0ffd1c6 Update proxmox.tf 2025-08-27 23:31:24 +00:00
2a895a8924 Update proxmox.tf 2025-08-27 23:26:10 +00:00
5d5f1b8a20 Update proxmox.tf 2025-08-27 22:54:37 +00:00
197a1656cb Update proxmox.tf 2025-08-27 22:49:23 +00:00
0a5caedfcd Update proxmox.tf 2025-08-27 22:42:39 +00:00
5f01a1ab40 Update cloud-init-base.yaml 2025-08-27 22:32:29 +00:00
5ae6d0f51c Update proxmox.tf 2025-08-27 22:23:01 +00:00
21f8b84b7d Update cloud-init-base.yaml 2025-08-27 22:03:18 +00:00
1b6c25cae3 Update cloud-init-base.yaml 2025-08-27 21:49:34 +00:00
680633fefe Update cloud-init-vm.yaml.tftpl 2025-08-27 21:42:50 +00:00
40d55dfd23 Update cloud-init-base.yaml 2025-08-27 21:41:22 +00:00
0fd1686f2a Update cloud-init-base.yaml 2025-08-27 20:44:26 +00:00
ae89f7062c Update cloud-init-vm.yaml.tftpl 2025-08-27 20:18:34 +00:00
783c4fcb33 Update merge_yaml.py 2025-08-27 20:10:20 +00:00
0d2aa11fca Update .gitea/workflows/ci-test.yaml 2025-08-27 20:06:05 +00:00
a6a980f24c Update merge_yaml.py 2025-08-27 19:58:06 +00:00
013518813f Update merge_yaml.py 2025-08-27 19:06:39 +00:00
82243fa145 Update cloud-init-vm.yaml.tftpl 2025-08-27 19:02:17 +00:00
2bfaa72d81 Update cloud-init-vm.yaml.tftpl 2025-08-27 19:00:51 +00:00
62af6c9c28 Update cloud-init-vm.yaml.tftpl 2025-08-27 18:36:14 +00:00
79a8acb794 Update cloud-init-vm.yaml.tftpl 2025-08-27 18:19:17 +00:00
13d33506e6 Update cloud-init-vm.yaml.tftpl 2025-08-27 18:06:33 +00:00
3b6f28c522 Update cloud-init-vm.yaml.tftpl 2025-08-27 17:36:12 +00:00
c160abf546 Update cloud-init-vm.yaml.tftpl 2025-08-27 17:18:02 +00:00
31434adc99 Update cloud-init-vm.yaml.tftpl 2025-08-27 17:00:14 +00:00
d42e297ca6 Update cloud-init-vm.yaml.tftpl 2025-08-27 14:13:19 +00:00
ec340b7f6b Update cloud-init-vm.yaml.tftpl 2025-08-27 14:02:41 +00:00
e866b5c2cf Update cloud-init-vm.yaml.tftpl 2025-08-27 13:52:41 +00:00
bf045fa7e8 Update cloud-init-vm.yaml.tftpl 2025-08-27 13:47:09 +00:00
6a18aa937b Update merge_yaml.py 2025-08-27 13:34:28 +00:00
d6a27d8f4f Update .gitea/workflows/ci-test.yaml 2025-08-27 13:31:31 +00:00
0a9d8a08de Update cloud-init-vm.yaml.tftpl 2025-08-27 13:20:57 +00:00
214a587e0f Update cloud-init-base.yaml 2025-08-27 13:20:39 +00:00
c7e9308a7a Update .gitea/workflows/ci-test.yaml 2025-08-27 13:10:48 +00:00
3ae0671e6d Update proxmox.tf 2025-08-27 11:33:36 +00:00
8e40b70b0f Update proxmox.tf 2025-08-27 11:25:34 +00:00
9fd88af475 Update proxmox.tf 2025-08-27 10:25:15 +00:00
08f2896c85 Update proxmox.tf 2025-08-27 10:17:40 +00:00
c49e9e6f55 Update proxmox.tf 2025-08-27 10:17:06 +00:00
017865126d python 2025-08-27 10:14:14 +00:00
95b9e4490b Add merge_yaml.py 2025-08-27 10:11:31 +00:00
2eb54cf48e Update proxmox.tf 2025-08-27 09:40:40 +00:00
86edcc3bf7 Update .gitea/workflows/ci-test.yaml 2025-08-27 09:32:42 +00:00
35a8f17063 Update .gitea/workflows/ci-test.yaml 2025-08-27 09:26:03 +00:00
cb6c6acd30 Update .gitea/workflows/ci-test.yaml 2025-08-27 09:18:06 +00:00
c496743fcf Update proxmox.tf 2025-08-27 09:13:17 +00:00
f0dcae1694 Update proxmox.tf 2025-08-27 09:09:04 +00:00
a216874980 Update proxmox.tf 2025-08-27 09:08:39 +00:00
aa63551529 Update proxmox.tf 2025-08-27 08:55:44 +00:00
7e1682b967 Update proxmox.tf 2025-08-27 08:41:44 +00:00
db9e04b0d8 Update proxmox.tf 2025-08-27 08:14:14 +00:00
3a09ab7222 Update proxmox.tf 2025-08-26 20:21:20 +00:00
efa41de3c6 Update proxmox.tf 2025-08-26 20:09:30 +00:00
6839b201c9 Update proxmox.tf 2025-08-26 20:04:29 +00:00
c63d01b7e6 Update proxmox.tf 2025-08-26 20:01:05 +00:00
48506d756a Update proxmox.tf 2025-08-26 19:46:24 +00:00
c633e14add Update proxmox.tf 2025-08-26 19:37:37 +00:00
b72966ae33 Update proxmox.tf 2025-08-26 19:33:14 +00:00
b2862089bf Update proxmox.tf 2025-08-26 19:28:49 +00:00
1676ce77ed Update proxmox.tf 2025-08-26 19:17:49 +00:00
59154e65fd Update proxmox.tf 2025-08-26 19:14:38 +00:00
f46e3007e9 Update proxmox.tf 2025-08-26 19:10:03 +00:00
08258abb83 Update proxmox.tf 2025-08-26 19:05:17 +00:00
0475a56863 Update proxmox.tf 2025-08-26 18:56:51 +00:00
dcf9395ca3 Update proxmox.tf 2025-08-26 18:53:17 +00:00
028bbb58d6 Update proxmox.tf 2025-08-26 18:49:31 +00:00
a8c97a6c88 Update proxmox.tf 2025-08-26 18:44:45 +00:00
104aa039d1 Update proxmox.tf 2025-08-26 18:35:29 +00:00
d1304f045f Update proxmox.tf 2025-08-26 18:23:57 +00:00
73c3603883 Update proxmox.tf 2025-08-26 18:13:45 +00:00
a04a7303f1 Update proxmox.tf 2025-08-26 18:07:34 +00:00
5559ecf0be Update proxmox.tf 2025-08-26 17:37:13 +00:00
70dc5ea228 Update proxmox.tf 2025-08-26 17:27:16 +00:00
cbf9c9db6f Update .gitea/workflows/ci-test.yaml 2025-08-26 17:22:02 +00:00
a6d3326ecb Update proxmox.tf 2025-08-26 17:16:50 +00:00
b36eaf88db Update proxmox.tf 2025-08-26 17:02:22 +00:00
084189f173 create cloud-init-base.yaml 2025-08-26 17:01:39 +00:00
2d1792d0dd create cloud-init-vm.yaml.tftpl 2025-08-26 16:59:44 +00:00
28f183d71b Update proxmox.tf 2025-08-26 16:01:30 +00:00
6aa9a02f48 datastore => data_store 2025-08-26 15:20:07 +00:00
95e93539d2 Update proxmox.variables.tf 2025-08-26 14:56:56 +00:00
7b64634e07 Update proxmox.tf 2025-08-26 14:32:23 +00:00
af66f5fceb Update proxmox.tf 2025-08-26 14:04:52 +00:00
bc73c25329 Update proxmox.tf 2025-08-26 14:01:07 +00:00
95243a04ff Update proxmox.tf 2025-08-26 13:49:09 +00:00
58644bdfa9 Update proxmox.tf 2025-08-26 13:37:28 +00:00
c8989775c9 not saved file 2025-08-26 14:19:56 +01:00
4ccb20b3c0 multiple vms 2025-08-26 14:17:45 +01:00
777c8cd299 Update proxmox.tf 2025-08-26 12:20:01 +00:00
d416cda06e Update proxmox.variables.tf 2025-08-26 11:32:00 +00:00
9842d62927 Merge branch 'fenix-admin' of https://gitea.fenix-dev.com/fenix-gitea-admin/iac-teste into fenix-admin 2025-08-25 18:41:02 +01:00
a6ca011a07 dockerfile for runner 2025-08-25 18:40:53 +01:00
14 changed files with 401 additions and 65 deletions

View File

@ -15,8 +15,22 @@ jobs:
PM_API_TOKEN_SECRET: ${{ secrets.PM_API_TOKEN_SECRET }}
BW_EMAIL: ${{ secrets.BW_EMAIL }}
BW_PASSWORD: ${{ secrets.BW_PASSWORD }}
BW_CLIENTID: ${{ secrets.BW_CLIENTID }}
BW_CLIENTSECRET: ${{ secrets.BW_CLIENTSECRET }}
VAULTWARDEN_LINK: ${{secrets.VAULTWARDEN_LINK }}
steps:
- name: Verificar se commit pede por [deploy-opentofu]
if: "!contains(gitea.event.head_commit.message, '[deploy-opentofu]')"
run: |
echo "Commit não contém [deploy-opentofu], a pipeline será ignorada."
exit 1
- name: Executar deploy opentofu
run: echo "Commit contém [deploy-opentofu], a pipeline será executada."
- name: Updating apt-get
run: |
apt-get update -y
@ -26,12 +40,12 @@ jobs:
with:
path: infra/iac
- name: cloning iac secrets repository
uses: actions/checkout@v4
with:
repository: fenix-gitea-admin/iac-teste-secrets
token: ${{ secrets.GGITEA_TOKEN }}
path: infra/secrets
#- name: cloning iac secrets repository
# uses: actions/checkout@v4
# with:
# repository: fenix-gitea-admin/iac-opentofu-private-secrets
# token: ${{ secrets.GGITEA_TOKEN }}
# path: infra/secrets
- name: Install cloudflare prerequisites
@ -69,16 +83,28 @@ jobs:
}
EOF
- name: vaultwarden urls as secrets
working-directory:
run: |
bw config server $VAULTWARDEN_LINK
bw login --apikey
BW_SESSION=$(bw unlock "$BW_PASSWORD" --raw)
bw get item "iac.proxmox-ssh-link" --session "$BW_SESSION" | jq -r '.notes' > "proxmox-ssh-link.txt"
- name: Start cloudflared Access TCP -> SOCKS5 (background)
env:
CF_SVC_ID: ${{ secrets.CF_SVC_ID }}
CF_SVC_SECRET: ${{ secrets.CF_SVC_SECRET }}
HOSTNAME: "proxmox-ssh.fenix-dev.com"
run: |
Hostname=$(cat proxmox-ssh-link.txt)
# 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.
nohup cloudflared access tcp \
--hostname "$HOSTNAME" \
--hostname "$Hostname" \
--listener "tcp://127.0.0.1:1081" \
--service-token-id "$CF_SVC_ID" \
--service-token-secret "$CF_SVC_SECRET" \
@ -109,22 +135,53 @@ jobs:
sleep 3
cat dante.log
- name: vaultwarden login
- name: vaultwarden getsecrets
working-directory: infra/iac
run: |
BW_SESSION=$(bw login)
BW_SESSION=$(bw unlock "$BW_PASSWORD" --raw)
# Ler o arquivo de referência
for secret in $(jq -c '.secrets[]' secrets/vault-secrets-map.json); do
name=$(echo "$secret" | jq -r '.name')
type=$(echo "$secret" | jq -r '.type')
output=$(echo "$secret" | jq -r '.output')
echo "$name $type $output"
item_id=$(bw get item "$name" | jq -r '.id')
echo "$item_id"
mkdir -p "$(dirname "$output")"
echo "dir made"
if [ "$type" == "attachment" ]; then
echo "attachment get"
bw get attachment "$output" --itemid "$item_id" --output "$output" --session "$BW_SESSION"
elif [ "$type" == "note" ]; then
echo "note get"
bw get item "$name" --session "$BW_SESSION" | jq -r '.notes' > "$output"
fi
done
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
pip install ruamel.yaml
- name: Init OpenTofu
working-directory: infra/iac
run: |
tofu init
tofu init
- name: Plan
working-directory: infra/iac
run: |
# Find all .auto.tfvars in the secrets folder
# Find all .tfvars in the secrets folder
VAR_FILES=""
for f in ../secrets/secrets/*.auto.tfvars; do
ls -la ../secrets/secrets
for f in ../secrets/secrets/*.tfvars; do
echo "found - $f"
VAR_FILES="$VAR_FILES -var-file=$f"
done
tofu plan $VAR_FILES -out=./tfplan | tee ./tfplan.txt

18
LICENSE Normal file
View File

@ -0,0 +1,18 @@
MIT License
Copyright (c) 2025 fenix-gitea-admin
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.

19
cloud-init-base.yaml Normal file
View File

@ -0,0 +1,19 @@
locale: "pt_PT.UTF-8"
keyboard:
layout: "pt"
variant: "nodeadkeys"
users:
- default
ssh_pwauth: true
package_update: true
packages:
- qemu-guest-agent
- net-tools
- curl
runcmd:
- systemctl enable qemu-guest-agent
- systemctl start qemu-guest-agent
- echo "done" > /tmp/cloud-config.done

36
cloud-init-vm.yaml.tftpl Normal file
View File

@ -0,0 +1,36 @@
package_update: true
%{ if length(each.value.extra_packages) > 0 ~}
packages:
%{ for pkg in each.value.extra_packages ~}
- ${pkg}
%{ endfor ~}
%{ endif ~}
%{ if length(each.value.extra_users) > 0 ~}
users:
%{ for u in each.value.extra_users ~}
- name: ${u.name}
groups:
%{ if length(u.groups) > 0 ~}
%{ for g in u.groups ~}
- ${g}
%{ endfor ~}
%{ endif ~}
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 ~}
%{ if length(each.value.extra_runcmd) > 0 ~}
runcmd:
%{ for cmd in each.value.extra_runcmd ~}
- ${cmd}
%{ endfor ~}
%{ endif ~}

View File

@ -0,0 +1,2 @@
#cloud-config
${content}

23
documentation/Dockerfile Normal file
View 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

View File

@ -1,9 +1,9 @@
https://spacelift.io/blog/opentofu-tutorial - explaining language of opentofu
https://spacelift.io/blog/opentofu-tutorial - explaining language of opentofu
https://opentofu.org/docs/intro/ - quick start and explaning who to work in team
https://opentofu.org/docs/intro/ - CICD for opentofu explained
tofu init

View File

@ -1,9 +1,5 @@
terraform {
required_providers {
random = {
source = "hashicorp/random"
version = "~> 3.6"
}
vaultwarden = {
source = "ottramst/vaultwarden"
version = "0.4.4"
@ -24,5 +20,3 @@ terraform {
lock = true # enable state locking
}
}
provider "random" {}

45
merge_yaml.py Normal file
View File

@ -0,0 +1,45 @@
#!/usr/bin/env python3
from ruamel.yaml import YAML
import sys
import json
from collections.abc import Mapping
def deep_merge_yaml(dict1, dict2):
result = dict1.copy()
for key, value in dict2.items():
if key in result:
if isinstance(result[key], list) and isinstance(value, list):
result[key] = result[key] + value
elif isinstance(result[key], Mapping) and isinstance(value, Mapping):
result[key] = deep_merge_yaml(result[key], value)
else:
result[key] = value
else:
result[key] = value
return result
def main():
input_data = json.load(sys.stdin)
file1 = input_data["file1"]
file2 = input_data["file2"]
yaml = YAML()
yaml.indent(mapping=2, sequence=4, offset=2)
with open(file1, "r") as f1, open(file2, "r") as f2:
yaml1 = yaml.load(f1)
yaml2 = yaml.load(f2)
merged = deep_merge_yaml(yaml1, yaml2)
from io import StringIO
output = StringIO()
yaml.dump(merged, output)
print(json.dumps({
"merged_yaml": output.getvalue()
}))
if __name__ == "__main__":
main()

View File

@ -30,32 +30,58 @@ resource "proxmox_virtual_environment_file" "cloud_init_yaml" {
source_raw {
file_name = "user-data-cloud-config.yaml"
data = <<-EOF
#cloud-config
users:
- default
- name: testeuser
groups: sudo
shell: /bin/bash
sudo: ALL=(ALL) NOPASSWD:ALL
data = file("${path.module}/cloud-init-base.yaml")
}
}
ssh_pwauth: true
chpasswd:
list: |
testeuser:testepassword
expire: false
locals {
rendered_yaml_per_vm ={
for vm in var.proxmox_k8s_vms : vm.name =>
templatefile("${path.module}/cloud-init-vm.yaml.tftpl",
{
each = {
value = vm
}
})
}
}
package_update: true
packages:
- qemu-guest-agent
- net-tools
- curl
runcmd:
- systemctl enable qemu-guest-agent
- systemctl start qemu-guest-agent
- echo "done" > /tmp/cloud-config.done
EOF
data "external" "merged_yaml" {
for_each = { for vm in var.proxmox_k8s_vms : vm.name => vm }
depends_on = [local_file.rendered_yaml_file]
program = ["python3", "${path.module}/merge_yaml.py"]
query = {
file1 = "${path.module}/cloud-init-base.yaml"
file2 = "${path.module}/cloud-init-extra-${each.key}.yaml"
}
}
resource "local_file" "rendered_yaml_file" {
for_each = { for vm in var.proxmox_k8s_vms : vm.name => vm }
content = local.rendered_yaml_per_vm[each.key]
filename = "${path.module}/cloud-init-extra-${each.key}.yaml"
}
# Gerar um snippet cloud-init por VM
resource "proxmox_virtual_environment_file" "vm_user_data" {
for_each = { for vm in var.proxmox_k8s_vms : vm.name => vm }
node_name = "fenix"
datastore_id = "local-snippets"
content_type = "snippets"
source_raw {
file_name = "cloud-init-iac-k8s-${each.key}.yaml"
data = templatefile("${path.module}/cloud-init-wrapper.yaml.tftpl", {
content = data.external.merged_yaml[each.key].result["merged_yaml"]
})
}
}
@ -85,13 +111,6 @@ resource "proxmox_virtual_environment_vm" "proxmox-kubernetes-VM-template" {
dedicated = 4096
}
# Configuração do disco rígido
disk {
datastore_id = "local-lvm"
interface = "scsi1"
size = 64
}
disk {
datastore_id = "local-lvm"
file_id = proxmox_virtual_environment_download_file.latest_ubunto_cloud_img.id
@ -102,32 +121,59 @@ resource "proxmox_virtual_environment_vm" "proxmox-kubernetes-VM-template" {
# Configuração da interface de rede
network_device {
bridge = "vmbr0"
model = "virtio"
}
initialization {
ip_config {
ipv4 {
address = "dhcp" # IP estático + máscara de rede
dns {
servers = ["1.1.1.1"]
}
ip_config {
ipv4 {
address = "dhcp"
}
}
}
user_data_file_id = proxmox_virtual_environment_file.cloud_init_yaml.id
}
}
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]
name = "VM-Kubernetes-01"
node_name = "fenix"
name = each.value.name
node_name = each.value.node_name
vm_id = each.value.vm_id
clone {
vm_id = proxmox_virtual_environment_vm.proxmox-kubernetes-VM-template.id
}
agent {
enabled = true
cpu {
cores = each.value.cores
}
}
memory {
dedicated = each.value.memory
}
disk {
datastore_id = each.value.data_store
size = each.value.disk_size
interface = "scsi1"
}
initialization {
ip_config {
ipv4 {
address = each.value.ip
gateway = each.value.gateway
}
}
user_data_file_id = proxmox_virtual_environment_file.vm_user_data[each.key].id
}
agent {
enabled = true
}
}

View File

@ -32,3 +32,25 @@ variable "proxmox_apikey" {
variable "node_name" {
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)
data_store = optional(string)
gateway = string
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))
}))
}

View File

@ -2,4 +2,57 @@ proxmox_server = "proxmox.example.com"
PM_API_TOKEN_ID = "tokenid"
PM_API_TOKEN_SECRET = "tokensecret"
# 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
proxmox_server = "https://proxmox.example.com:443/api2/json"
proxmox_apikey = "user@pam!token=fdjkdslfjdsflkj"
proxmox_server_ssh = "127.0.0.1:1080"
proxmox_username_ssh = "user"
proxmox_password_ssh = "password"
# tokenid is read automatically from PM_API_TOKEN_ID
# token is read automatically from PM_API_TOKEN_SECRET
proxmox_k8s_vms = [
{
name = "k8s-master-01"
vm_id = 3001
node_name = "node"
ip = "192.168.1.99/24"
cores = 2
memory = 2000
disk_size = 32
data_store = "local-lvm"
gateway = "192.168.1.1"
extra_users = [
{
name = "user"
password = "pass"
groups = ["sudo"]
}
]
extra_packages = []
extra_runcmd = []
},
{
name = "k8s-worker-01"
vm_id = 3002
node_name = "node"
ip = "192.168.1.101/24"
cores = 1
memory = 2000
disk_size = 32
data_store = "local-lvm"
gateway = "192.168.1.1"
extra_users = [
{
name = "user"
password = "pass"
groups = ["sudo"]
}
]
extra_packages = []
extra_runcmd = []
},
]

View File

@ -0,0 +1,19 @@
{
"secrets": [
{
"name": "iac.opentofu.consul.secrets",
"type": "note",
"output": "../secrets/secrets/consul.secrets.tfvars"
},
{
"name": "iac.opentofu.proxmox.secrets",
"type": "note",
"output": "../secrets/secrets/proxmox.secrets.tfvars"
},
{
"name": "iac.opentofu.vaultwarden.secrets",
"type": "note",
"output": "../secrets/secrets/vaultwarden.secrets.tfvars"
}
]
}

View File

@ -3,4 +3,6 @@ vaultwarden_email = "admin@example.com"
vaultwarden_master_password = "SuperSecretMasterPassword"
vaultwarden_admin_token = "tokenadmin"
vaultwarden_client_id = "clientid"
vaultwarden_client_secret = "clientsecret"
vaultwarden_client_secret = "clientsecret"
# email is read automatically from BW_EMAIL
# password is read automatically from BW_PASSWORD