Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Terraform configuration #1076

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
38 changes: 38 additions & 0 deletions tools/terraform/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log
crash.*.log

# Exclude all .tfvars files, which are likely to contain sensitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
*.tfvars
*.tfvars.json

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Ignore transient lock info files created by terraform apply
.terraform.tfstate.lock.info

# Include override files you do wish to add to version control using negated pattern
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# Ignore CLI configuration files
.terraformrc
terraform.rc

24 changes: 24 additions & 0 deletions tools/terraform/.terraform.lock.hcl

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

49 changes: 49 additions & 0 deletions tools/terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# PostgreSQL Database
resource "clevercloud_postgresql" "postgresql" {
name = var.database_name
plan = "dev"
region = var.region
}

# API Node.js
resource "clevercloud_nodejs" "api" {
name = "${var.project_name}-api"
region = var.region
build_flavor = "M"
min_instance_count = 1
max_instance_count = 1
smallest_flavor = "XS"
biggest_flavor = "XS"

package_manager = "custom"

dependencies = [
clevercloud_postgresql.postgresql.id
]

deployment {
repository = "https://github.com/MTES-MCT/zero-logement-vacant"
commit = "refs/heads/main"
}

environment = {
CC_HEALTH_CHECK_PATH = "/"
CC_OVERRIDE_BUILDCACHE = ".:../.cache/puppeteer"
CEREMA_API = "https://portaildf.cerema.fr"
CEREMA_ENABLED = "false"
CEREMA_PASSWORD = "unused"
CEREMA_USERNAME = "unused"
DATABASE_ENV = "development"
DATABASE_URL = clevercloud_postgresql.postgresql.host
LOG_LEVEL = "debug"
PORT = "8080"
TZ = "Etc/UTC"
WORKSPACE = "@zerologementvacant/server"
}

hooks {
pre_run = "corepack yarn workspace $WORKSPACE migrate"
}

start_script = "corepack yarn workspace $WORKSPACE start"
}
19 changes: 19 additions & 0 deletions tools/terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
output "database_connection_string" {
description = "Connection string for the PostgreSQL database"
value = clevercloud_postgresql.postgresql.host
}

output "api_url" {
description = "Public URL for the API"
value = clevercloud_nodejs.api.vhost
}

# output "frontend_url" {
# description = "Public URL for the React frontend"
# value = clevercloud_application.frontend.public_url
# }
#
# output "queue_url" {
# description = "Public URL for the queue worker"
# value = clevercloud_application.queue.public_url
# }
14 changes: 14 additions & 0 deletions tools/terraform/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
required_providers {
clevercloud = {
source = "clevercloud/clevercloud"
version = "0.5.1"
}
}
}

provider "clevercloud" {
organisation = var.clevercloud_org
token = var.clevercloud_api_token
secret = var.clevercloud_api_secret
}
32 changes: 32 additions & 0 deletions tools/terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
variable "clevercloud_org" {
description = "Clever Cloud Organisation ID"
type = string
}

variable "clevercloud_api_token" {
description = "Clever Cloud API Token"
type = string
}

variable "clevercloud_api_secret" {
description = "Clever Cloud API Secret"
type = string
}

variable "project_name" {
description = "Nom du projet"
type = string
default = "terraform"
}

variable "database_name" {
description = "Nom de la base de données PostgreSQL"
type = string
default = "terraform"
}

variable "region" {
description = "Région Clever Cloud"
type = string
default = "par" # Paris (Europe)
}