diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..052238c --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +terraform.tfstate +terraform.tfstate.backup +terraform.tfvars +.terraform diff --git a/terraform/database.tf b/terraform/database.tf new file mode 100644 index 0000000..3c587a1 --- /dev/null +++ b/terraform/database.tf @@ -0,0 +1,9 @@ +resource "digitalocean_database_cluster" "postgres-example" { + name = var.postgres.name + engine = "pg" + version = var.postgres.version + size = var.postgres.size + region = var.region + node_count = var.postgres.node_count + tags = [var.default_tag] +} diff --git a/terraform/kubernetes.tf b/terraform/kubernetes.tf new file mode 100644 index 0000000..5cde077 --- /dev/null +++ b/terraform/kubernetes.tf @@ -0,0 +1,12 @@ +resource "digitalocean_kubernetes_cluster" "querido-diario" { + name = var.cluster_name + region = var.region + version = "1.20.2-do.0" + + node_pool { + name = "worker-pool" + node_count = var.node_count + size = var.node_size + tags = [var.default_tag] + } +} diff --git a/terraform/load_balancer.tf b/terraform/load_balancer.tf new file mode 100644 index 0000000..abb2b12 --- /dev/null +++ b/terraform/load_balancer.tf @@ -0,0 +1,19 @@ +resource "digitalocean_loadbalancer" "public" { + name = var.load_balancer.name + region = var.region + + forwarding_rule { + entry_port = var.load_balancer.forwarding_rule.entry_port + entry_protocol = var.load_balancer.forwarding_rule.entry_protocol + + target_port = var.load_balancer.forwarding_rule.target_port + target_protocol = var.load_balancer.forwarding_rule.target_protocol + } + + healthcheck { + port = var.load_balancer.healthcheck.port + protocol = var.load_balancer.healthcheck.protocol + } + + droplet_tag = var.default_tag +} diff --git a/terraform/provider.tf b/terraform/provider.tf new file mode 100644 index 0000000..06ac412 --- /dev/null +++ b/terraform/provider.tf @@ -0,0 +1,5 @@ +provider "digitalocean" { + token = var.do_token + spaces_access_id = var.do_spaces_access_key + spaces_secret_key = var.do_spaces_secret +} diff --git a/terraform/registry.tf b/terraform/registry.tf new file mode 100644 index 0000000..0cd110e --- /dev/null +++ b/terraform/registry.tf @@ -0,0 +1,4 @@ +resource "digitalocean_container_registry" "querido-diario-registry" { + name = var.registry.name + subscription_tier_slug = var.registry.subscription_tier_slug +} diff --git a/terraform/spaces.tf b/terraform/spaces.tf new file mode 100644 index 0000000..151d9f0 --- /dev/null +++ b/terraform/spaces.tf @@ -0,0 +1,5 @@ +resource "digitalocean_spaces_bucket" "querido-diario-spaces" { + name = var.spaces.name + region = var.region + acl = var.spaces.acl +} diff --git a/terraform/tag.tf b/terraform/tag.tf new file mode 100644 index 0000000..4899156 --- /dev/null +++ b/terraform/tag.tf @@ -0,0 +1,3 @@ +resource "digitalocean_tag" "foobar" { + name = var.default_tag +} diff --git a/terraform/variables.tf b/terraform/variables.tf new file mode 100644 index 0000000..13bea8f --- /dev/null +++ b/terraform/variables.tf @@ -0,0 +1,114 @@ +variable "do_token"{ + default = null + type = string +} + +variable "do_spaces_secret" { + default = null + type = string +} +variable "do_spaces_access_key"{ + default = null + type = string +} + +variable "cluster_name" { + default = "querido-diario" + type = string +} + +variable "node_size" { + default = "s-1vcpu-2gb" + type = string +} + +variable "node_count" { + default = 2 +} + +variable "region" { + default = "nyc3" +} + +variable "postgres" { + type = object({ + name = string + version = string + size = string + region = string + node_count = number + database = string + user = string + password = string + }) + default = { + name = "example-postgres-cluster" + version = "11" + size = "db-s-1vcpu-1gb" + region = "nyc3" + node_count = 1 + database = "querido-diario" + user = "querido-diario" + password = "querido-diario" + } +} + +variable "default_tag" { + default = "querido-diario" + type = string +} + +variable "registry" { + type = object({ + name = string + subscription_tier_slug = string + }) + default = { + name = "querido-diario" + subscription_tier_slug = "starter" + } +} + +variable "load_balancer" { + type = object({ + name = string + redirect_http_to_https = bool + forwarding_rule =object({ + entry_port = number + entry_protocol = string + target_port = number + target_protocol = string + }) + healthcheck = object({ + port = number + protocol = string + }) + }) + default = { + name = "querido-diario-load-balancer" + redirect_http_to_https = true + forwarding_rule = { + entry_port = 80 + entry_protocol = "http" + target_port = 80 + target_protocol = "http" + } + healthcheck = { + port = 22 + protocol = "tcp" + } + + } +} + +variable "spaces" { + type = object({ + name = string + acl = string + }) + default = { + name = "querido-diario" + acl = "public-read" + } +} + diff --git a/terraform/versions.tf b/terraform/versions.tf new file mode 100644 index 0000000..965ffdb --- /dev/null +++ b/terraform/versions.tf @@ -0,0 +1,8 @@ +terraform { + required_providers { + digitalocean = { + version = "~> 2.7" + } + } + required_version = ">= 0.12" +}