Initial commit

Signed-off-by: TuDatTr <tuan-dat.tran@tudattr.dev>
main
TuDatTr 2023-11-21 14:55:39 +01:00
commit c41fc4ef81
7 changed files with 277 additions and 0 deletions

34
.gitignore vendored Normal file
View File

@ -0,0 +1,34 @@
# Local .terraform directories
**/.terraform/*
# .tfstate files
*.tfstate
*.tfstate.*
# Crash log files
crash.log
crash.*.log
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
*.tfvars
*.tfvars.json
# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json
# Include override files you do wish to add to version control using negated pattern
# !example_override.tf
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*
# Ignore CLI configuration files
.terraformrc
terraform.rc

22
.terraform.lock.hcl Normal file
View File

@ -0,0 +1,22 @@
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/kubernetes" {
version = "2.23.0"
constraints = "2.23.0"
hashes = [
"h1:xyFc77aYkPoU4Xt1i5t0B1IaS8TbTtp9aCSuQKDayII=",
"zh:10488a12525ed674359585f83e3ee5e74818b5c98e033798351678b21b2f7d89",
"zh:1102ba5ca1a595f880e67102bbf999cc8b60203272a078a5b1e896d173f3f34b",
"zh:1347cf958ed3f3f80b3c7b3e23ddda3d6c6573a81847a8ee92b7df231c238bf6",
"zh:2cb18e9f5156bc1b1ee6bc580a709f7c2737d142722948f4a6c3c8efe757fa8d",
"zh:5506aa6f28dcca2a265ccf8e34478b5ec2cb43b867fe6d93b0158f01590fdadd",
"zh:6217a20686b631b1dcb448ee4bc795747ebc61b56fbe97a1ad51f375ebb0d996",
"zh:8accf916c00579c22806cb771e8909b349ffb7eb29d9c5468d0a3f3166c7a84a",
"zh:9379b0b54a0fa030b19c7b9356708ec8489e194c3b5e978df2d31368563308e5",
"zh:aa99c580890691036c2931841e88e7ee80d59ae52289c8c2c28ea0ac23e31520",
"zh:c57376d169875990ac68664d227fb69cd0037b92d0eba6921d757c3fd1879080",
"zh:e6068e3f94f6943b5586557b73f109debe19d1a75ca9273a681d22d1ce066579",
"zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c",
]
}

2
README.org Normal file
View File

@ -0,0 +1,2 @@
* Terraform Homelab
This repo contains the terraform configuration for my homelab to deploy various services.

5
namespaces.tf Normal file
View File

@ -0,0 +1,5 @@
resource "kubernetes_namespace" "testing" {
metadata {
name = "homelab-testing"
}
}

12
provider.tf Normal file
View File

@ -0,0 +1,12 @@
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = ">= 2.0"
}
}
}
provider "kubernetes" {
config_path = "~/.kube/config"
}

72
traefik.tf Normal file
View File

@ -0,0 +1,72 @@
resource "kubernetes_deployment" "traefik" {
metadata {
name = "traefik"
labels = {
name = "traefik.k3s.seyshiro.de"
}
namespace = kubernetes_namespace.testing.metadata.0.name
}
spec {
replicas = 1
selector {
match_labels = {
name = "traefik.k3s.seyshiro.de"
}
}
template {
metadata {
labels = {
name = "traefik.k3s.seyshiro.de"
}
}
spec {
container {
image = "traefik:v3.0"
name = "traefik"
port {
container_port = 80
}
port {
container_port = 8080
}
resources {
limits = {
cpu = "0.5"
memory = "512Mi"
}
requests = {
cpu = "250m"
memory = "50Mi"
}
}
}
}
}
}
}
resource "kubernetes_service" "traefik" {
metadata {
name = "traefik"
namespace = kubernetes_namespace.testing.metadata.0.name
}
spec {
selector = {
name = kubernetes_deployment.traefik.spec.0.template.0.metadata.0.labels.name
}
port {
port = 80
target_port = 80
}
type = "NodePort"
}
}

130
uptimekuma.tf Normal file
View File

@ -0,0 +1,130 @@
resource "kubernetes_deployment" "status" {
metadata {
name = "status"
labels = {
name = "status.k3s.seyshiro.de"
}
namespace = kubernetes_namespace.testing.metadata.0.name
}
spec {
replicas = 1
selector {
match_labels = {
name = "status.k3s.seyshiro.de"
}
}
template {
metadata {
labels = {
name = "status.k3s.seyshiro.de"
}
}
spec {
container {
image = "louislam/uptime-kuma:1.23.6"
name = "status"
port {
container_port = 3001
}
resources {
limits = {
cpu = "0.5"
memory = "512Mi"
}
requests = {
cpu = "250m"
memory = "50Mi"
}
}
volume_mount {
name = "volv"
mount_path = "/app/data"
}
}
volume {
name = "volv"
persistent_volume_claim {
claim_name = kubernetes_persistent_volume.status.metadata.0.name
}
}
}
}
}
}
resource "kubernetes_service" "status" {
metadata {
name = "status"
namespace = kubernetes_namespace.testing.metadata.0.name
}
spec {
selector = {
name = kubernetes_deployment.status.spec.0.template.0.metadata.0.labels.name
}
port {
port = 3001
target_port = 3001
}
type = "NodePort"
}
}
resource "kubernetes_persistent_volume_claim" "status" {
metadata {
name = "status"
namespace = kubernetes_namespace.testing.metadata.0.name
}
spec {
access_modes = ["ReadWriteMany"]
resources {
requests = {
storage = "2Gi"
}
}
volume_name = kubernetes_persistent_volume.status.metadata.0.name
storage_class_name = "local-path"
}
wait_until_bound = true
}
resource "kubernetes_persistent_volume" "status" {
metadata {
name = "status"
}
spec {
access_modes = ["ReadWriteMany"]
capacity = {
storage = "2Gi"
}
node_affinity {
required {
node_selector_term {
match_fields{
key = "metadata.name"
operator = "In"
values = ["status"]
}
}
}
}
persistent_volume_source {
local {
path = "/home/tuan/terraform/status/"
}
}
storage_class_name = "local-path"
}
}