Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.env


# Terraform

# Local .terraform directories
.terraform/

Expand Down
14 changes: 14 additions & 0 deletions terraform/dependencies.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
required_version = "~> v1.14.7"

required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "~> 2.81.0"
}
random = {
source = "hashicorp/random"
version = "~> 3.8.1"
}
}
}
3 changes: 3 additions & 0 deletions terraform/domain.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "digitalocean_domain" "main" {
name = var.domain_name
}
20 changes: 20 additions & 0 deletions terraform/kubernetes.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
data "digitalocean_kubernetes_versions" "current" {
version_prefix = var.k8s_version
}

resource "digitalocean_kubernetes_cluster" "main" {
name = var.cluster_name
region = var.region
version = data.digitalocean_kubernetes_versions.current.latest_version
vpc_uuid = digitalocean_vpc.main.id

auto_upgrade = false
Comment thread
clofour marked this conversation as resolved.
surge_upgrade = true

node_pool {
name = "default"
size = var.node_size
node_count = var.node_count
labels = { role = "general" }
}
}
45 changes: 45 additions & 0 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
output "kubeconfig" {
value = digitalocean_kubernetes_cluster.main.kube_config[0].raw_config
sensitive = true
}


output "postgres_host" {
value = digitalocean_database_cluster.postgres.private_host
}

output "postgres_port" {
value = digitalocean_database_cluster.postgres.port
}

output "postgres_user" {
value = digitalocean_database_user.gitlab.name
}

output "postgres_password" {
value = digitalocean_database_user.gitlab.password
sensitive = true
Comment thread
clofour marked this conversation as resolved.
}


output "valkey_host" {
value = digitalocean_database_cluster.valkey.private_host
}

output "valkey_port" {
value = digitalocean_database_cluster.valkey.port
}

output "valkey_password" {
value = digitalocean_database_cluster.valkey.password
sensitive = true
}


output "spaces_endpoint" {
value = "${var.region}.digitaloceanspaces.com"
}

output "spaces_buckets" {
value = { for k, b in digitalocean_spaces_bucket.gitlab : k => b.name }
}
27 changes: 27 additions & 0 deletions terraform/postgres.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
resource "digitalocean_database_cluster" "postgres" {
name = "${var.cluster_name}-postgres"
engine = "pg"
version = 18
size = "db-s-1vcpu-1gb"
region = var.region
node_count = 1
Comment thread
clofour marked this conversation as resolved.
private_network_uuid = digitalocean_vpc.main.id
}

resource "digitalocean_database_db" "gitlab" {
cluster_id = digitalocean_database_cluster.postgres.id
name = "gitlab_production"
}

resource "digitalocean_database_user" "gitlab" {
cluster_id = digitalocean_database_cluster.postgres.id
name = "gitlab"
}

resource "digitalocean_database_firewall" "postgres" {
cluster_id = digitalocean_database_cluster.postgres.id
rule {
type = "k8s"
value = digitalocean_kubernetes_cluster.main.id
}
}
5 changes: 5 additions & 0 deletions terraform/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
provider "digitalocean" {
token = var.do_token
spaces_access_id = var.spaces_access_id
spaces_secret_key = var.spaces_secret_key
}
18 changes: 18 additions & 0 deletions terraform/spaces.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
locals {
spaces = toset([
"artifacts", "lfs", "uploads", "packages",
"registry", "backups", "tmp", "ci-secure-files",
"dependency-proxy", "terraform-state", "pages"
])
}

resource "random_id" "suffix" {
byte_length = 3
}

resource "digitalocean_spaces_bucket" "gitlab" {
for_each = local.spaces
name = "${var.cluster_name}-${each.key}-${random_id.suffix.hex}"
region = var.region
acl = "private"
}
Comment thread
clofour marked this conversation as resolved.
18 changes: 18 additions & 0 deletions terraform/valkey.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
resource "digitalocean_database_cluster" "valkey" {
name = "${var.cluster_name}-valkey"
engine = "valkey"
version = "8"
size = "db-s-1vcpu-1gb"
region = var.region
node_count = 1
Comment thread
clofour marked this conversation as resolved.
private_network_uuid = digitalocean_vpc.main.id
eviction_policy = "noeviction"
}

resource "digitalocean_database_firewall" "valkey" {
cluster_id = digitalocean_database_cluster.valkey.id
rule {
type = "k8s"
value = digitalocean_kubernetes_cluster.main.id
}
}
54 changes: 54 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
variable "do_token" {
type = string
sensitive = true
}

variable "spaces_access_id" {
type = string
sensitive = true
}

variable "spaces_secret_key" {
type = string
sensitive = true
}


variable "region" {
type = string
default = "fra1"
}

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

variable "k8s_version" {
type = string
default = "1.35.1"
}

variable "node_size" {
type = string
default = "s-2vcpu-4gb"
}

variable "node_count" {
type = number
default = 2
}

variable "domain_name" {
type = string
}

variable "gitlab_host" {
type = string
default = "gitlab"
}

variable "registry_host" {
type = string
default = "registry"
}
5 changes: 5 additions & 0 deletions terraform/vpc.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "digitalocean_vpc" "main" {
name = "${var.cluster_name}-vpc"
region = var.region
ip_range = "10.20.0.0/16"
Comment thread
clofour marked this conversation as resolved.
}