From d237e56a02fad2acb80c690f5db6bfaaf4a5a848 Mon Sep 17 00:00:00 2001 From: Ricard Illa Date: Tue, 4 Jul 2023 16:03:41 +0200 Subject: [PATCH] feat: general refactor --- main.tf | 58 +++++++++++++++++++++++++-------- modules/cert-manager/main.tf | 44 ------------------------- modules/minio/main.tf | 4 --- modules/minio_buckets/main.tf | 4 --- modules/postgresql/main.tf | 7 ---- modules/postgresql/variables.tf | 11 ------- variables.tf | 6 ---- 7 files changed, 45 insertions(+), 89 deletions(-) diff --git a/main.tf b/main.tf index fbe9ad4..3528d2b 100644 --- a/main.tf +++ b/main.tf @@ -9,23 +9,51 @@ terraform { skip_metadata_api_check = 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" { -# source = "./modules/cert-manager" -# 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 -#} +provider "kubernetes" { + config_path = "~/.kube/config" +} -module "postgresql" { - source = "./modules/postgresql" - host = "pg.monotremata.xyz" - password = var.pg_passwd +provider "helm" { + kubernetes { + config_path = "~/.kube/config" + } +} + +provider "minio" { + minio_ssl = true +} + +provider "postgresql" { username = "terraform" - db_owner = "rilla" + password = var.pg_passwd } module "dns" { @@ -82,4 +110,8 @@ module "minio" { module "minio_buckets" { source = "./modules/minio_buckets" + providers = { + minio = minio + } + depends_on = [module.minio] } diff --git a/modules/cert-manager/main.tf b/modules/cert-manager/main.tf index 2b1347f..1b828a9 100644 --- a/modules/cert-manager/main.tf +++ b/modules/cert-manager/main.tf @@ -11,16 +11,6 @@ terraform { } } -provider "kubernetes" { - config_path = "~/.kube/config" -} - -provider "helm" { - kubernetes { - config_path = "~/.kube/config" - } -} - resource "helm_release" "cert-manager" { name = "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" { manifest = { apiVersion = "cert-manager.io/v1" diff --git a/modules/minio/main.tf b/modules/minio/main.tf index fd106e1..a1bceed 100644 --- a/modules/minio/main.tf +++ b/modules/minio/main.tf @@ -7,10 +7,6 @@ terraform { } } -provider "kubernetes" { - config_path = "~/.kube/config" -} - # terraform import module.minio.kubernetes_namespace.minio_namespace minio resource "kubernetes_namespace" "minio_namespace" { metadata { diff --git a/modules/minio_buckets/main.tf b/modules/minio_buckets/main.tf index 55a7a85..68ea0a0 100644 --- a/modules/minio_buckets/main.tf +++ b/modules/minio_buckets/main.tf @@ -7,10 +7,6 @@ terraform { } } -provider "minio" { - minio_ssl = true -} - resource "minio_s3_bucket" "state_terraform_s3" { bucket = "terraform" acl = "private" diff --git a/modules/postgresql/main.tf b/modules/postgresql/main.tf index 2fc2d24..e9bd01e 100644 --- a/modules/postgresql/main.tf +++ b/modules/postgresql/main.tf @@ -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" { name = "terraform_backend" owner = var.db_owner diff --git a/modules/postgresql/variables.tf b/modules/postgresql/variables.tf index 62c59f1..620c92d 100644 --- a/modules/postgresql/variables.tf +++ b/modules/postgresql/variables.tf @@ -1,14 +1,3 @@ -variable "host" { - type = string - description = "postgresql host" -} - -variable "port" { - type = number - description = "postgresql post" - default = 5432 -} - variable "password" { type = string description = "postgresql password" diff --git a/variables.tf b/variables.tf index 1b7dc95..6a3fb76 100644 --- a/variables.tf +++ b/variables.tf @@ -1,9 +1,3 @@ -#variable "hetzner_token" { -# type = string -# description = "hetzner dns token" -# sensitive = true -#} - variable "email" { type = string description = "email for letsencrypt registration"