Skip to content

Commit

Permalink
Initial Terraform scripts
Browse files Browse the repository at this point in the history
Adds the first version of the Terraform script to deploy the
infrastructure to run the Querido Diário workloads.

Signed-off-by: José Guilherme Vanz <[email protected]>
  • Loading branch information
jvanz committed Apr 19, 2021
1 parent 8deb210 commit 07cb187
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
terraform.tfstate
terraform.tfstate.backup
terraform.tfvars
.terraform
9 changes: 9 additions & 0 deletions terraform/database.tf
Original file line number Diff line number Diff line change
@@ -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]
}
12 changes: 12 additions & 0 deletions terraform/kubernetes.tf
Original file line number Diff line number Diff line change
@@ -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]
}
}
19 changes: 19 additions & 0 deletions terraform/load_balancer.tf
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 5 additions & 0 deletions terraform/provider.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.do_spaces_access_key
spaces_secret_key = var.do_spaces_secret
}
4 changes: 4 additions & 0 deletions terraform/registry.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "digitalocean_container_registry" "querido-diario-registry" {
name = var.registry.name
subscription_tier_slug = var.registry.subscription_tier_slug
}
5 changes: 5 additions & 0 deletions terraform/spaces.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "digitalocean_spaces_bucket" "querido-diario-spaces" {
name = var.spaces.name
region = var.region
acl = var.spaces.acl
}
3 changes: 3 additions & 0 deletions terraform/tag.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "digitalocean_tag" "foobar" {
name = var.default_tag
}
114 changes: 114 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}

8 changes: 8 additions & 0 deletions terraform/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
digitalocean = {
version = "~> 2.7"
}
}
required_version = ">= 0.12"
}

0 comments on commit 07cb187

Please sign in to comment.