Skip to content

Commit

Permalink
initial work on linode (blocked on postgres access)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljguarino committed Jan 7, 2024
1 parent d7fe830 commit 5ff5020
Show file tree
Hide file tree
Showing 17 changed files with 489 additions and 6 deletions.
50 changes: 50 additions & 0 deletions templates/providers/apps/linode.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
terraform {
required_version = ">= 1.0"

backend "s3" {
endpoint = "us-east-1.linodeobjects.com"
bucket = "{{ .Bucket }}"
key = "{{ .Cluster }}/apps/terraform.tfstate"
region = "us-east-1"
}

required_providers {
linode = {
source = "linode/linode"
version = "~> 2.12.0"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = ">= 2.10"
}
plural = {
source = "pluralsh/plural"
version = ">= 0.2.0"
}
}
}

provider "linode" {}

module "parsed" {
source = "../bootstrap/terraform/modules/raw-kubeconfig"
kubeconfig = module.mgmt.cluster.kubeconfig
}

provider "kubernetes" {
host = module.parsed.cluster.server
cluster_ca_certificate = base64decode(module.parsed.cluster.certificate-authority-data)
token = module.parsed.user.token
}

data "kubernetes_secret" "console-auth" {
metadata {
name = "console-auth-token"
namespace = "plrl-console"
}
}

provider "plural" {
console_url = "https://console.{{ .Subdomain }}"
access_token = data.kubernetes_secret.console-auth.data.access-token
}
48 changes: 48 additions & 0 deletions templates/providers/bootstrap/linode.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
terraform {
required_version = ">= 1.0"

backend "s3" {
endpoint = "us-east-1.linodeobjects.com"
bucket = "{{ .Bucket }}"
key = "{{ .Cluster }}/bootstrap/terraform.tfstate"
region = "us-east-1"
}

required_providers {
linode = {
source = "linode/linode"
version = "~> 2.12.0"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = ">= 2.10"
}
random = {
source = "hashicorp/random"
version = "3.6.0"
}
helm = {
source = "hashicorp/helm"
version = "2.12.1"
}
local = {
source = "hashicorp/local"
version = "2.4.1"
}
}
}

provider "linode" {}

module "parsed" {
source = "../bootstrap/terraform/modules/raw-kubeconfig"
kubeconfig = module.mgmt.cluster.kubeconfig
}

provider "helm" {
kubernetes {
host = module.parsed.cluster.server
cluster_ca_certificate = base64decode(module.parsed.cluster.certificate-authority-data)
token = module.parsed.user.token
}
}
4 changes: 2 additions & 2 deletions templates/setup/providers/aws.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module "mgmt" {
source = "../bootstrap/terraform/clouds/aws"
cluster_name = "{{ .Cluster }}"
source = "../bootstrap/terraform/clouds/aws"
cluster_name = "{{ .Cluster }}"
}
8 changes: 4 additions & 4 deletions templates/setup/providers/gcp.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module "mgmt" {
source = "../bootstrap/terraform/clouds/gcp"
project_id = "{{ .Project }}"
cluster_name = "{{ .Cluster }}"
region = "{{ .Region }}"
source = "../bootstrap/terraform/clouds/gcp"
project_id = "{{ .Project }}"
cluster_name = "{{ .Cluster }}"
region = "{{ .Region }}"
}
5 changes: 5 additions & 0 deletions templates/setup/providers/linode.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module "mgmt" {
source = "../bootstrap/terraform/clouds/linode"
cluster_name = "{{ .Cluster }}"
region = "{{ .Region }}"
}
17 changes: 17 additions & 0 deletions terraform/clouds/linode/lke.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
resource "linode_lke_cluster" "mgmt" {
label = var.cluster_name
k8s_version = var.kubernetes_vsn
region = var.region

dynamic "pool" {
for_each = var.node_pools
content {
type = pool.value.type
count = pool.value.count
autoscaler {
min = pool.value.autoscaler.min
max = pool.value.autoscaler.max
}
}
}
}
3 changes: 3 additions & 0 deletions terraform/clouds/linode/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
db_url = var.create_db ? format("postgresql://%s:%s@%s:5432/console", linode_database_postgresql.postgres[0].root_username, linode_database_postgresql.postgres[0].root_password, linode_database_postgresql.postgres[0].host_primary) : ""
}
11 changes: 11 additions & 0 deletions terraform/clouds/linode/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
output "cluster" {
value = linode_lke_cluster.mgmt
}

output "ready" {
value = linode_lke_cluster.mgmt
}

output "db_url" {
value = local.db_url
}
22 changes: 22 additions & 0 deletions terraform/clouds/linode/postgres.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
resource "linode_database_postgresql" "postgres" {
count = var.create_db ? 1 : 0
label = "console"
engine_id = var.engine_id
region = var.region
type = var.db_size

allow_list = var.db_allowlist
cluster_size = 1
encrypted = true
replication_type = "semi_synch"
replication_commit_type = "remote_write"
ssl_connection = true

updates {
day_of_week = "saturday"
duration = 1
frequency = "monthly"
hour_of_day = 22
week_of_month = 2
}
}
48 changes: 48 additions & 0 deletions terraform/clouds/linode/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
variable "region" {
type = string
default = "us-east"
}

variable "create_db" {
type = bool
default = true
}

variable "cluster_name" {
type = string
default = "plural"
}

variable "db_size" {
type = string
default = "g6-standard-2"
}

variable "db_allowlist" {
type = list(string)
default = ["0.0.0.0/0"]
}

variable "engine_id" {
type = string
default = "postgresql/13.2"
}

variable "kubernetes_vsn" {
type = string
default = "1.27"
}

variable "node_pools" {
type = list(any)
default = [
{
type="g6-standard-2",
count=3
autoscaler={
min=3
max=20
}
}
]
}
8 changes: 8 additions & 0 deletions terraform/clouds/linode/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
linode = {
source = "linode/linode"
version = ">= 2.12.0"
}
}
}
11 changes: 11 additions & 0 deletions terraform/modules/raw-kubeconfig/parse.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
locals {
kubeconfig = yamldecode(var.kubeconfig)
}

output "cluster" {
value = local.kubeconfig.clusters[0]
}

output "user" {
value = local.kubeconfig.users[0].user
}
3 changes: 3 additions & 0 deletions terraform/modules/raw-kubeconfig/variable.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "kubeconfig" {
type = string
}
123 changes: 123 additions & 0 deletions test/linode/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5ff5020

Please sign in to comment.