3 Commits
Author SHA1 Message Date
pi-ux-ce 85026544e8 can create new entries with random password not erased after new excution 2025-05-26 23:35:23 +01:00
pi-ux-ce 810fa2951a Update module.tf 2025-05-26 22:07:55 +00:00
pi-ux-ce 9f83ec215b try some bitwarden function 2025-05-20 23:56:32 +01:00
52 changed files with 2352 additions and 52900 deletions
-1
View File
@@ -1 +0,0 @@
9fdbb94c-0fd5-4ce2-919f-1fbb596cd318
-1
View File
@@ -1 +0,0 @@
2.pYoQjnuN9ZB+IqEypWrFPw==|/nlBG5qPy/zIFwYjjNXMuNWLU8pSt3TLR1/q4L3AEzi5Semc2261DyelXIfVpOn21JOGOV7jiIV6P3CSuASCjvCH+lCZSbjHfcj/MIOl3IBZJWF3vnTBVl3yjYD+Jmf0/zaYXbUW881oiO3Pu5Obc2jiBKNlX2bx5H11Iyi/fOmvR+EgsdequGgRm0FiSkjkbyG8d9bR55XR9NtS5x9a8EOhKWu0yXFGAKkDGV/m+j45z20mVTlAuuNDtIOX/rDKdKJpzg6SF8EuRTGC5RWAHJ+V8BACe3xxHi43YFit5RjpQ83F6rUGc+hc7TTcKyLA0Go7vUnKQ2wljSihM+HgJbGI6Sgnc9/Ys9AyDI0Bfz4EntfUqSeMBoaatvGpe3LYZdGysUMtDUoQWAvEfKbnnTKQRJb6zTD0RjhJ1ZowrrUFXyU9s1kNu3Sx29Q6h926lIiZ7kNejLcBEIJm0NjifAT9E0dwWTC6/bM2NrQpAotQBQGKGOGGRPIQW8vM7EJ6pl3ZSM/RzRnvQEdmWLNTbLd5eUd0efTviQr4BTxhwj7m3UGBUI/ZQhd3UNTU2ZVpt93nY2QPW3EpNpPBdYMnAgqbc3iz9mGZKtUwYpCwEpHj2G0CxCjgoj8il3Ys+vpPbYqpx+/FbibQLsELAbvLtK/TnDT5tq2gCYIHNUYL+iO+rdm8uGVWcFeMUBvyC/sdHEJgnQ3Rf6Up8lhgP3NQu6QgWT5gkGRrJ4RoYYET9919FOas43imUfWLEAaL/iU+NliGj3B0gCnwi1Ljm4+k5MOVHJqgcBdh0LHhNgIQcBurV0Qk8ZkoVnkTBjTMduOGogn9+Ny7B5D28nk8VW4fHL9MsgvYTZXZmI0QKgS2YzTmkle916qGLWgo5hcp5V4MG1EBpchzu0JJUUdPrb06txBr+cCCYvGi1B2epw6nJAJ7OGB4vzcJM/kVQYRVQmV/kfWXxtROCkx3CAKG5oyKMiiPcUiiqIIYuhRUEZYPC9+w67nMANPG8VcyqylcEba/FMSn4ECj7ce2iHCnyAnk9wb78P/YZdNMGbgviJq1nZm+OaGmpMxEoZHpyOe3EmuEKNpuSgqXGygR6ltAqzFRNJJlHm1PLHWxp4n4n5E1VhbaFiN2urTn/Pt2hqh0YEHyRVYYDSJv5QL8Dqq7WVYD2V3waLwi5Q5o6jc2XkaGN3hLg0fH7yO9KMa+MGUIcx5TZX+QGwiB4n/rZijV2h9d7th/tn0+/Gxtz+JcZ9J+4j4/1MR89vGe1EFOl9ZpUYxQVTVNuLoPaql5dXJZf3LeLL3fq05yNyW38NzcT5fFjevSRyRyoTHTrePCr5Tk5D0BaNQDhgDvBtC1kdo72HKR0+y1x31TxzLmc3OMBj2iqMxt0V7snwUfuVYu43LY48YML3wxRe/EVDmP6h8H89JWkw1aCJsLInN7hDSpUJtGBIn30c5r2kSw/87iVskVnQAUsQFMPOzUmDm6E07fnysbPwuAECuha93aMljzQNF4mwd6Pey24Pkfl+K7wypOL94iK1GcM4FqsCpNfD/X1M3Z+AVQahXAtUt82wmaXfQUtQ6Dvt6mfwFnknmWpyI9Pbj3r8lh4M5rffMFucJac32eoq+KY9xdhyPyep0becLQxNog2LiWliSQlfKBoB3X9FSyDalwEasWagUvNdENqkL+GWCxlCZK7g+ibvO5keA0Baqt1ohRcBoigNfmcTsZUPRhq+dy2cvaiPaGRDgX2DKlJdC8LnPDb/qTvk+uP5yZaKSItjdFkYo7c+fbOXH+I93Kd9IK+LJVM+9cWnx6yKBW/TaaEuZCBholtxME8ZQDcnXIelp67IamsfuVb5QNouZuimzb9rP9vEDVTdyE3e5rYzl2AaljMdTIjB1ut5ZqGA8=|hem/6+QHhqSdcTgKycZLP9EDBT3JA8fLIUqETgTITNk=
-2
View File
@@ -39,5 +39,3 @@ terraform.rc
module.tf.save* module.tf.save*
terraform.tfstate* terraform.tfstate*
.terraform.lock.hcl .terraform.lock.hcl
.bw-provider-state
+268 -1117
View File
File diff suppressed because it is too large Load Diff
-119
View File
@@ -1,119 +0,0 @@
variable "cronjob" {
type = map(object({
name = optional(string)
image = string
enabled = bool
namespace = optional(string)
connected_namespace = optional(string, "")
schedule = string
command = optional(list(string))
args = optional(list(string))
pvc = optional(map(object({
name = string
pvc = optional(bool, false)
config_map = optional(bool, false)
secret = optional(bool, false)
host_path = optional(string)
pvc_size = optional(string)
storage_class_name = optional(string, "nfs-storage-intelligent")
annotations_fileType = optional(string)
existing_pvc = optional(bool, false)
mount_path = string
sub_path = optional(string)
})))
}))
}
locals {
pvc_list = flatten([
for key, value in var.cronjob : [
for index, pvc in value.pvc : {
key = "${coalesce(value.namespace, value.connected_namespace, key)}/${pvc.name}"
index = index
pvc = pvc.pvc
name = pvc.name
pvc_size = pvc.pvc_size
mount_path = pvc.mount_path
storage_class_name = pvc.storage_class_name
annotations_fileType = pvc.annotations_fileType
existing_pvc = pvc.existing_pvc
sub_path = pvc.sub_path
namespace = coalesce(value.namespace, value.connected_namespace, key)
}] if value.enabled == true && value.pvc != null
])
# group duplicates instead of throwing an error
pvc_map_grouped = {
for p in local.pvc_list :
p.key => p...
}
# keep only one PVC per key (take the first)
pvc_map = {
for k, list in local.pvc_map_grouped :
k => list[0]
}
pvc_details = values(local.pvc_map)
}
resource "kubernetes_persistent_volume_claim_v1" "automatic-pvc-cronjob" {
for_each = { for key, value in local.pvc_details : "${value.index}" => merge(value, { mew_key = value.index }) if value.pvc && value.existing_pvc != true }
metadata {
namespace = coalesce(each.value.namespace, each.key)
name = "${each.value.name}-pvc"
labels = {
deployment_method = "Terraform"
}
annotations = {
fileType = try(each.value.annotations_fileType, "file")
}
}
spec {
access_modes = ["ReadWriteMany"]
storage_class_name = each.value.storage_class_name
resources {
requests = {
storage = each.value.pvc_size
}
}
}
}
resource "kubernetes_cron_job_v1" "automatic_cronjob" {
for_each = { for key, value in var.cronjob : key => value if value.enabled == true }
metadata {
name = "${each.key}-cronjob"
namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key)
labels = {
app = each.key
deployment_method = "Terraform"
}
}
spec {
schedule = each.value.schedule
job_template {
metadata {}
spec {
template {
metadata {}
spec {
container {
name = coalesce(each.value.name, each.key)
image = each.value.image
command = each.value.command != null ? each.value.command : []
args = each.value.args != null ? each.value.args : []
}
}
}
}
}
}
}
@@ -1,6 +0,0 @@
apiVersion: v1
kind: Secret
metadata:
name: bitwarden-identity-cert-password
namespace: bitwarden
type: Opaque
@@ -1,15 +0,0 @@
apiVersion: v1
kind: Service
metadata:
name: bitwarden-mssql-nodeport
namespace: bitwarden
spec:
ports:
- name: 1433bitwarden-m
nodePort: 31433
port: 1433
protocol: TCP
targetPort: 1433
selector:
app: bitwarden-mssql
type: NodePort
@@ -1,46 +0,0 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: bitwarden-calendar-backup
namespace: bitwarden
spec:
schedule: "0 0 * * *"
jobTemplate:
spec:
backoffLimit: 4
ttlSecondsAfterFinished: 100
template:
spec:
containers:
- name: bitwarden-database-backup
image: mcr.microsoft.com/mssql-tools
envFrom:
- secretRef:
name: bitwarden-mssql-db-terraform
optional: false
command: ["/bin/sh","-c"]
#args: ["mysqldump -h $DB_HOST -u $MYSQL_USER -p$MYSQL_ROOT_PASSWORD $MYSQL_DATABASE |gzip -9 > /backup/$(DB_DATABASE_NAME)-DB-$(date +%Y%m%d).sql.gz "]
args: ["sleep 3600"]
volumeMounts:
- name: backup
mountPath: /backup
volumes:
- name: backup
persistentVolumeClaim:
claimName: bitwarden-database-backup
restartPolicy: Never
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: bitwarden-database-backup
namespace: bitwarden
annotations:
fileType: Backup
spec:
storageClassName: nfs-storage-fastaccess
accessModes:
- ReadWriteMany
resources:
requests:
storage: 2Gi
File diff suppressed because it is too large Load Diff
@@ -1,11 +0,0 @@
apiVersion: v1
data:
APP_URL: https://bookstack.tryton.geeraert.eu
LOCAL_GID: "1000"
LOCAL_UID: "1000"
TZ: Europe/London
kind: ConfigMap
metadata:
name: config
namespace: bitwarden
@@ -1,20 +0,0 @@
apiVersion: v1
data:
ACCEPT_EULA: "Y"
ASPNETCORE_ENVIRONMENT: Production
globalSettings__baseServiceUri__vault: http://localhost
globalSettings__pushRelayBaseUri: https://push.bitwarden.com
globalSettings__selfHosted: "true"
globalSettings__baseServiceUri__internalNotifications: "http://bitwarden-notifications-svc:5000"
globalSettings__baseServiceUri__internalAdmin: "http://bitwarden-admin-svc:5000"
globalSettings__baseServiceUri__internalIdentity: "http://bitwarden-identity-svc:5000"
globalSettings__baseServiceUri__internalApi: "http://bitwarden-api-svc:5000"
globalSettings__baseServiceUri__internalVault: "http://bitwarden-web-svc:5000"
globalSettings__baseServiceUri__internalSso: "http://bitwarden-sso-svc:5000"
globalSettings__baseServiceUri__internalScim: "http://bitwarden-self-host-scim:5000"
kind: ConfigMap
metadata:
name: global.env
namespace: bitwarden
@@ -1,28 +0,0 @@
apiVersion: v1
data:
ACCEPT_EULA: "Y"
adminSettings__admins: pierre@geeraert.eu
globalSettings__baseServiceUri__vault: http://bitwarden.tryton.geeraert.eu
globalSettings__disableUserRegistration: "false"
globalSettings__duo__aKey: p9jCHtnG4NZNZu4SThpVlCuOF1oePGhu53Wa4RJwuyeqRAWQ0aJN7GsKYrGbYIYO
globalSettings__hibpApiKey: REPLACE
globalSettings__identityServer__certificatePassword: test
globalSettings__installation__id: c36aded0-b0f1-4252-920b-ac4c008fc920
globalSettings__installation__key: CtQE5U1tMJE4Dzk7N9DU
globalSettings__internalIdentityKey: I5TMbqmEjhw9uBNmFZ9rU6s1KN5xqAKXh7RSPfgyj2XQ4sjlP22SCupFn4IVhYX7
globalSettings__mail__replyToEmail: no-reply@bitwarden.tryton.geeraert.eu
globalSettings__mail__smtp__host: smtp.gmail.com
globalSettings__mail__smtp__password: vmxkiidikqwirpuh
globalSettings__mail__smtp__port: "587"
globalSettings__mail__smtp__ssl: "false"
globalSettings__mail__smtp__username: p3jh6qa2@gmail.com
globalSettings__oidcIdentityClientKey: w47pWOkPa6mrTkiPuKizitsiRTR6NH8ufI01u77zbZt3LUcKWJ4wchMn6ouiwN7V
globalSettings__sqlServer__connectionString: Data Source=tcp:bitwarden-mssql-svc,1433;Initial
Catalog=bitwarden_vault;Persist Security Info=False;User ID=sa;Password=ChQKWDIW73eSHzX1UyvGDAv4pFw6DVKM;MultipleActiveResultSets=False;Connect
Timeout=30;Encrypt=True;TrustServerCertificate=True
globalSettings__yubico__clientId: REPLACE
globalSettings__yubico__key: REPLACE
kind: ConfigMap
metadata:
name: global.override.env
namespace: bitwarden
@@ -1,16 +0,0 @@
apiVersion: v1
kind: Service
metadata:
labels:
deployment_method: manually
name: identity
namespace: bitwarden
spec:
ports:
- name: 5000bitwarden-i
port: 5000
protocol: TCP
targetPort: 5000
selector:
app: bitwarden-identity
type: ClusterIP
@@ -1,9 +0,0 @@
apiVersion: v1
data:
ACCEPT_EULA: "Y"
MSSQL_PID: Express
SA_PASSWORD: SECRET
kind: ConfigMap
metadata:
name: mssql.env
namespace: bitwarden
@@ -1,7 +0,0 @@
apiVersion: v1
data:
SA_PASSWORD: ChQKWDIW73eSHzX1UyvGDAv4pFw6DVKM
kind: ConfigMap
metadata:
name: mssql.override.env
namespace: bitwarden
@@ -1,8 +0,0 @@
apiVersion: v1
data:
LOCAL_GID: "1001"
LOCAL_UID: "1001"
kind: ConfigMap
metadata:
name: uid.env
namespace: bitwarden
@@ -1,10 +0,0 @@
apiVersion: v1
data:
DB_DATABASE_NAME: ZGphbmdv
DB_HOST: ZGphbmdvLWRiLXN2Yw==
DB_PASSWORD: U3VmZnJhZ2UtTW9uZXliYWdzLUlsbHVzaW9uNw==
DB_USERNAME: ZGphbmdvX3VzZXJuYW1l
kind: Secret
metadata:
name: django-db-credentials
namespace: django
@@ -1,17 +0,0 @@
---
apiVersion: v1
kind: Service
metadata:
name: django-db-nodeport
namespace: django
spec:
ports:
- name: http
nodePort: 32345
port: 5432
protocol: TCP
targetPort: 5432
selector:
app: django-db
type: NodePort
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
-1
View File
@@ -1 +0,0 @@
kubectl exec -it -n reverse-proxy deploy/reverse-proxy -c reverse-proxy -- nginx -s reload
@@ -1,23 +0,0 @@
apiVersion: v1
data:
nginx-http-auth.local: |
## Version 2022/08/06
# Fail2Ban jail configuration for nginx-http-auth
# To use more aggressive http-auth modes set filter parameter "mode" in jail.local:
# normal (default), aggressive (combines all), auth or fallback
# See "tests/files/logs/nginx-http-auth" or "filter.d/nginx-http-auth.conf" for usage example and details.
[nginx-http-auth]
enabled = false
port = http,https
filter = nginx-unauthorized
action = nginx-block-map
logpath = /var/log/nginx/backend_debug.log
maxretry = 5
kind: ConfigMap
metadata:
creationTimestamp: null
name: fail2ban-nginx-http-auth-jail
namespace: fail2ban
@@ -1,30 +0,0 @@
apiVersion: v1
data:
nginx-unauthorized.local: |
## Version 2022/08/06
# Fail2Ban filter configuration for nginx unauthorized
[INCLUDES]
before = common.conf
[Definition]
#original
#failregex = ^<HOST>.*"(GET|POST|HEAD).*" (401) .*$
#try this one
failregex = ^<HOST> - .* "(?:GET|POST|HEAD) [^"]+" 401
^<HOST> - .* upstream_status=401
#for servarr
^<HOST> -.*"GET /login\?returnUrl=/&loginFailed=true HTTP/.*" 200
^<HOST> -.*"POST /login\?returnUrl=/&loginFailed=true HTTP/.*" 200
#for bitwarden
^<HOST> -.*"POST /identity/accounts/prelogin *HTTP/.*" 200
#actionban = touch /tmp/<name>.ban
#actionunban = touch /tmp/<name>.unban
kind: ConfigMap
metadata:
creationTimestamp: null
name: fail2ban-nginx-unauthorized-filter
namespace: fail2ban
@@ -1,19 +0,0 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: role:service-acc
namespace: reverse-proxy
rules:
- apiGroups: [""]
resources:
- pods
- pods/exec
verbs:
- create
- list
- apiGroups: ["apps"]
resources:
- deployments
verbs:
- get
@@ -1,15 +0,0 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: rolebinding:service-acc
namespace: reverse-proxy
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: role:service-acc
subjects:
- kind: ServiceAccount
name: kubectl-service-account
namespace: fail2ban
@@ -1,6 +0,0 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: kubectl-service-account
namespace: fail2ban
@@ -1,58 +0,0 @@
apiVersion: v1
data:
nginx-block-map.local: "## Version 2022/08/06\n# Fail2Ban configuration file for
black-listing via nginx\n#\n# Author: Serg G. Brester (aka sebres)\n#\n# To use
'nginx-block-map' action you should define some special blocks in your nginx configuration,\n#
and use it hereafter in your locations (to notify fail2ban by failure, resp. nginx
by ban).\n#\n# Example (argument \"token_id\" resp. cookie \"session_id\" used
here as unique identifier for user):\n#\n# http {\n# ...\n# # maps to
check user is blacklisted (banned in f2b):\n# #map $arg_token_id $blck_lst_tok
{ include blacklisted-tokens.map; }\n# map $cookie_session_id $blck_lst_ses
{ include blacklisted-sessions.map; }\n# ...\n# # special log-format to
notify fail2ban about failures:\n# log_format f2b_session_errors '$msec failure
\"$cookie_session_id\" - $remote_addr - $remote_user '\n# ;# '\"$request\"
$status $bytes_sent '\n# # '\"$http_referer\" \"$http_user_agent\"';\n#\n#
\ # location checking blacklisted values:\n# location ... {\n# #
check banned sessionid:\n# if ($blck_lst_ses != \"\") {\n# try_files
\"\" @f2b-banned;\n# }\n# ...\n# # notify fail2ban about a failure
inside nginx:\n# error_page 401 = @notify-f2b;\n# ...\n# }\n#
\ ...\n# # location for return with \"403 Forbidden\" if banned:\n# location
@f2b-banned {\n# default_type text/html;\n# return 403 \"<br/><center>\n#
\ <b style=\\\"color:red; font-size:18pt; border:2pt solid black; padding:5pt;\\\">\n#
\ You are banned!</b></center>\";\n# }\n# ...\n# # location
to notify fail2ban about a failure inside nginx:\n# location @notify-f2b {\n#
\ access_log /var/log/nginx/f2b-auth-errors.log f2b_session_errors;\n# }\n#
\ }\n# ...\n#\n# Note that quote-character (and possibly other special characters)
are not allowed currently as session-id.\n# Thus please add any session-id validation
rule in your locations (or in the corresponding backend-service), \n# like in
example below:\n#\n# location ... {\n# if ($cookie_session_id !~ \"^[\\w\\-]+$\")
{\n# return 403 \"Wrong session-id\"\n# }\n# ...\n# }\n#\n# The
parameters for jail corresponding log-format (f2b_session_errors):\n#\n# [nginx-blck-lst]\n#
\ filter =\n# datepattern = ^Epoch\n# failregex = ^ failure \"<F-ID>[^\"]+</F-ID>\"
- <ADDR>\n# usedns = no\n#\n# The same log-file can be used for IP-related jail
(additionally to session-related, to ban very bad IPs):\n#\n# [nginx-blck-ip]\n#
\ maxretry = 100\n# filter =\n# datepattern = ^Epoch\n# failregex = ^ failure
\"[^\"]+\" - <ADDR>\n# usedns = no\n#\n\n[Definition]\n\n# path to configuration
of nginx (used to target nginx-instance in multi-instance system,\n# and as path
for the blacklisted map):\n#srv_cfg_path = /etc/nginx/\n\nsrv_cfg_path = /blacklisted.d/\n\n#
cmd-line arguments to supply to test/reload nginx:\n#srv_cmd = nginx -c %(srv_cfg_path)s/nginx.conf\nsrv_cmd
= nginx\n\n# pid file (used to check nginx is running):\nsrv_pid = /run/nginx.pid\n\n#
command used to check whether nginx is running and configuration is valid:\nsrv_is_running
= [ -f \"%(srv_pid)s\" ]\nsrv_check_cmd = %(srv_is_running)s && %(srv_cmd)s -qt\n\n#
first test nginx is running and configuration is correct, hereafter send reload
signal:\n#blck_lst_reload = %(srv_check_cmd)s; if [ $? -eq 0 ]; then\n# %(srv_cmd)s
-s reload; if [ $? -ne 0 ]; then echo 'reload failed.'; fi;\n# fi;\n\nrestart_file
= /restart-signal/restart.txt\n\nblck_lst_reload = touch %(restart_file)s;sleep
20; rm %(restart_file)s;\n\n# map-file for nginx, can be redefined using `action
= nginx-block-map[blck_lst_file=\"/path/file.map\"]`:\nblck_lst_file = %(srv_cfg_path)s/blacklisted-sessions.conf\n\n#
Action definition:\n\nactionstart_on_demand = false\nactionstart = touch '%(blck_lst_file)s'\n\nactionflush
= truncate -s 0 '%(blck_lst_file)s'; %(blck_lst_reload)s\n\nactionstop = %(actionflush)s\n\nactioncheck
= \n\n_echo_blck_row = printf '\\%%s 1;\\n' \"<fid>\"\n\nactionban = echo <ip>
| awk -F. '{print \"deny \"$1\".\"$2\".\"$3\".\"$4\";\"}' >> '%(blck_lst_file)s';
%(blck_lst_reload)s\n\nactionunban = id=$(%(_echo_blck_row)s | sed -e 's/[]\\/$*.^|[]/\\\\&/g');
sed -i \"/^$id$/d\" %(blck_lst_file)s; %(blck_lst_reload)s\n"
kind: ConfigMap
metadata:
creationTimestamp: null
name: nginx-block-map-action
namespace: fail2ban
@@ -1,124 +0,0 @@
## Version 2022/08/06
# Fail2Ban configuration file for black-listing via nginx
#
# Author: Serg G. Brester (aka sebres)
#
# To use 'nginx-block-map' action you should define some special blocks in your nginx configuration,
# and use it hereafter in your locations (to notify fail2ban by failure, resp. nginx by ban).
#
# Example (argument "token_id" resp. cookie "session_id" used here as unique identifier for user):
#
# http {
# ...
# # maps to check user is blacklisted (banned in f2b):
# #map $arg_token_id $blck_lst_tok { include blacklisted-tokens.map; }
# map $cookie_session_id $blck_lst_ses { include blacklisted-sessions.map; }
# ...
# # special log-format to notify fail2ban about failures:
# log_format f2b_session_errors '$msec failure "$cookie_session_id" - $remote_addr - $remote_user '
# ;# '"$request" $status $bytes_sent '
# # '"$http_referer" "$http_user_agent"';
#
# # location checking blacklisted values:
# location ... {
# # check banned sessionid:
# if ($blck_lst_ses != "") {
# try_files "" @f2b-banned;
# }
# ...
# # notify fail2ban about a failure inside nginx:
# error_page 401 = @notify-f2b;
# ...
# }
# ...
# # location for return with "403 Forbidden" if banned:
# location @f2b-banned {
# default_type text/html;
# return 403 "<br/><center>
# <b style=\"color:red; font-size:18pt; border:2pt solid black; padding:5pt;\">
# You are banned!</b></center>";
# }
# ...
# # location to notify fail2ban about a failure inside nginx:
# location @notify-f2b {
# access_log /var/log/nginx/f2b-auth-errors.log f2b_session_errors;
# }
# }
# ...
#
# Note that quote-character (and possibly other special characters) are not allowed currently as session-id.
# Thus please add any session-id validation rule in your locations (or in the corresponding backend-service),
# like in example below:
#
# location ... {
# if ($cookie_session_id !~ "^[\w\-]+$") {
# return 403 "Wrong session-id"
# }
# ...
# }
#
# The parameters for jail corresponding log-format (f2b_session_errors):
#
# [nginx-blck-lst]
# filter =
# datepattern = ^Epoch
# failregex = ^ failure "<F-ID>[^"]+</F-ID>" - <ADDR>
# usedns = no
#
# The same log-file can be used for IP-related jail (additionally to session-related, to ban very bad IPs):
#
# [nginx-blck-ip]
# maxretry = 100
# filter =
# datepattern = ^Epoch
# failregex = ^ failure "[^"]+" - <ADDR>
# usedns = no
#
[Definition]
# path to configuration of nginx (used to target nginx-instance in multi-instance system,
# and as path for the blacklisted map):
#srv_cfg_path = /etc/nginx/
srv_cfg_path = /blacklisted.d/
# cmd-line arguments to supply to test/reload nginx:
#srv_cmd = nginx -c %(srv_cfg_path)s/nginx.conf
srv_cmd = nginx
# pid file (used to check nginx is running):
srv_pid = /run/nginx.pid
# command used to check whether nginx is running and configuration is valid:
srv_is_running = [ -f "%(srv_pid)s" ]
srv_check_cmd = %(srv_is_running)s && %(srv_cmd)s -qt
# first test nginx is running and configuration is correct, hereafter send reload signal:
#blck_lst_reload = %(srv_check_cmd)s; if [ $? -eq 0 ]; then
# %(srv_cmd)s -s reload; if [ $? -ne 0 ]; then echo 'reload failed.'; fi;
# fi;
restart_file = /restart-signal/restart.txt
blck_lst_reload = kubectl exec -it -n reverse-proxy deploy/reverse-proxy -c reverse-proxy -- nginx -s reload
# map-file for nginx, can be redefined using `action = nginx-block-map[blck_lst_file="/path/file.map"]`:
blck_lst_file = %(srv_cfg_path)s/blacklisted-sessions.conf
# Action definition:
actionstart_on_demand = false
actionstart = touch '%(blck_lst_file)s'
actionflush = truncate -s 0 '%(blck_lst_file)s'; %(blck_lst_reload)s
actionstop = %(actionflush)s
actioncheck =
_echo_blck_row = printf '\%%s 1;\n' "<fid>"
actionban = kubectl exec -it -n reverse-proxy deploy/reverse-proxy -c reverse-proxy -- sh -c "echo 'deny <ip>;' > /etc/nginx/blacklisted.d/blacklisted-sessions.conf"; %(blck_lst_reload)s
actionunban = id=$(%(_echo_blck_row)s | sed -e 's/[]\/$*.^|[]/\\&/g'); sed -i "/^$id$/d" %(blck_lst_file)s; %(blck_lst_reload)s
@@ -1,12 +0,0 @@
apiVersion: v1
data:
VPN_DNS_IP: MTAuMi4wLjE=
VPN_ENDPOINT_IP: ODkuMTA1LjIxNC4xOTY=
VPN_ENDPOINT_PORT: NTE4MjA=
WIREGUARD_PRIVATE_KEY: Q0h3OHNkVUliaVRPbTgxTzZGOWRyMm9Nc2k1ZFl4SnZValo1Z2Jwd3UzWT0=
WIREGUARD_PUBLIC_KEY: WG4yQkwrdmhJZ2dsMnVKZ29HY2NqMG4wQ3Z3N09hZU5LMXdPZk91dElTUT0=
kind: Secret
metadata:
creationTimestamp: null
name: gluetun-secret-nl-free-280
namespace: gluetun
@@ -1,10 +0,0 @@
apiVersion: v1
data:
DB_DATABASE_NAME: aW1taWNo
DB_HOST: aW1taWNoLWRiLXN2Yw==
DB_PASSWORD: U3Bvb24tQm9yb3VnaC1CYXNpczg=
DB_USERNAME: aW1taWNo
kind: Secret
metadata:
name: immich-db-credentials
namespace: immich
@@ -5,9 +5,9 @@ data:
POSTGRES_PASSWORD: cGFwZXJsZXNz POSTGRES_PASSWORD: cGFwZXJsZXNz
PAPERLESS_ADMIN_USER: YWRtaW4= PAPERLESS_ADMIN_USER: YWRtaW4=
PAPERLESS_ADMIN_PASSWORD: YWRtaW4= PAPERLESS_ADMIN_PASSWORD: YWRtaW4=
POSTGRES_HOST: cGFwZXJsZXNzLWRiLXN2Yw== POSTGRES_HOST: cGFwZXItZGItc3Zj
kind: Secret kind: Secret
metadata: metadata:
name: paperless-credentials name: paperless-credentials
namespace: paperless namespace: paper
type: Opaque type: Opaque
@@ -1,5 +0,0 @@
[IMAP-1993]
documentation = *** note: this server will work for both Office 365 and personal Outlook/Hotmail accounts ***
server_address = outlook.office365.com
server_port = 993
local_address = 127.0.0.1
@@ -1,13 +0,0 @@
apiVersion: v1
data:
emailproxy.config: |
[IMAP-1993]
documentation = *** note: this server will work for both Office 365 and personal Outlook/Hotmail accounts ***
server_address = outlook.office365.com
server_port = 993
local_address = 127.0.0.1
kind: ConfigMap
metadata:
creationTimestamp: null
name: emailproxyconfig
namespace: paperless
@@ -1,45 +0,0 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: paperless-calendar-backup
namespace: paperless
spec:
schedule: "0 0 * * *"
jobTemplate:
spec:
backoffLimit: 4
ttlSecondsAfterFinished: 100
template:
spec:
containers:
- name: paperless-database-backup
image: alpine/psql
envFrom:
- secretRef:
name: paperless-db-terraform
optional: false
command: ["/bin/sh","-c"]
args: ["pg_dump |gzip -9 > /backup/$(DB_DATABASE_NAME)-DB-$(date +%Y%m%d).sql.gz "]
volumeMounts:
- name: backup
mountPath: /backup
volumes:
- name: backup
persistentVolumeClaim:
claimName: paperless-database-backup
restartPolicy: Never
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: paperless-database-backup
namespace: paperless
annotations:
fileType: Backup
spec:
storageClassName: nfs-storage-fastaccess
accessModes:
- ReadWriteMany
resources:
requests:
storage: 2Gi
@@ -6,5 +6,6 @@ data:
DB_USER: cHJvd2xhcnJfdXNlcm5hbWU= DB_USER: cHJvd2xhcnJfdXNlcm5hbWU=
kind: Secret kind: Secret
metadata: metadata:
creationTimestamp: null
name: prowlarr-credentials name: prowlarr-credentials
namespace: bookstack namespace: bookstack
@@ -6,5 +6,6 @@ data:
DB_USER: c2VydmFycl91c2VybmFtZQ== DB_USER: c2VydmFycl91c2VybmFtZQ==
kind: Secret kind: Secret
metadata: metadata:
creationTimestamp: null
name: servarr-db-credentials name: servarr-db-credentials
namespace: servarr namespace: servarr
+4 -6
View File
@@ -35,8 +35,8 @@ PROXY_HTTP="http://gluetun-svc.gluetun.svc:8888"
#BASE_URL="https://www.pornpics.com/pornstars/eiby-shine/" #BASE_URL="https://www.pornpics.com/pornstars/eiby-shine/"
#pornstars="eiby-shine" #pornstars="eiby-shine"
#BASE_URL="https://www.pornpics.com/pornstars/chloe-camilla/" BASE_URL="https://www.pornpics.com/?q=shy+imp"
#pornstars="chloe-camilla" pornstars="shy-imp"
#BASE_URL="https://www.pornpics.com/pornstars/becky-summer" #BASE_URL="https://www.pornpics.com/pornstars/becky-summer"
#pornstars="becky-summer" #pornstars="becky-summer"
@@ -44,9 +44,6 @@ PROXY_HTTP="http://gluetun-svc.gluetun.svc:8888"
#clear files beforehand #clear files beforehand
echo "Pornstar: "$pornstars
echo "URL: "$BASE_URL
mkdir -p $DESTINATION_FOLDER/$pornstars mkdir -p $DESTINATION_FOLDER/$pornstars
@@ -66,7 +63,7 @@ echo "" > $DESTINATION_FOLDER/$pornstars-image_to_download.txt
for f in $(cat $DESTINATION_FOLDER/$pornstars-urls_of_galleries.txt ); do for f in $(cat $DESTINATION_FOLDER/$pornstars-urls_of_galleries.txt ); do
$curl_command $f | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*" | grep "https://cdni.pornpics.com/" >> $DESTINATION_FOLDER/$pornstars-image_to_download.txt $curl_command $f | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*" | grep "https://cdni.pornpics.com/1280" >> $DESTINATION_FOLDER/$pornstars-image_to_download.txt
echo $f echo $f
done done
@@ -76,3 +73,4 @@ for g in $(cat $DESTINATION_FOLDER/$pornstars-image_to_download.txt ); do
# wget -e use_proxy=yes -e http_proxy=$PROXY_HTTP $g -P $DESTINATION_FOLDER/$pornstars # wget -e use_proxy=yes -e http_proxy=$PROXY_HTTP $g -P $DESTINATION_FOLDER/$pornstars
echo $g echo $g
done done
exit 0
@@ -1,85 +0,0 @@
#!/bin/bash
#install required packages
apk add curl wget
#named argument generation
skip_searching_gallery="${skip_searching_gallery:-false}"
while [ $# -gt 0 ]; do
if [[ $1 == "--"* ]]; then
v="${1/--/}"
declare "$v"="$2"
shift
fi
shift
done
#check if we will use a HTTP proxy or not
if [[ -z $http_proxy ]]; then
echo "not using proxy"
curl_command="curl"
else
echo "using proxy"
echo $http_proxy
curl_command="curl -x $http_proxy"
fi
#dowload from https://www.pornpics.com/pornstars/eiby-shine/
DESTINATION_FOLDER="/data"
PROXY_HTTP="http://gluetun-svc.gluetun.svc:8888"
#BASE_URL="https://www.pornpics.com/pornstars/eiby-shine/"
#pornstars="eiby-shine"
#BASE_URL="https://www.pornpics.com/?q=shy+imp"
#pornstars="shy-imp"
#BASE_URL="https://www.pornpics.com/pornstars/gloria-sol/"
#pornstars="gloria-sol"
#BASE_URL="https://www.pornpics.com/pornstars/becky-summer"
#pornstars="becky-summer"
#clear files beforehand
echo "Pornstar: "$pornstars
echo "URL: "$BASE_URL
mkdir -p $DESTINATION_FOLDER/$pornstars
if [[ $skip_searching_gallery == true ]]; then
echo "not looping through galleries"
echo "using existing file instead"
#because we need to keep the file $DESTINATION_FOLDER/$pornstars-urls_of_galleries.txt with the existing URL , in this condition,
#no deletion of this file
else
echo "looping through galleries"
#because we will re-generate this file, can be emptied
echo "" > $DESTINATION_FOLDER/$pornstars-urls_of_galleries.txt
$curl_command -s $BASE_URL | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*" | grep "https://www.pornpics.com/galleries/" |sort -u >> $DESTINATION_FOLDER/$pornstars-urls_of_galleries.txt
fi
echo "" > $DESTINATION_FOLDER/$pornstars-image_to_download.txt
for f in $(cat $DESTINATION_FOLDER/$pornstars-urls_of_galleries.txt ); do
echo "$curl_command $f"
$curl_command "$f"
$curl_command "$f" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*" | grep "https://cdni.pornpics.com/1280" >> $DESTINATION_FOLDER/$pornstars-image_to_download.txt
echo $f
done
for g in $(cat $DESTINATION_FOLDER/$pornstars-image_to_download.txt ); do
$curl_command -O --output-dir $DESTINATION_FOLDER/$pornstars "$g"
# wget -e use_proxy=yes -e http_proxy=$PROXY_HTTP $g -P $DESTINATION_FOLDER/$pornstars
echo $g
done
exit 0
@@ -6,24 +6,25 @@ data:
\"$v\"=\"$2\"\n shift\n fi\n shift\ndone\n\n#check if we will use \"$v\"=\"$2\"\n shift\n fi\n shift\ndone\n\n#check if we will use
a HTTP proxy or not\n\nif [[ -z $http_proxy ]]; then\n echo \"not using a HTTP proxy or not\n\nif [[ -z $http_proxy ]]; then\n echo \"not using
proxy\"\n curl_command=\"curl\"\nelse\n echo \"using proxy\"\n curl_command=\"curl proxy\"\n curl_command=\"curl\"\nelse\n echo \"using proxy\"\n curl_command=\"curl
-x $http_proxy\"\n\nfi\n\n\n#dowload from https://www.pornpics.com/pornstars/eiby-shine/\nDESTINATION_FOLDER=\"/data\"\nPROXY_HTTP=\"http://gluetun-svc.gluetun.svc:8888\"\n\n#BASE_URL=\"https://www.pornpics.com/pornstars/eiby-shine/\"\n#pornstars=\"eiby-shine\"\n\n#BASE_URL=\"https://www.pornpics.com/pornstars/chloe-camilla/\"\n#pornstars=\"chloe-camilla\"\n\n#BASE_URL=\"https://www.pornpics.com/pornstars/becky-summer\"\n#pornstars=\"becky-summer\"\n\n\n#clear -x $http_proxy\"\n\nfi\n\n\n#dowload from https://www.pornpics.com/pornstars/eiby-shine/\nDESTINATION_FOLDER=\"/data\"\nPROXY_HTTP=\"http://gluetun-svc.gluetun.svc:8888\"\n\n#BASE_URL=\"https://www.pornpics.com/pornstars/eiby-shine/\"\n#pornstars=\"eiby-shine\"\n\nBASE_URL=\"https://www.pornpics.com/?q=shy+imp\"\npornstars=\"shy-imp\"\n\n#BASE_URL=\"https://www.pornpics.com/pornstars/becky-summer\"\n#pornstars=\"becky-summer\"\n\n\n#clear
files beforehand\n\necho \"Pornstar: \"$pornstars\necho \"URL: \"$BASE_URL\n\n\nmkdir files beforehand\n\n\nmkdir -p $DESTINATION_FOLDER/$pornstars\n\nif [[ $skip_searching_gallery
-p $DESTINATION_FOLDER/$pornstars\n\nif [[ $skip_searching_gallery == true ]]; == true ]]; then\n echo \"not looping through galleries\"\n\t\techo \"using
then\n echo \"not looping through galleries\"\n\t\techo \"using existing existing file instead\"\n\t\t#because we need to keep the file $DESTINATION_FOLDER/$pornstars-urls_of_galleries.txt
file instead\"\n\t\t#because we need to keep the file $DESTINATION_FOLDER/$pornstars-urls_of_galleries.txt with the existing URL , in this condition, \n\t\t#no deletion of this file\necho
with the existing URL , in this condition, \n\t\t#no deletion of this file\nelse\n \"https://www.pornpics.com/galleries/onlyfans-shy-imp-starring-shy-imp-naked-porn-pics-90263490/\nhttps://www.pornpics.com/galleries/onlyfans-shy-imp-featuring-shy-imp-xxx-porn-pics-15741579/\nhttps://www.pornpics.com/galleries/onlyfans-shy-imp-starring-shy-imp-naked-photos-68925414/\nhttps://www.pornpics.com/galleries/onlyfans-shy-imp-shy-imp-20862921/\nhttps://www.pornpics.com/galleries/skinny-girl-with-pink-hair-shy-imp-shows-her-small-tits-during-a-solo-show-50988369/\nhttps://www.pornpics.com/galleries/onlyfans-shy-imp-featuring-shy-imp-hot-gallery-86312934/\"
\ echo \"looping through galleries\"\n\t\t#because we will re-generate this >> $DESTINATION_FOLDER/$pornstars-urls_of_galleries.txt\n\nelse\n echo
file, can be emptied\n\t\techo \"\" > $DESTINATION_FOLDER/$pornstars-urls_of_galleries.txt\n \"looping through galleries\"\n\t\t#because we will re-generate this file, can
be emptied\n\t\techo \"\" > $DESTINATION_FOLDER/$pornstars-urls_of_galleries.txt\n
\ $curl_command -s $BASE_URL | grep -Eo \"(http|https)://[a-zA-Z0-9./?=_%:-]*\" \ $curl_command -s $BASE_URL | grep -Eo \"(http|https)://[a-zA-Z0-9./?=_%:-]*\"
| grep \"https://www.pornpics.com/galleries/\" |sort -u >> $DESTINATION_FOLDER/$pornstars-urls_of_galleries.txt\nfi\n\necho | grep \"https://www.pornpics.com/galleries/\" |sort -u >> $DESTINATION_FOLDER/$pornstars-urls_of_galleries.txt\nfi\n\necho
\"\" > $DESTINATION_FOLDER/$pornstars-image_to_download.txt\n\n\nfor f in $(cat \"\" > $DESTINATION_FOLDER/$pornstars-image_to_download.txt\n\n\nfor f in $(cat
$DESTINATION_FOLDER/$pornstars-urls_of_galleries.txt ); do\n\t$curl_command $f $DESTINATION_FOLDER/$pornstars-urls_of_galleries.txt ); do\n\t$curl_command $f
| grep -Eo \"(http|https)://[a-zA-Z0-9./?=_%:-]*\" | grep \"https://cdni.pornpics.com/\" | grep -Eo \"(http|https)://[a-zA-Z0-9./?=_%:-]*\" | grep \"https://cdni.pornpics.com/1280\"
>> $DESTINATION_FOLDER/$pornstars-image_to_download.txt\n\techo $f\ndone\n\n\nfor >> $DESTINATION_FOLDER/$pornstars-image_to_download.txt\n\techo $f\ndone\n\n\nfor
g in $(cat $DESTINATION_FOLDER/$pornstars-image_to_download.txt ); do \n\t$curl_command g in $(cat $DESTINATION_FOLDER/$pornstars-image_to_download.txt ); do \n\t$curl_command
-O --output-dir $DESTINATION_FOLDER/$pornstars $g\n# wget -e use_proxy=yes -O --output-dir $DESTINATION_FOLDER/$pornstars $g\n# wget -e use_proxy=yes
-e http_proxy=$PROXY_HTTP $g -P $DESTINATION_FOLDER/$pornstars\n echo $g -e http_proxy=$PROXY_HTTP $g -P $DESTINATION_FOLDER/$pornstars\n echo $g
\ndone\n" \ndone\nexit 0\n"
kind: ConfigMap kind: ConfigMap
metadata: metadata:
creationTimestamp: null creationTimestamp: null
@@ -17,17 +17,13 @@ spec:
mountPropagation: None mountPropagation: None
name: data-pvc name: data-pvc
command: command:
# - /bin/bash
# - -c
# - sleep 3600
- bash - bash
- -c
- sleep 3600
# - bash
- /config/download.sh - /config/download.sh
- --http_proxy - --http_proxy
- "http://gluetun-svc.gluetun.svc:8888" - "http://gluetun-svc.gluetun.svc:8888"
- --BASE_URL
- "https://www.pornpics.com/?q=bretona"
- --pornstars
- "bretona"
restartPolicy: Never restartPolicy: Never
volumes: volumes:
- configMap: - configMap:
-15
View File
@@ -1,15 +0,0 @@
apiVersion: v1
kind: Service
metadata:
name: tdarr-svc-ext
namespace: servarr
spec:
ports:
- name: tdarr
nodePort: 30266
port: 8266
protocol: TCP
targetPort: 8266
selector:
app: tdarr
type: NodePort
@@ -6,5 +6,6 @@ data:
DB_USER: d2lraWpzX3VzZXJuYW1l DB_USER: d2lraWpzX3VzZXJuYW1l
kind: Secret kind: Secret
metadata: metadata:
creationTimestamp: null
name: wikijs-db-credentials name: wikijs-db-credentials
namespace: wikijs namespace: wikijs
+124 -409
View File
@@ -1,24 +1,58 @@
terraform { terraform {
required_version = "> 0.8.0" required_version = "> 0.8.0"
required_providers { required_providers {
bitwarden-secrets = { bitwarden = {
source = "bitwarden/bitwarden-secrets" source = "maxlaverse/bitwarden"
version = "0.5.4-pre" version = ">= 0.13.6"
} }
} }
} }
provider "kubernetes" { provider "kubernetes" {
config_path = "~/.kube/config" config_path = "~/.kube/config"
} }
provider "bitwarden" {
email = "pierre@geeraert.eu"
master_password = ""
server = "https://bitwarden.tryton.geeraert.eu"
experimental {
embedded_client = true
}
}
#https://stackoverflow.com/questions/66670949/how-to-tell-terraform-to-skip-the-secret-manager-resource-if-it-exists
#for the secret not overwritten (not tested)
data "bitwarden_item_login" "example" {
search = "bookstack.zeus.geeraert.eu"
}
provider "bitwarden-secrets" { data "bitwarden_item_secure_note" "vpn_preshared_key" {
api_url = "https://bitwarden.tryton.geeraert.eu/api" search = "terraform testing"
identity_url = "https://bitwarden.tryton.geeraert.eu/identity" }
access_token = "0.9f4b7c5f-e6e7-4eff-929e-b474016a2b9c.bMRELajGGb7qMuXXvzgCCJdDfxfTCS:mFDT7tHSi43KJSnkwvTSYg==" output "pgpin" {
value = nonsensitive(coalesce(data.bitwarden_item_secure_note.vpn_preshared_key.field.1.hidden,1234))
sensitive = true
}
resource "random_password" "password" {
length = 16
special = true
override_special = "!#$%&*()-_=+[]{}<>:?"
}
resource "bitwarden_item_secure_note" "terraform_upload_testing" {
name = "terraform upload testing"
# notes = <<EOT
#[global]
#secret = "<something sensitive>"
#EOT
organization_id = "a6361589-badd-4bde-9cb4-af8901161c0d" organization_id = "a6361589-badd-4bde-9cb4-af8901161c0d"
collection_ids = ["3fa902cd-8244-46bc-a4ea-af8901262d94"]
field {
name = "category"
hidden = random_password.password.result
}
} }
variable "kubernetes" { variable "kubernetes" {
@@ -26,17 +60,13 @@ variable "kubernetes" {
name = optional(string) name = optional(string)
image = string image = string
pvc = optional(map(object({ pvc = optional(map(object({
name = string name = string
pvc = optional(bool, false) pvc = optional(bool, false)
config_map = optional(bool, false) config_map = optional(bool, false)
secret = optional(bool, false) host_path = optional(string)
host_path = optional(string) pvc_size = optional(string)
pvc_size = optional(string) storage_class_name = optional(string, "nfs-storage-intelligent")
storage_class_name = optional(string, "nfs-storage-intelligent") mount_path = string
annotations_fileType = optional(string)
existing_pvc = optional(bool, false)
mount_path = string
sub_path = optional(string)
}))) })))
environment = optional(map(object({ environment = optional(map(object({
name = optional(string) name = optional(string)
@@ -48,26 +78,22 @@ variable "kubernetes" {
}) })
})) }))
}))) })))
replicas = optional(number, 1) replicas = optional(number, 1)
namespace = optional(string) namespace = optional(string)
connected_namespace = optional(string, "") connected_namespace = optional(string, "")
command = optional(list(string)) # namespace = optional(string,coalesce(connected_namespace,""))
#block_namespace_creation = optional(bool, false)
service_port = optional(list(number)) service_port = optional(list(number))
service_type = optional(string, "ClusterIP") service_type = optional(string, "ClusterIP")
service_name = optional(string) service_name = optional(string)
domain_name = optional(string)
liveness_tcp_socket = optional(number) liveness_tcp_socket = optional(number)
liveness_http_get = optional(string) liveness_http_get = optional(string)
liveness_http_get_path = optional(string) liveness_http_get_path = optional(string)
database = optional(map(string)) database = optional(map(string))
database_command = optional(list(string))
database_args = optional(list(string))
redis = optional(map(string)) redis = optional(map(string))
enabled = optional(bool, true) enabled = optional(bool, true)
secret_ref = optional(list(string)) secret_ref = optional(list(string))
config_map_ref = optional(list(string)) config_map_ref = optional(list(string))
config_map_import = optional(list(string))
secret_import = optional(list(string))
extra_manifest = optional(list(string)) extra_manifest = optional(list(string))
requirements = optional(map(string)) requirements = optional(map(string))
# requirements = optional(map(string), { # requirements = optional(map(string), {
@@ -77,66 +103,25 @@ variable "kubernetes" {
# requests-memory = "200Mi" # requests-memory = "200Mi"
# }) # })
dns_nameservers = optional(string) dns_nameservers = optional(string)
service_account_name = optional(string)
environment_variables = optional(map(string), { name = "value" }) environment_variables = optional(map(string), { name = "value" })
security_context = optional(bool, false) security_context = optional(bool, false)
})) }))
} }
variable "database_backup_info" {
type = map(object({
image = optional(string)
command = optional(string)
}))
description = "based on DB engine, give the docker image and the command used to backup"
default = {
postgres = {
image = "alpine/psql"
command = "pg_dump |gzip -9 > /backup/$(DB_DATABASE_NAME)-DB-$(date +%Y%m%d).sql.gz"
}
mysql = {
image = "mysql"
command = "mysqldump -h $DB_HOST -u $MYSQL_USER -p$MYSQL_ROOT_PASSWORD $MYSQL_DATABASE |gzip -9 > /backup/$(DB_DATABASE_NAME)-DB-$(date +%Y%m%d).sql.gz"
}
sqlserver = {
image = "mcr.microsoft.com/mssql-tools"
command = "/opt/mssql-tools/bin/sqlcmd -S $DB_HOST -U $DB_USERNAME -P $DB_PASSWORD -Q \"BACKUP DATABASE $DB_DATABASE_NAME TO DISK = '/backup/$DB_DATABASE_NAME-$(date +%Y%m%d).bak' WITH COPY_ONLY, CHECKSUM,FORMAT, MEDIANAME = 'SQLServerBackups',NAME = 'Full Backup of SQLTestDB'\";exit"
}
}
}
locals { locals {
pvc_list = flatten([ pvc_details = flatten([
for key, value in var.kubernetes : [ for key, value in var.kubernetes : [
for index, pvc in value.pvc : { for index, pvc in value.pvc : {
key = "${coalesce(value.namespace, value.connected_namespace, key)}/${pvc.name}" index = index
index = index pvc = pvc.pvc
pvc = pvc.pvc name = pvc.name
name = pvc.name pvc_size = pvc.pvc_size
pvc_size = pvc.pvc_size mount_path = pvc.mount_path
mount_path = pvc.mount_path storage_class_name = pvc.storage_class_name
storage_class_name = pvc.storage_class_name namespace = coalesce(value.namespace, value.connected_namespace, key)
annotations_fileType = pvc.annotations_fileType
existing_pvc = pvc.existing_pvc
sub_path = pvc.sub_path
namespace = coalesce(value.namespace, value.connected_namespace, key)
}] if value.enabled == true && value.pvc != null }] if value.enabled == true && value.pvc != null
]) ])
# group duplicates instead of throwing an error
pvc_map_grouped = {
for p in local.pvc_list :
p.key => p...
}
# keep only one PVC per key (take the first)
pvc_map = {
for k, list in local.pvc_map_grouped :
k => list[0]
}
pvc_details = values(local.pvc_map)
} }
locals { locals {
@@ -152,7 +137,7 @@ locals {
data "kubernetes_all_namespaces" "allns" {} data "kubernetes_all_namespaces" "allns" {}
resource "kubernetes_namespace_v1" "automatic" { resource "kubernetes_namespace" "automatic" {
for_each = { for key, value in var.kubernetes : key => value if value.enabled == true && value.connected_namespace == "" } for_each = { for key, value in var.kubernetes : key => value if value.enabled == true && value.connected_namespace == "" }
metadata { metadata {
annotations = { annotations = {
@@ -190,20 +175,15 @@ resource "kubernetes_manifest" "manifest" {
resource "kubernetes_persistent_volume_claim_v1" "automatic-pvc" { resource "kubernetes_persistent_volume_claim" "automatic-pvc" {
for_each = { for key, value in local.pvc_details : "${value.index}" => merge(value, { mew_key = value.index }) if value.pvc && value.existing_pvc != true } for_each = { for key, value in local.pvc_details : "${value.index}" => merge(value, { mew_key = value.index }) if value.pvc }
metadata { metadata {
namespace = coalesce(each.value.namespace, each.key) namespace = coalesce(each.value.namespace, each.key)
name = "${each.value.name}-pvc" name = "${each.value.name}-pvc"
labels = { labels = {
deployment_method = "Terraform" deployment_method = "Terraform"
} }
annotations = {
fileType = try(each.value.annotations_fileType, "file")
}
} }
spec { spec {
access_modes = ["ReadWriteMany"] access_modes = ["ReadWriteMany"]
storage_class_name = each.value.storage_class_name storage_class_name = each.value.storage_class_name
@@ -214,8 +194,8 @@ resource "kubernetes_persistent_volume_claim_v1" "automatic-pvc" {
} }
} }
} }
resource "kubernetes_persistent_volume_claim_v1" "automatic-pvc-database" { resource "kubernetes_persistent_volume_claim" "automatic-pvc-database" {
for_each = { for key, value in var.kubernetes : key => value if value.database != null && value.enabled == true && !(try(value.database.shunt, false)) } for_each = { for key, value in var.kubernetes : key => value if value.database != null && value.enabled == true }
metadata { metadata {
namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key) namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key)
name = "${each.key}-db-pvc" name = "${each.key}-db-pvc"
@@ -234,29 +214,7 @@ resource "kubernetes_persistent_volume_claim_v1" "automatic-pvc-database" {
} }
} }
resource "kubernetes_persistent_volume_claim_v1" "backup-pvc-database" { resource "kubernetes_persistent_volume_claim" "automatic-pvc-redis" {
for_each = { for key, value in var.kubernetes : key => value if value.database != null && value.enabled == true }
metadata {
namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key)
name = "${each.key}-db-backup"
labels = {
deployment_method = "Terraform"
}
annotations = {
fileType = "Backup" }
}
spec {
access_modes = ["ReadWriteMany"]
storage_class_name = "nfs-storage-fastaccess"
resources {
requests = {
storage = "1Gi"
}
}
}
}
resource "kubernetes_persistent_volume_claim_v1" "automatic-pvc-redis" {
for_each = { for key, value in var.kubernetes : key => value if value.redis != null && value.enabled == true } for_each = { for key, value in var.kubernetes : key => value if value.redis != null && value.enabled == true }
metadata { metadata {
namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key) namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key)
@@ -276,7 +234,7 @@ resource "kubernetes_persistent_volume_claim_v1" "automatic-pvc-redis" {
} }
} }
resource "kubernetes_service_v1" "automatic_service" { resource "kubernetes_service" "automatic_service" {
for_each = { for key, value in var.kubernetes : key => value if value.service_port != null && value.enabled == true } for_each = { for key, value in var.kubernetes : key => value if value.service_port != null && value.enabled == true }
metadata { metadata {
name = "${each.key}-svc" name = "${each.key}-svc"
@@ -300,7 +258,7 @@ resource "kubernetes_service_v1" "automatic_service" {
content { content {
port = port.value port = port.value
target_port = port.value target_port = port.value
name = replace("${port.value}${each.key}", "/(.{0,15})(.*)/", "$1") name = replace("${each.key}${port.value}", "/(.{0,15})(.*)/", "$1")
} }
} }
@@ -317,14 +275,13 @@ resource "kubernetes_service_v1" "automatic_service" {
} }
resource "kubernetes_service_v1" "automatic_service_database" { resource "kubernetes_service" "automatic_service_database" {
for_each = { for key, value in var.kubernetes : key => value if value.database != null && value.enabled == true && !(try(value.database.shunt, false)) } for_each = { for key, value in var.kubernetes : key => value if value.database != null && value.enabled == true }
metadata { metadata {
name = "${each.key}-db-svc" name = "${each.key}-db-svc"
namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key) namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key)
labels = { labels = {
deployment_method = "Terraform" deployment_method = "Terraform"
#username = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_password[each.key].key}"
} }
} }
spec { spec {
@@ -343,7 +300,7 @@ resource "kubernetes_service_v1" "automatic_service_database" {
resource "kubernetes_service_v1" "automatic_service_redis" { resource "kubernetes_service" "automatic_service_redis" {
for_each = { for key, value in var.kubernetes : key => value if value.redis != null && value.enabled == true } for_each = { for key, value in var.kubernetes : key => value if value.redis != null && value.enabled == true }
metadata { metadata {
name = "${each.key}-redis-svc" name = "${each.key}-redis-svc"
@@ -403,7 +360,7 @@ resource "kubernetes_deployment_v1" "automatic" {
content { content {
container_port = port.value container_port = port.value
# name = "${each.key}-${port.value}" # name = "${each.key}-${port.value}"
name = replace("${port.value}${each.key}", "/(.{0,15})(.*)/", "$1") name = replace("${each.key}${port.value}", "/(.{0,15})(.*)/", "$1")
} }
} }
@@ -413,44 +370,12 @@ resource "kubernetes_deployment_v1" "automatic" {
content { content {
mount_path = volume_mount.value.mount_path mount_path = volume_mount.value.mount_path
name = "${volume_mount.value.name}-pvc" name = "${volume_mount.value.name}-pvc"
sub_path = volume_mount.value.sub_path != null ? volume_mount.value.sub_path : ""
} }
} }
dynamic "volume_mount" {
for_each = try(each.value.database.engine == "sqlserver", false) && try(each.value.database.shunt, false) ? [1] : []
content {
mount_path = "/backup"
name = "${each.key}-db-backup"
}
}
dynamic "env_from" { dynamic "env_from" {
for_each = each.value.secret_ref != null ? each.value.secret_ref : [] for_each = each.value.secret_ref != null ? each.value.secret_ref : []
content {
dynamic "secret_ref" {
for_each = [1]
content {
name = env_from.value
}
}
}
}
dynamic "env_from" {
for_each = each.value.database != null && each.value.enabled == true && !(try(each.value.database.shunt, false)) ? ["${each.key}-db-terraform"] : []
#for_each = each.value.database != null && each.value.enabled == true ? ["${each.key}-db-terraform"] : []
content {
dynamic "secret_ref" {
for_each = [1]
content {
name = env_from.value
}
}
}
}
dynamic "env_from" {
for_each = each.value.database != null && each.value.enabled == true ? ["${each.key}-db-mapped-terraform"] : []
content { content {
dynamic "secret_ref" { dynamic "secret_ref" {
for_each = [1] for_each = [1]
@@ -472,8 +397,6 @@ resource "kubernetes_deployment_v1" "automatic" {
} }
} }
command = each.value.command != null ? each.value.command : []
dynamic "env" { dynamic "env" {
for_each = each.value.environment != null ? each.value.environment : {} for_each = each.value.environment != null ? each.value.environment : {}
@@ -488,6 +411,7 @@ resource "kubernetes_deployment_v1" "automatic" {
content { content {
name = env.value.value_from.secret_key_ref.name name = env.value.value_from.secret_key_ref.name
key = env.value.value_from.secret_key_ref.key key = env.value.value_from.secret_key_ref.key
# optional = true
} }
} }
} }
@@ -510,6 +434,16 @@ resource "kubernetes_deployment_v1" "automatic" {
} }
} }
# resources {
# limits = {
# cpu = each.value.requirements.limits-cpu
# memory = each.value.requirements.limits-memory
# }
# requests = {
# cpu = each.value.requirements.requests-cpu
# memory = each.value.requirements.requests-memory
# }
# }
dynamic "security_context" { dynamic "security_context" {
for_each = each.value.security_context == true ? [1] : [] for_each = each.value.security_context == true ? [1] : []
@@ -550,7 +484,6 @@ resource "kubernetes_deployment_v1" "automatic" {
} }
} }
service_account_name = each.value.service_account_name != null ? each.value.service_account_name : null
dynamic "volume" { dynamic "volume" {
for_each = each.value.pvc != null ? each.value.pvc : {} for_each = each.value.pvc != null ? each.value.pvc : {}
@@ -578,41 +511,24 @@ resource "kubernetes_deployment_v1" "automatic" {
} }
} }
dynamic "secret" {
for_each = volume.value.secret ? [1] : []
content {
secret_name = volume.value.name
}
}
} }
} }
dynamic "volume" {
for_each = try(each.value.database.engine == "sqlserver", false) && try(each.value.database.shunt, false) ? [1] : []
content {
name = "${each.key}-db-backup"
persistent_volume_claim {
claim_name = "${each.key}-db-backup"
}
}
}
} }
} }
} }
depends_on = [kubernetes_persistent_volume_claim_v1.automatic-pvc]
} }
resource "kubernetes_deployment_v1" "database-automatic" { resource "kubernetes_deployment_v1" "database-automatic" {
for_each = { for key, value in var.kubernetes : key => value if value.database != null && value.enabled == true && !(try(value.database.shunt, false)) } for_each = { for key, value in var.kubernetes : key => value if value.database != null && value.enabled == true }
metadata { metadata {
namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key) namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key)
name = "${coalesce(each.value.name, each.key)}-db" name = "${coalesce(each.value.namespace, each.key)}-db"
labels = { labels = {
app = each.key app = each.key
deployment_method = "Terraform" deployment_method = "Terraform"
@@ -650,32 +566,13 @@ resource "kubernetes_deployment_v1" "database-automatic" {
} }
volume_mount { volume_mount {
mount_path = try(each.value.database.mountPath, "/var/lib/postgresql/") mount_path = try(each.value.database.mountPath, "/var/lib/postgresql/data")
name = "${each.key}-db-pvc" name = "${each.key}-db-pvc"
} }
dynamic "volume_mount" {
for_each = try(each.value.database.engine == "sqlserver", false) && !(try(each.value.database.shunt, false)) ? [1] : []
content {
mount_path = "/backup"
name = "${each.key}-db-backup"
}
}
command = try([each.value.database.command], [])
args = each.value.database_args != null ? each.value.database_args : []
dynamic "env_from" {
for_each = each.value.database != null && each.value.enabled == true && !(try(each.value.database.shunt, false)) ? ["${each.key}-db-terraform"] : []
content {
dynamic "secret_ref" {
for_each = [1]
content {
name = env_from.value
}
}
}
}
dynamic "env" { dynamic "env" {
for_each = each.value.environment != null ? each.value.environment : {} for_each = each.value.environment != null ? each.value.environment : {}
@@ -700,6 +597,40 @@ resource "kubernetes_deployment_v1" "database-automatic" {
} }
# resources {
# limits = {
# cpu = each.value.requirements.limits-cpu
# memory = each.value.requirements.limits-memory
# }
# requests = {
# cpu = each.value.requirements.requests-cpu
# memory = each.value.requirements.requests-memory
# }
# }
# dynamic "liveness_probe" {
# for_each = each.value.liveness_tcp_socket != null || each.value.liveness_http_get != null ? [""] : []
# content {
# dynamic "tcp_socket" {
# for_each = each.value.liveness_tcp_socket != null ? [""] : []
# content {
# port = each.value.liveness_tcp_socket
# }
# }
# dynamic "http_get" {
# for_each = each.value.liveness_http_get != null ? [""] : []
# content {
# port = each.value.liveness_http_get
# path = coalesce(each.value.liveness_http_get_path, "/")
# }
# }
# initial_delay_seconds = 3
# period_seconds = 3
# }
# }
} }
@@ -710,70 +641,6 @@ resource "kubernetes_deployment_v1" "database-automatic" {
} }
} }
dynamic "volume" {
for_each = try(each.value.database.engine == "sqlserver", false) && !(try(each.value.database.shunt, false)) ? [1] : []
content {
name = "${each.key}-db-backup"
persistent_volume_claim {
claim_name = "${each.key}-db-backup"
}
}
}
}
}
}
}
resource "kubernetes_cron_job_v1" "database-backup" {
for_each = { for key, value in var.kubernetes : key => value if value.database != null && value.enabled == true }
metadata {
name = "${coalesce(each.value.namespace, each.key)}-db-backup"
namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key)
labels = {
app = each.key
deployment_method = "Terraform"
database = "true"
}
}
spec {
failed_jobs_history_limit = 5
schedule = "1 0 * * *"
timezone = "Etc/UTC"
successful_jobs_history_limit = 5
job_template {
metadata {}
spec {
backoff_limit = 4
ttl_seconds_after_finished = 100
template {
metadata {}
spec {
container {
name = "${coalesce(each.value.namespace, each.key)}-db-backup"
image = try(var.database_backup_info[each.value.database.engine].image, var.database_backup_info.postgres.image)
command = ["/bin/sh", "-c"]
args = [try(var.database_backup_info[each.value.database.engine].command, var.database_backup_info.postgres.command)]
env_from {
secret_ref {
name = "${each.key}-db-terraform"
}
}
volume_mount {
mount_path = "/backup"
name = "${each.key}-db-backup"
}
}
volume {
name = "${each.key}-db-backup"
persistent_volume_claim {
claim_name = "${each.key}-db-backup"
}
}
}
}
} }
} }
} }
@@ -786,7 +653,7 @@ resource "kubernetes_deployment_v1" "redis-automatic" {
metadata { metadata {
namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key) namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key)
name = "${coalesce(each.value.name, each.key)}-redis" name = "${coalesce(each.value.namespace, each.key)}-redis"
labels = { labels = {
app = each.key app = each.key
deployment_method = "Terraform" deployment_method = "Terraform"
@@ -903,155 +770,3 @@ resource "kubernetes_deployment_v1" "redis-automatic" {
} }
} }
} }
resource "kubernetes_config_map_v1" "automatic-configmap" {
metadata {
name = "extra-sites-terraform"
namespace = "reverse-proxy"
annotations = {
"reloader.stakater.com/match" : "true",
}
}
data = {
for key, value in var.kubernetes :
"${value.domain_name}.conf" => templatefile("nginx_config.tftpl", {
name_site = value.domain_name
name_service = "${key}-svc.${coalesce(value.namespace, value.connected_namespace, key)}.svc:${value.service_port.0}"
}) if value.domain_name != null && value.enabled == true
}
}
data "bitwarden-secrets_secret" "configmap_import" {
for_each = {
for pair in flatten([
for k, v in var.kubernetes : [
for id in v.config_map_import : {
map_key = k
secret_id = id
}
] if v.config_map_import != null && v.enabled == true
]) : "${pair.map_key}-${pair.secret_id}" => pair.secret_id
}
id = each.value
}
resource "kubernetes_config_map_v1" "configmap_import" {
for_each = { for key, value in data.bitwarden-secrets_secret.configmap_import : key => value }
metadata {
name = each.value.note
namespace = split("__", each.value.key)[0]
}
data = yamldecode(each.value.value)
}
data "bitwarden-secrets_secret" "secret_import" {
for_each = {
for pair in flatten([
for k, v in var.kubernetes : [
for id in v.secret_import : {
map_key = k
secret_id = id
}
] if v.secret_import != null && v.enabled == true
]) : "${pair.map_key}-${pair.secret_id}" => pair.secret_id
}
id = each.value
}
resource "kubernetes_secret_v1" "secret_import" {
for_each = { for key, value in data.bitwarden-secrets_secret.secret_import : key => value }
metadata {
name = each.value.note
namespace = split("__", each.value.key)[0]
}
data = yamldecode(each.value.value)
}
resource "kubernetes_secret_v1" "automatic-database-secret" {
for_each = { for key, value in var.kubernetes : key => value if value.database != null && value.enabled == true }
metadata {
name = "${each.key}-db-terraform"
namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key)
}
data = {
DB_DATABASE_NAME = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_name[each.key].value}"
DB_DATABASE = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_name[each.key].value}"
POSTGRES_DB = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_name[each.key].value}"
MYSQL_DATABASE = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_name[each.key].value}"
PGDATABASE = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_name[each.key].value}"
DB_HOST = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_host[each.key].value}"
PGHOST = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_host[each.key].value}"
POSTGRES_HOST = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_host[each.key].value}"
DB_PASSWORD = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_password[each.key].value}"
MYSQL_PASSWORD = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_password[each.key].value}"
MYSQL_ROOT_PASSWORD = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_password[each.key].value}"
POSTGRES_PASSWORD = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_password[each.key].value}"
PGPASSWORD = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_password[each.key].value}"
DB_USERNAME = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_username[each.key].value}"
POSTGRES_USER = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_username[each.key].value}"
MYSQL_USER = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_username[each.key].value}"
PGUSER = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_username[each.key].value}"
DATABASE_URL = "postgresql://${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_username[each.key].value}:${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_password[each.key].value}@${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_host[each.key].value}:${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_port[each.key].value}/${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_name[each.key].value}"
}
}
resource "kubernetes_secret_v1" "automatic-database-mapped-secret" {
for_each = { for key, value in var.kubernetes : key => value if value.database != null && value.enabled == true }
metadata {
name = "${each.key}-db-mapped-terraform"
namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key)
}
data = {
"${try(each.value.database.map_name, "DB_DATABASE_NAME")}" = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_name[each.key].value}"
"${try(each.value.database.map_host, "DB_DATABASE_NAME")}" = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_host[each.key].value}"
"${try(each.value.database.map_password, "DB_DATABASE_NAME")}" = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_password[each.key].value}"
"${try(each.value.database.map_username, "DB_DATABASE_NAME")}" = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_db_username[each.key].value}"
}
}
resource "bitwarden-secrets_secret" "automatic_bitwarden_secret_db_username" {
for_each = { for key, value in var.kubernetes : key => value if value.database != null && value.enabled == true }
key = "${each.key}__db__username"
value = try(each.value.database.username, each.key)
project_id = "b5fc4c48-e951-442f-97ca-b3e800c143cd"
}
resource "bitwarden-secrets_secret" "automatic_bitwarden_secret_db_password" {
for_each = { for key, value in var.kubernetes : key => value if value.database != null && value.enabled == true }
key = "${each.key}__db__password"
project_id = "b5fc4c48-e951-442f-97ca-b3e800c143cd"
length = 32
special = true
min_special = 5
avoid_ambiguous = true
}
resource "bitwarden-secrets_secret" "automatic_bitwarden_secret_db_host" {
for_each = { for key, value in var.kubernetes : key => value if value.database != null && value.enabled == true }
key = "${each.key}__db__host"
project_id = "b5fc4c48-e951-442f-97ca-b3e800c143cd"
value = try(each.value.database.host, "${each.key}-db-svc.${coalesce(each.value.namespace, each.value.connected_namespace, each.key)}.svc")
}
resource "bitwarden-secrets_secret" "automatic_bitwarden_secret_db_port" {
for_each = { for key, value in var.kubernetes : key => value if value.database != null && value.enabled == true }
key = "${each.key}__db__port"
project_id = "b5fc4c48-e951-442f-97ca-b3e800c143cd"
value = try(each.value.database.port, 5432)
}
resource "bitwarden-secrets_secret" "automatic_bitwarden_secret_db_name" {
for_each = { for key, value in var.kubernetes : key => value if value.database != null && value.enabled == true }
key = "${each.key}__db__name"
project_id = "b5fc4c48-e951-442f-97ca-b3e800c143cd"
value = try(each.value.database.name, each.key)
}
+185
View File
@@ -0,0 +1,185 @@
terraform {
required_version = "> 0.8.0"
}
provider "kubernetes" {
config_path = "~/.kube/config"
}
resource "kubernetes_namespace" "screeps" {
metadata {
annotations = {
name = "screeps"
}
name = "screeps"
}
}
resource "kubernetes_persistent_volume_claim" "screeps-pvc" {
metadata {
namespace = "screeps"
name = "screeps-pvc"
}
spec {
access_modes = ["ReadWriteMany"]
storage_class_name = "nfs-storage-intelligent"
resources {
requests = {
storage = "1Gi"
}
}
}
}
resource "kubernetes_deployment_v1" "screeps" {
metadata {
namespace = "screeps"
name = "screeps"
labels = {
app = "screepsserver"
}
}
spec {
replicas = 1
selector {
match_labels = {
app = "screepsserver"
}
}
template {
metadata {
labels = {
app = "screepsserver"
}
}
spec {
container {
image = "screepers/screeps-launcher"
name = "screeps-launcher"
port {
container_port = 21025
name = "screeps-port"
}
volume_mount {
mount_path = "/screeps"
name = "screeps-volume"
}
resources {
limits = {
cpu = "2"
memory = "2Gi"
}
requests = {
cpu = "250m"
memory = "500Mi"
}
}
}
volume {
name = "screeps-volume"
persistent_volume_claim {
claim_name = "screeps-pvc"
}
}
}
}
}
}
resource "kubernetes_service" "screeps_service" {
metadata {
name = "screeps"
namespace = "screeps"
}
spec {
selector = {
app = "screepsserver"
}
port {
port = 21025
}
}
}
variable "kubernetes" {
type = map(object({
service = string
#testingbool= bool
pvc_name = optional(string)
namespace = optional(string)
service_port = optional(number)
LoadBalancerbool = optional(string)
enabled = optional(bool, true)
proxy_cache = optional(bool, false)
extra-value = optional(string, "")
http2_bool = optional(bool, false)
proxy_pass_https = optional(bool, false)
authentication_required = optional(bool, false)
}))
}
resource "kubernetes_namespace" "automatic" {
for_each = { for key, value in var.kubernetes : key => value if value.enabled == true }
metadata {
annotations = {
name = coalesce(each.value.namespace, each.key)
}
name = coalesce(each.value.namespace, each.key)
}
}
resource "kubernetes_persistent_volume_claim" "automatic-pvc" {
for_each = { for key, value in var.kubernetes : key => value if value.pvc_name != null }
metadata {
namespace = coalesce(each.value.namespace, each.key)
name = coalesce(each.value.namespace, each.key)
}
spec {
access_modes = ["ReadWriteMany"]
storage_class_name = "nfs-storage-intelligent"
resources {
requests = {
storage = "1Gi"
}
}
}
}
resource "kubernetes_service" "automatic_service" {
for_each = { for key, value in var.kubernetes : key => value if value.service_port != null }
metadata {
name = coalesce(each.value.namespace, each.key)
namespace = coalesce(each.value.namespace, each.key)
}
spec {
selector = {
app = "screepsserver"
}
port {
port = each.value.service_port
}
if(each.value.LoadBalancerbool == "enabled" ? [type = "LoadBalancer"] :[]
}
}
}
-90
View File
@@ -1,90 +0,0 @@
############################################
# config file for ${name_site}
############################################
upstream ${name_site}_backend {
server ${name_service};
server 1.1.1.1 backup;
}
server {
server_name ${name_site}.tryton.geeraert.eu www.${name_site}.tryton.geeraert.eu;
location / {
proxy_pass http://${name_site}_backend;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
}
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
access_log /var/log/nginx/access.log my_custom_format;
access_log /var/log/nginx/ip_audit.log ip_audit;
listen 443 ssl;
ssl_certificate /etc/nginx/ssl/live/tryton.geeraert.eu/fullchain.pem;
ssl_certificate_key /etc/nginx/ssl/live/tryton.geeraert.eu/privkey.pem;
}
server {
if ($host = www.${name_site}.tryton.geeraert.eu) {
return 301 https://$host$request_uri;
}
if ($host = ${name_site}.tryton.geeraert.eu) {
return 301 https://$host$request_uri;
}
server_name www.${name_site}.tryton.geeraert.eu ${name_site}.tryton.geeraert.eu;
listen 80;
return 404;
}
############################################
# config file for ${name_site}
############################################
upstream ${name_site}_backend_root {
server ${name_service};
server 1.1.1.1 backup;
}
server {
server_name ${name_site}.geeraert.eu www.${name_site}.geeraert.eu;
location / {
proxy_pass http://${name_site}_backend_root;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
}
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
access_log /var/log/nginx/access.log my_custom_format;
access_log /var/log/nginx/ip_audit.log ip_audit;
listen 443 ssl;
ssl_certificate /etc/nginx/ssl/live/geeraert.eu/fullchain.pem;
ssl_certificate_key /etc/nginx/ssl/live/geeraert.eu/privkey.pem;
}
server {
if ($host = www.${name_site}.geeraert.eu) {
return 301 https://$host$request_uri;
}
if ($host = ${name_site}.geeraert.eu) {
return 301 https://$host$request_uri;
}
server_name www.${name_site}.geeraert.eu ${name_site}.geeraert.eu;
listen 80;
return 404;
}
-56
View File
@@ -1,56 +0,0 @@
resource "bitwarden-secrets_secret" "automatic_bitwarden_secret_redis_host" {
for_each = { for key, value in var.kubernetes : key => value if value.redis != null && value.enabled == true }
key = "${each.key}__redis__host"
project_id = "b5fc4c48-e951-442f-97ca-b3e800c143cd"
value = try(each.value.redis.host, "${each.key}-redis-svc.${coalesce(each.value.namespace, each.value.connected_namespace, each.key)}.svc")
}
resource "bitwarden-secrets_secret" "automatic_bitwarden_secret_redis_port" {
for_each = { for key, value in var.kubernetes : key => value if value.redis != null && value.enabled == true }
key = "${each.key}__redis__port"
project_id = "b5fc4c48-e951-442f-97ca-b3e800c143cd"
value = try(each.value.redis.port, 5432)
}
##
## Commenting until I use the redis password option
##
#resource "bitwarden-secrets_secret" "automatic_bitwarden_secret_redis_password" {
# for_each = { for key, value in var.kubernetes : key => value if value.redis != null && value.enabled == true }
# key = "${each.key}__redis__password"
# project_id = "b5fc4c48-e951-442f-97ca-b3e800c143cd"
# length = 32
# special = true
# min_special = 5
# avoid_ambiguous = true
#}
resource "bitwarden-secrets_secret" "automatic_bitwarden_secret_redis_REPLICATION_MODE" {
for_each = { for key, value in var.kubernetes : key => value if value.redis != null && value.enabled == true }
key = "${each.key}__redis__REPLICATION_MODE"
project_id = "b5fc4c48-e951-442f-97ca-b3e800c143cd"
value = try(each.value.redis.REPLICATION_MODE, "master")
}
resource "bitwarden-secrets_secret" "automatic_bitwarden_secret_redis_TLS_ENABLED" {
for_each = { for key, value in var.kubernetes : key => value if value.redis != null && value.enabled == true }
key = "${each.key}__redis__TLS_ENABLED"
project_id = "b5fc4c48-e951-442f-97ca-b3e800c143cd"
value = try(each.value.redis.TLS_ENABLED, "no")
}
resource "kubernetes_secret_v1" "automatic-redis-secret" {
for_each = { for key, value in var.kubernetes : key => value if value.redis != null && value.enabled == true }
metadata {
name = "${each.key}-redis-terraform"
namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key)
}
data = {
REDIS_HOSTNAME = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_redis_host[each.key].value}"
REDIS_PORT = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_redis_port[each.key].value}"
REDIS_REPLICATION_MODE = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_redis_REPLICATION_MODE[each.key].value}"
REDIS_TLS_ENABLED = "${resource.bitwarden-secrets_secret.automatic_bitwarden_secret_redis_TLS_ENABLED[each.key].value}"
}
}
+734 -21101
View File
File diff suppressed because one or more lines are too long
+794 -21162
View File
File diff suppressed because one or more lines are too long
+223 -1875
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff