Skip to content

Commit

Permalink
✨ All good
Browse files Browse the repository at this point in the history
  • Loading branch information
dejain4 committed Jun 18, 2023
1 parent b5b4a49 commit b96d64e
Show file tree
Hide file tree
Showing 20 changed files with 301 additions and 94 deletions.
14 changes: 8 additions & 6 deletions environments/dev/compute.tfvars
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
presentation_name = "presentation-server-dev"
application_name = "application-server-dev"
region = "nyc1"
size = "s-1vcpu-1gb"
image = "ubuntu-20-04-x64"
digitalocean_token = var.digitalocean_token
presentation_name = "presentation-server-dev"
application_name = "application-server-dev"
presentation_region = "nyc1"
presentation_size = "s-1vcpu-1gb"
presentation_image = "ubuntu-20-04-x64"
application_region = "nyc1"
application_size = "s-1vcpu-1gb"
application_image = "ubuntu-20-04-x64"
8 changes: 4 additions & 4 deletions environments/dev/storage.tfvars
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
database_name = "database-server-dev"
database_region = "nyc1"
database_size = "s-1vcpu-1gb"
database_image = "ubuntu-20-04-x64"
database_name = "database-server-dev"
database_region = "nyc1"
database_size = "s-1vcpu-1gb"
database_image = "ubuntu-20-04-x64"
14 changes: 8 additions & 6 deletions environments/prod/compute.tfvars
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
presentation_name = "presentation-server-prod"
application_name = "application-server-prod"
region = "nyc1"
size = "s-1vcpu-1gb"
image = "ubuntu-20-04-x64"
digitalocean_token = "your-digitalocean-token"
presentation_name = "presentation-server-prod"
application_name = "application-server-prod"
presentation_region = "nyc1"
presentation_size = "s-1vcpu-1gb"
presentation_image = "ubuntu-20-04-x64"
application_region = "nyc1"
application_size = "s-1vcpu-1gb"
application_image = "ubuntu-20-04-x64"
8 changes: 4 additions & 4 deletions environments/prod/storage.tfvars
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
database_name = "database-server-prod"
database_region = "nyc1"
database_size = "s-1vcpu-1gb"
database_image = "ubuntu-20-04-x64"
database_name = "database-server-prod"
database_region = "nyc1"
database_size = "s-1vcpu-1gb"
database_image = "ubuntu-20-04-x64"
14 changes: 8 additions & 6 deletions environments/staging/compute.tfvars
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
presentation_name = "presentation-server-stage"
application_name = "application-server-stage"
region = "nyc1"
size = "s-1vcpu-1gb"
image = "ubuntu-20-04-x64"
digitalocean_token = "your-digitalocean-token"
presentation_name = "presentation-server-stage"
application_name = "application-server-stage"
presentation_region = "nyc1"
presentation_size = "s-1vcpu-1gb"
presentation_image = "ubuntu-20-04-x64"
application_region = "nyc1"
application_size = "s-1vcpu-1gb"
application_image = "ubuntu-20-04-x64"
8 changes: 4 additions & 4 deletions environments/staging/storage.tfvars
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
database_name = "database-server-stage"
database_region = "nyc1"
database_size = "s-1vcpu-1gb"
database_image = "ubuntu-20-04-x64"
database_name = "database-server-stage"
database_region = "nyc1"
database_size = "s-1vcpu-1gb"
database_image = "ubuntu-20-04-x64"
27 changes: 13 additions & 14 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
module "compute" {
source = "./compute"
module "networking" {
source = "./modules/networking"

digitalocean_token = var.digitalocean_token

presentation_name = var.presentation_name
presentation_region = var.presentation_region
presentation_size = var.presentation_size
presentation_image = var.presentation_image

presentation_name = var.presentation_name
application_name = var.application_name
region = var.region
size = var.size
image = var.image
}
application_name = var.application_name
application_region = var.application_region
application_size = var.application_size
application_image = var.application_image

module "storage" {
source = "./modules/storage"

database_name = var.database_name
database_region = var.database_region
database_size = var.database_size
database_image = var.database_image
}

module "networking" {
source = "./modules/networking"
}
16 changes: 8 additions & 8 deletions modules/compute/main.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
resource "digitalocean_droplet" "presentation" {
name = var.presentation_name
region = var.region
size = var.size
image = var.image
name = var.presentation_name
region = var.presentation_region
size = var.presentation_size
image = var.presentation_image
}

resource "digitalocean_droplet" "application" {
name = var.application_name
region = var.region
size = var.size
image = var.image
name = var.application_name
region = var.application_region
size = var.application_size
image = var.application_image
}
8 changes: 8 additions & 0 deletions modules/compute/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ output "application_ip" {
description = "IP address of the application droplet."
value = digitalocean_droplet.application.ipv4_address
}

output "presentation_droplet_id" {
value = digitalocean_droplet.presentation.id
}

output "application_droplet_id" {
value = digitalocean_droplet.application.id
}
12 changes: 12 additions & 0 deletions modules/compute/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "~> 2.0"
}
}
}

provider "digitalocean" {
token = var.digitalocean_token
}
41 changes: 25 additions & 16 deletions modules/compute/variables.tf
Original file line number Diff line number Diff line change
@@ -1,35 +1,44 @@
variable "presentation_name" {
description = "Name for the presentation server"
description = "Name of the presentation droplet"
type = string
}

variable "presentation_region" {
description = "Region for the presentation droplet"
type = string
}

variable "presentation_size" {
description = "Size of the presentation droplet"
type = string
}

variable "presentation_image" {
description = "Image for the presentation droplet"
type = string
default = "presentation-server"
}

variable "application_name" {
description = "Name for the application server"
description = "Name of the application droplet"
type = string
default = "application-server"
}

variable "region" {
description = "Region for the droplets"
variable "application_region" {
description = "Region for the application droplet"
type = string
default = "nyc1"
}

variable "size" {
description = "Size of the droplets"
variable "application_size" {
description = "Size of the application droplet"
type = string
default = "s-1vcpu-1gb"
}

variable "image" {
description = "Image for the droplets"
variable "application_image" {
description = "Image for the application droplet"
type = string
default = "ubuntu-20-04-x64"
}

variable "digitalocean_token" {
description = "DigitalOcean API token."
description = "Digitalocean token"
type = string
default = ""
}
}
47 changes: 32 additions & 15 deletions modules/networking/main.tf
Original file line number Diff line number Diff line change
@@ -1,25 +1,42 @@
resource "digitalocean_private_networking" "network" {
name = "private-network"
droplet_ids = [
digitalocean_droplet.presentation.id,
digitalocean_droplet.application.id,
digitalocean_droplet.database.id
]
module "compute" {
source = "../compute"

presentation_name = var.presentation_name
presentation_region = var.presentation_region
presentation_size = var.presentation_size
presentation_image = var.presentation_image

application_name = var.application_name
application_region = var.application_region
application_size = var.application_size
application_image = var.application_image

digitalocean_token = var.digitalocean_token

}

module "storage" {
source = "../storage"

database_name = var.database_name
database_region = var.database_region
database_size = var.database_size
database_image = var.database_image

digitalocean_token = var.digitalocean_token
}

resource "digitalocean_firewall" "firewall" {
name = "firewall"
droplet_ids = [
digitalocean_droplet.presentation.id,
digitalocean_droplet.application.id,
digitalocean_droplet.database.id
module.compute.presentation_droplet_id,
module.compute.application_droplet_id,
module.storage.database_droplet_id
]

inbound_rule {
protocol = "tcp"
port_range = "80"
source_type = "any"
protocol = "tcp"
port_range = "80"
source_addresses = ["0.0.0.0/0"]
}

}

7 changes: 1 addition & 6 deletions modules/networking/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
output "private_network_id" {
description = "ID of the private network."
value = digitalocean_private_networking.network.id
}

output "firewall_id" {
description = "ID of the firewall."
value = digitalocean_firewall.firewall.id
value = digitalocean_firewall.firewall.name
}
12 changes: 12 additions & 0 deletions modules/networking/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "~> 2.0"
}
}
}

provider "digitalocean" {
token = var.digitalocean_token
}
64 changes: 64 additions & 0 deletions modules/networking/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
variable "presentation_name" {
description = "Name of the presentation droplet"
type = string
}

variable "presentation_region" {
description = "Region for the presentation droplet"
type = string
}

variable "presentation_size" {
description = "Size of the presentation droplet"
type = string
}

variable "presentation_image" {
description = "Image for the presentation droplet"
type = string
}

variable "application_name" {
description = "Name of the application droplet"
type = string
}

variable "application_region" {
description = "Region for the application droplet"
type = string
}

variable "application_size" {
description = "Size of the application droplet"
type = string
}

variable "application_image" {
description = "Image for the application droplet"
type = string
}

variable "digitalocean_token" {
description = "Digitalocean token"
type = string
}

variable "database_name" {
description = "Name of the database"
type = string
}

variable "database_region" {
description = "Region where the database is located"
type = string
}

variable "database_size" {
description = "Size of the database"
type = string
}

variable "database_image" {
description = "Image for the database"
type = string
}
4 changes: 4 additions & 0 deletions modules/storage/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ output "database_password" {
description = "Password for the database."
value = "your-database-password"
}

output "database_droplet_id" {
value = digitalocean_droplet.database.id
}
12 changes: 12 additions & 0 deletions modules/storage/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "~> 2.0"
}
}
}

provider "digitalocean" {
token = var.digitalocean_token
}
Loading

0 comments on commit b96d64e

Please sign in to comment.