Skip to content

Commit d819631

Browse files
committed
Add various terraform and SETUP.md updates
1 parent 5112b2c commit d819631

File tree

10 files changed

+233
-43
lines changed

10 files changed

+233
-43
lines changed

.gitignore

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
# Local .terraform directories
2-
.terraform/
3-
4-
# .tfstate files
1+
# Terraform files
52
*.tfstate
63
*.tfstate.*
7-
8-
# Crash log files
4+
*.tfvars
5+
!*.tfvars.example
6+
.terraform/
7+
.terraform.lock.hcl
98
crash.log
109
crash.*.log
11-
12-
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
13-
# password, private keys, and other secrets. These should not be part of version
14-
# control as they are data points which are potentially sensitive and subject
15-
# to change depending on the environment.
16-
*.tfvars
17-
*.tfvars.json
10+
*.tfplan
11+
*.tfplan.*
1812

1913
# Ignore override files as they are usually used to override resources locally and so
2014
# are not checked in
@@ -29,13 +23,19 @@ override.tf.json
2923
# Include override files you do wish to add to version control using negated pattern
3024
# !example_override.tf
3125

32-
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
33-
# example: *tfplan*
34-
3526
# Ignore CLI configuration files
3627
.terraformrc
3728
terraform.rc
3829

39-
## Miscellaneous
30+
# IDE files
31+
.vscode/
32+
.idea/
33+
*.swp
34+
*.swo
35+
36+
# OS files
4037
.DS_Store
38+
Thumbs.db
39+
40+
## Miscellaneous
4141
charts/

SETUP.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,12 @@ As it turns out, we're not quite done with our monitoring configuration. K3s doe
879879

880880
To fix this, we need to add Grafana Loki and Alloy.
881881

882+
TODO: Describe setting up Loki and Alloy.
883+
884+
## Adding n8n
885+
886+
TODO: Describe deploying n8n
887+
882888
## Finishing Up
883889

884890
The last thing that you should do is hop into the ArgoCD dashboard (via whatever IP you set it to for external) and deploy all the root/namespaces/apps there.

terraform/.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Terraform files
2+
*.tfstate
3+
*.tfstate.*
4+
*.tfvars
5+
!*.tfvars.example
6+
.terraform/
7+
.terraform.lock.hcl
8+
crash.log
9+
crash.*.log
10+
*.tfplan
11+
*.tfplan.*
12+
13+
# IDE files
14+
.vscode/
15+
.idea/
16+
*.swp
17+
*.swo
18+
19+
# OS files
20+
.DS_Store
21+
Thumbs.db

terraform/main.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Main Terraform configuration for Kubernetes infrastructure
2+
# This file serves as the entry point and can be used to organize resources
3+
4+
# Local values for common configurations
5+
locals {
6+
common_labels = {
7+
"app.kubernetes.io/managed-by" = var.managed_by
8+
"environment" = var.environment
9+
"cluster" = var.cluster_name
10+
"terraform" = "true"
11+
}
12+
13+
# Longhorn parameters that are common across storage classes
14+
longhorn_common_params = {
15+
"staleReplicaTimeout" = tostring(var.longhorn_stale_replica_timeout)
16+
"fromBackup" = ""
17+
"fsType" = var.longhorn_fs_type
18+
}
19+
}

terraform/namespaces.tf

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ resource "kubernetes_namespace" "applications" {
22
metadata {
33
name = "applications"
44
labels = {
5-
"app.kubernetes.io/managed-by" = "terraform"
5+
"app.kubernetes.io/managed-by" = var.managed_by
6+
"environment" = var.environment
7+
"cluster" = var.cluster_name
68
}
79
}
810
}
@@ -11,7 +13,9 @@ resource "kubernetes_namespace" "argocd" {
1113
metadata {
1214
name = "argocd"
1315
labels = {
14-
"app.kubernetes.io/managed-by" = "terraform"
16+
"app.kubernetes.io/managed-by" = var.managed_by
17+
"environment" = var.environment
18+
"cluster" = var.cluster_name
1519
}
1620
}
1721
}
@@ -20,7 +24,9 @@ resource "kubernetes_namespace" "atlantis" {
2024
metadata {
2125
name = "atlantis"
2226
labels = {
23-
"app.kubernetes.io/managed-by" = "terraform"
27+
"app.kubernetes.io/managed-by" = var.managed_by
28+
"environment" = var.environment
29+
"cluster" = var.cluster_name
2430
}
2531
}
2632
}
@@ -29,7 +35,9 @@ resource "kubernetes_namespace" "cert_manager" {
2935
metadata {
3036
name = "cert-manager"
3137
labels = {
32-
"app.kubernetes.io/managed-by" = "terraform"
38+
"app.kubernetes.io/managed-by" = var.managed_by
39+
"environment" = var.environment
40+
"cluster" = var.cluster_name
3341
}
3442
}
3543
}
@@ -38,7 +46,9 @@ resource "kubernetes_namespace" "kube_system" {
3846
metadata {
3947
name = "kube-system"
4048
labels = {
41-
"app.kubernetes.io/managed-by" = "terraform"
49+
"app.kubernetes.io/managed-by" = var.managed_by
50+
"environment" = var.environment
51+
"cluster" = var.cluster_name
4252
}
4353
}
4454
}
@@ -47,16 +57,20 @@ resource "kubernetes_namespace" "logging" {
4757
metadata {
4858
name = "logging"
4959
labels = {
50-
"app.kubernetes.io/managed-by" = "terraform"
60+
"app.kubernetes.io/managed-by" = var.managed_by
61+
"environment" = var.environment
62+
"cluster" = var.cluster_name
5163
}
5264
}
5365
}
5466

