Compare commits

...

2 Commits

Author SHA1 Message Date
Ricard Illa d237e56a02 feat: general refactor 2023-07-04 16:03:41 +02:00
Ricard Illa d9ffa00b03 feat: added minio bucket with terraform state 2023-07-04 15:31:18 +02:00
8 changed files with 67 additions and 90 deletions

View File

@ -1,4 +1,3 @@
# export TF_VAR_hetzner_token := `pass hetzner.com/tokens/suricata`
export TF_VAR_pg_passwd := `pass pg.monotremata.xyz/terraform` export TF_VAR_pg_passwd := `pass pg.monotremata.xyz/terraform`
export TF_VAR_minio_root_user := "rilla" export TF_VAR_minio_root_user := "rilla"
export TF_VAR_minio_root_password := `pass minio.monotremata.xyz/rilla` export TF_VAR_minio_root_password := `pass minio.monotremata.xyz/rilla`
@ -7,13 +6,14 @@ export LINODE_TOKEN := `pass linode.com/token`
export VULTR_API_KEY := `pass vultr.com/api_key` export VULTR_API_KEY := `pass vultr.com/api_key`
export HETZNER_DNS_API_TOKEN := `pass hetzner.com/tokens/terraform` export HETZNER_DNS_API_TOKEN := `pass hetzner.com/tokens/terraform`
minio_access_key := `pass minio.monotremata.xyz/terraform/access_key` export MINIO_ENDPOINT := "minio.monotremata.xyz:443"
minio_secret_key := `pass minio.monotremata.xyz/terraform/secret_key` export MINIO_USER := `pass minio.monotremata.xyz/terraform/access_key`
export MINIO_PASSWORD := `pass minio.monotremata.xyz/terraform/secret_key`
init: init:
terraform init \ terraform init \
-backend-config="access_key={{minio_access_key}}" \ -backend-config="access_key=$(pass minio.monotremata.xyz/terraform/access_key)" \
-backend-config="secret_key={{minio_secret_key}}" -backend-config="secret_key=$(pass minio.monotremata.xyz/terraform/secret_key)"
plan *ARGS: plan *ARGS:
terraform plan {{ARGS}} terraform plan {{ARGS}}

62
main.tf
View File

@ -9,23 +9,51 @@ terraform {
skip_metadata_api_check = true skip_metadata_api_check = true
skip_region_validation = true skip_region_validation = true
} }
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = ">= 2.20.0"
}
helm = {
source = "hashicorp/helm"
version = ">= 2.9.0"
}
minio = {
source = "aminueza/minio"
version = ">= 1.15.2"
}
linode = {
source = "linode/linode"
version = ">= 1.29.0"
}
hetznerdns = {
source = "timohirt/hetznerdns"
version = ">=2.2.0"
}
postgresql = {
source = "cyrilgdn/postgresql"
version = ">= 1.19.0"
}
}
} }
#module "cert-manager" { provider "kubernetes" {
# source = "./modules/cert-manager" config_path = "~/.kube/config"
# hetzner_token = var.hetzner_token }
# email = var.email
# zone_name = var.zone_name
# dns_common_name = var.dns_common_name
# dns_names = var.dns_names
#}
module "postgresql" { provider "helm" {
source = "./modules/postgresql" kubernetes {
host = "pg.monotremata.xyz" config_path = "~/.kube/config"
password = var.pg_passwd }
}
provider "minio" {
minio_ssl = true
}
provider "postgresql" {
username = "terraform" username = "terraform"
db_owner = "rilla" password = var.pg_passwd
} }
module "dns" { module "dns" {
@ -79,3 +107,11 @@ module "minio" {
minio_console_url = "minio-console.monotremata.xyz" minio_console_url = "minio-console.monotremata.xyz"
minio_host_path = "/mnt/k3s_volumes/minio" minio_host_path = "/mnt/k3s_volumes/minio"
} }
module "minio_buckets" {
source = "./modules/minio_buckets"
providers = {
minio = minio
}
depends_on = [module.minio]
}

View File

@ -11,16 +11,6 @@ terraform {
} }
} }
provider "kubernetes" {
config_path = "~/.kube/config"
}
provider "helm" {
kubernetes {
config_path = "~/.kube/config"
}
}
resource "helm_release" "cert-manager" { resource "helm_release" "cert-manager" {
name = "cert-manager" name = "cert-manager"
chart = "cert-manager" chart = "cert-manager"
@ -56,40 +46,6 @@ resource "kubernetes_secret" "hetzner-token" {
} }
} }
#resource "kubernetes_manifest" "clusterissuer_letsencrypt_staging" {
# manifest = {
# apiVersion = "cert-manager.io/v1"
# kind = "ClusterIssuer"
# metadata = {
# name = "letsencrypt-staging"
# }
# spec = {
# acme = {
# email = var.email
# privateKeySecretRef = {
# name = "letsencrypt-staging-account-key"
# }
# server = var.letsencrypt_servers.staging
# solvers = [
# {
# dns01 = {
# webhook = {
# config = {
# apiUrl = var.hetzner_dns_api
# secretName = kubernetes_secret.hetzner-token.metadata[0].name
# zoneName = var.zone_name
# }
# groupName = var.group_name
# solverName = "hetzner"
# }
# }
# }
# ]
# }
# }
# }
#}
resource "kubernetes_manifest" "clusterissuer_letsencrypt" { resource "kubernetes_manifest" "clusterissuer_letsencrypt" {
manifest = { manifest = {
apiVersion = "cert-manager.io/v1" apiVersion = "cert-manager.io/v1"

View File

@ -7,10 +7,6 @@ terraform {
} }
} }
provider "kubernetes" {
config_path = "~/.kube/config"
}
# terraform import module.minio.kubernetes_namespace.minio_namespace minio # terraform import module.minio.kubernetes_namespace.minio_namespace minio
resource "kubernetes_namespace" "minio_namespace" { resource "kubernetes_namespace" "minio_namespace" {
metadata { metadata {

View File

@ -0,0 +1,13 @@
terraform {
required_providers {
minio = {
source = "aminueza/minio"
version = ">= 1.15.2"
}
}
}
resource "minio_s3_bucket" "state_terraform_s3" {
bucket = "terraform"
acl = "private"
}

View File

@ -7,13 +7,6 @@ terraform {
} }
} }
provider "postgresql" {
host = var.host
port = var.port
username = var.username
password = var.password
}
resource "postgresql_database" "terraform_backend_db" { resource "postgresql_database" "terraform_backend_db" {
name = "terraform_backend" name = "terraform_backend"
owner = var.db_owner owner = var.db_owner

View File

@ -1,14 +1,3 @@
variable "host" {
type = string
description = "postgresql host"
}
variable "port" {
type = number
description = "postgresql post"
default = 5432
}
variable "password" { variable "password" {
type = string type = string
description = "postgresql password" description = "postgresql password"

View File

@ -1,9 +1,3 @@
#variable "hetzner_token" {
# type = string
# description = "hetzner dns token"
# sensitive = true
#}
variable "email" { variable "email" {
type = string type = string
description = "email for letsencrypt registration" description = "email for letsencrypt registration"