2 Commits

6 changed files with 13 additions and 50 deletions

View File

@ -1,12 +1,12 @@
name: IAC name: IAC
on: on:
push: push:
branches: [ dev ] branches: [ dev ]
workflow_dispatch: workflow_dispatch:
jobs: jobs:
hello: hello:
#precisa da imagem costum do opentofu #precisa da imagem costum do opentofu
runs-on: [ fenix-opentofu ] runs-on: [ fenix-opentofu ]
env: env:
@ -35,11 +35,6 @@ 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:
@ -65,7 +60,7 @@ jobs:
- name: Install dante-server - name: Install dante-server
run: | run: |
apt-get install -y dante-server openssl libssl1.1 apt-get install -y dante-server
- name: Configure dante-server - name: Configure dante-server
@ -90,15 +85,12 @@ jobs:
- name: vaultwarden urls as secrets - name: vaultwarden urls as secrets
working-directory:
run: | run: |
echo "config"
bw config server $VAULTWARDEN_LINK bw config server $VAULTWARDEN_LINK
echo "login"
bw login --apikey bw login --apikey
echo "session"
BW_SESSION=$(bw unlock "$BW_PASSWORD" --raw) BW_SESSION=$(bw unlock "$BW_PASSWORD" --raw)
echo "$BW_SESSION"
echo "getting item"
bw get item "iac.proxmox.ssh.link" --session "$BW_SESSION" | jq -r '.notes' > "proxmox-ssh-link.txt" 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)
@ -139,7 +131,7 @@ jobs:
run: | run: |
pkill danted || true pkill danted || true
danted -f /etc/danted.conf -D > dante.log 2>&1 & danted -f /etc/danted.conf -D > dante.log 2>&1 &
sleep 3 sleep 3
cat dante.log cat dante.log
@ -147,7 +139,6 @@ jobs:
working-directory: infra/iac working-directory: infra/iac
run: | run: |
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
@ -165,7 +156,6 @@ 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

View File

@ -12,7 +12,7 @@ RUN apt-get update && apt-get install -y \
nodejs \ nodejs \
npm \ npm \
unzip \ unzip \
&& 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 \ 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 \ && unzip /tmp/bw.zip -d /usr/local/bin \

View File

@ -5,7 +5,7 @@ https://opentofu.org/docs/intro/ - quick start and explaning who to work in team
https://opentofu.org/docs/intro/ - CICD for opentofu explained https://opentofu.org/docs/intro/ - CICD for opentofu explained
tofu init tofu init
tofu plan --var-file=opentofu-varfile.json tofu plan --var-file=opentofu-varfile.json
yes yes

View File

@ -6,7 +6,7 @@ terraform {
} }
bitwarden = { bitwarden = {
source = "maxlaverse/bitwarden" source = "maxlaverse/bitwarden"
version = ">= 0.16.0" version = ">= 0.15.0"
} }
proxmox = { proxmox = {
source = "bpg/proxmox" source = "bpg/proxmox"

View File

@ -1,7 +1,7 @@
{ {
"secrets": [ "secrets": [
{ {
"name": "iac.opentofu.consul.secrets", "name": "iac.opentofu.consul.secrets",
"type": "note", "type": "note",
"output": "../secrets/secrets/consul.secrets.tfvars" "output": "../secrets/secrets/consul.secrets.tfvars"
}, },

View File

@ -25,37 +25,10 @@ resource "vaultwarden_organization_collection" "vaultwarden-collection-iac" {
name = "iac-collection" name = "iac-collection"
} }
resource "bitwarden_item_login" "administrative-user" { resource "bitwarden_item_login" "administrative-user" {
name = "teste" name = "teste"
username = "teste" username = "teste"
password = "teste" password = "teste"
collection_ids = [vaultwarden_organization_collection.vaultwarden-collection-iac.id] collection_ids = [vaultwarden_organization_collection.vaultwarden-collection-iac.id]
} }
resource "bitwarden_item_secure_note" "hosts-ini" {
name = "iac.ansible.hosts.ini"
notes = <<EOT
${local.hosts_ini}
EOT
organization_id = vaultwarden_organization.vaultwarden-organization-fenix-iac.id
collection_ids = [vaultwarden_organization_collection.vaultwarden-collection-iac.id]
reprompt = true
}
locals{
hosts_ini = <<EOT
[master]
master ansible_host=${var.proxmox_k8s_vms[0].ip} ansible_user=${var.proxmox_k8s_vms[0].extra_users[0].name} ansible_ssh_pass=${var.proxmox_k8s_vms[0].extra_users[0].password}
[workers]
%{ for i, vm in var.proxmox_k8s_vms ~}
%{ if i != 0 }
worker-${replace(vm.ip, ".", "-")} ansible_host=${vm.ip} ansible_user=${vm.extra_users[0].name} ansible_ssh_pass=${vm.extra_users[0].password}
%{ endif }
%{ endfor }
EOT
}