5567
resource "kubernetes_namespace" "longhorn_system" {
5668
metadata {
57-
name = "longhorn"
69+
name = "longhorn-system"
5870
labels = {
59-
"app.kubernetes.io/managed-by" = "terraform"
71+
"app.kubernetes.io/managed-by" = var.managed_by
72+
"environment" = var.environment
73+
"cluster" = var.cluster_name
6074
}
6175
}
6276
}
@@ -65,7 +79,9 @@ resource "kubernetes_namespace" "monitoring" {
6579
metadata {
6680
name = "monitoring"
6781
labels = {
68-
"app.kubernetes.io/managed-by" = "terraform"
82+
"app.kubernetes.io/managed-by" = var.managed_by
83+
"environment" = var.environment
84+
"cluster" = var.cluster_name
6985
}
7086
}
7187
}

terraform/outputs.tf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
output "namespaces" {
2+
description = "Created Kubernetes namespaces"
3+
value = {
4+
applications = kubernetes_namespace.applications.metadata[0].name
5+
argocd = kubernetes_namespace.argocd.metadata[0].name
6+
atlantis = kubernetes_namespace.atlantis.metadata[0].name
7+
cert_manager = kubernetes_namespace.cert_manager.metadata[0].name
8+
kube_system = kubernetes_namespace.kube_system.metadata[0].name
9+
logging = kubernetes_namespace.logging.metadata[0].name
10+
longhorn_system = kubernetes_namespace.longhorn_system.metadata[0].name
11+
monitoring = kubernetes_namespace.monitoring.metadata[0].name
12+
}
13+
}
14+
15+
output "storage_classes" {
16+
description = "Created Kubernetes storage classes"
17+
value = {
18+
longhorn_default = kubernetes_storage_class.longhorn_default.metadata[0].name
19+
longhorn_high_availability = kubernetes_storage_class.longhorn_high_availability.metadata[0].name
20+
longhorn_fast = kubernetes_storage_class.longhorn_fast.metadata[0].name
21+
longhorn_retain = kubernetes_storage_class.longhorn_retain.metadata[0].name
22+
}
23+
}
24+
25+
output "cluster_info" {
26+
description = "Cluster information"
27+
value = {
28+
environment = var.environment
29+
cluster_name = var.cluster_name
30+
managed_by = var.managed_by
31+
}
32+
}

terraform/provider.tf

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
required_providers {
4+
kubernetes = {
5+
source = "hashicorp/kubernetes"
6+
version = "~> 2.23"
7+
}
8+
}
9+
10+
# Uncomment and configure backend for remote state management
11+
# backend "s3" {
12+
# bucket = "your-terraform-state-bucket"
13+
# key = "kubernetes/terraform.tfstate"
14+
# region = "us-west-2"
15+
# }
16+
}
17+
118
provider "kubernetes" {
219
# This is the path for K3s, not for full K8s
3-
config_path = "/etc/rancher/k3s/k3s.yaml"
20+
config_path = var.kubeconfig_path
421
}

terraform/storage-classes.tf

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ resource "kubernetes_storage_class" "longhorn_default" {
22
metadata {
33
name = "longhorn"
44
labels = {
5-
"app.kubernetes.io/managed-by" = "terraform"
5+
"app.kubernetes.io/managed-by" = var.managed_by
6+
"environment" = var.environment
7+
"cluster" = var.cluster_name
68
}
79
}
810
storage_provisioner = "driver.longhorn.io"
@@ -11,10 +13,10 @@ resource "kubernetes_storage_class" "longhorn_default" {
1113
allow_volume_expansion = true
1214

1315
parameters = {
14-
"numberOfReplicas" = "3"
15-
"staleReplicaTimeout" = "2880"
16+
"numberOfReplicas" = tostring(var.longhorn_replicas)
17+
"staleReplicaTimeout" = tostring(var.longhorn_stale_replica_timeout)
1618
"fromBackup" = ""
17-
"fsType" = "ext4"
19+
"fsType" = var.longhorn_fs_type
1820
"dataLocality" = "disabled"
1921
}
2022
}
@@ -23,7 +25,9 @@ resource "kubernetes_storage_class" "longhorn_high_availability" {
2325
metadata {
2426
name = "longhorn-ha"
2527
labels = {
26-
"app.kubernetes.io/managed-by" = "terraform"
28+
"app.kubernetes.io/managed-by" = var.managed_by
29+
"environment" = var.environment
30+
"cluster" = var.cluster_name
2731
}
2832
}
2933
storage_provisioner = "driver.longhorn.io"
@@ -32,10 +36,10 @@ resource "kubernetes_storage_class" "longhorn_high_availability" {
3236
allow_volume_expansion = true
3337

3438
parameters = {
35-
"numberOfReplicas" = "6"
36-
"staleReplicaTimeout" = "2880"
39+
"numberOfReplicas" = tostring(var.longhorn_ha_replicas)
40+
"staleReplicaTimeout" = tostring(var.longhorn_stale_replica_timeout)
3741
"fromBackup" = ""
38-
"fsType" = "ext4"
42+
"fsType" = var.longhorn_fs_type
3943
"dataLocality" = "best-effort"
4044
}
4145
}
@@ -44,7 +48,9 @@ resource "kubernetes_storage_class" "longhorn_fast" {
4448
metadata {
4549
name = "longhorn-fast"
4650
labels = {
47-
"app.kubernetes.io/managed-by" = "terraform"
51+
"app.kubernetes.io/managed-by" = var.managed_by
52+
"environment" = var.environment
53+
"cluster" = var.cluster_name
4854
}
4955
}
5056
storage_provisioner = "driver.longhorn.io"
@@ -53,10 +59,10 @@ resource "kubernetes_storage_class" "longhorn_fast" {
5359
allow_volume_expansion = true
5460

5561
parameters = {
56-
"numberOfReplicas" = "2"
57-
"staleReplicaTimeout" = "2880"
62+
"numberOfReplicas" = tostring(var.longhorn_fast_replicas)
63+
"staleReplicaTimeout" = tostring(var.longhorn_stale_replica_timeout)
5864
"fromBackup" = ""
59-
"fsType" = "ext4"
65+
"fsType" = var.longhorn_fs_type
6066
"dataLocality" = "strict-local"
6167
}
6268
}
@@ -65,7 +71,9 @@ resource "kubernetes_storage_class" "longhorn_retain" {
6571
metadata {
6672
name = "longhorn-retain"
6773
labels = {
68-
"app.kubernetes.io/managed-by" = "terraform"
74+
"app.kubernetes.io/managed-by" = var.managed_by
75+
"environment" = var.environment
76+
"cluster" = var.cluster_name
6977
}
7078
}
7179
storage_provisioner = "driver.longhorn.io"
@@ -74,10 +82,10 @@ resource "kubernetes_storage_class" "longhorn_retain" {
7482
allow_volume_expansion = true
7583

7684
parameters = {
77-
"numberOfReplicas" = "3"
78-
"staleReplicaTimeout" = "2880"
85+
"numberOfReplicas" = tostring(var.longhorn_replicas)
86+
"staleReplicaTimeout" = tostring(var.longhorn_stale_replica_timeout)
7987
"fromBackup" = ""
80-
"fsType" = "ext4"
88+
"fsType" = var.longhorn_fs_type
8189
"dataLocality" = "disabled"
8290
}
8391
}

terraform/terraform.tfvars.example

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copy this file to terraform.tfvars and customize the values
2+
3+
# Kubernetes configuration
4+
kubeconfig_path = "/etc/rancher/k3s/k3s.yaml"
5+
6+
# Environment and cluster information
7+
environment = "dev"
8+
cluster_name = "k3s-cluster"
9+
10+
# Resource labeling
11+
managed_by = "terraform"
12+
13+
# Longhorn storage class configuration
14+
longhorn_replicas = 3
15+
longhorn_ha_replicas = 6
16+
longhorn_fast_replicas = 2
17+
longhorn_stale_replica_timeout = 2880
18+
longhorn_fs_type = "ext4"

0 commit comments

Comments
 (0)