From cd61783e989d4cfe08a64bd94db42afe62fd3548 Mon Sep 17 00:00:00 2001 From: Andrea Gueugnaut Date: Mon, 6 Jan 2025 15:05:47 +0100 Subject: [PATCH] build(tools): init terraform configuration --- tools/terraform/.gitignore | 38 ++++++++++++++++++++++ tools/terraform/.terraform.lock.hcl | 24 ++++++++++++++ tools/terraform/main.tf | 49 +++++++++++++++++++++++++++++ tools/terraform/outputs.tf | 19 +++++++++++ tools/terraform/provider.tf | 14 +++++++++ tools/terraform/variables.tf | 32 +++++++++++++++++++ 6 files changed, 176 insertions(+) create mode 100644 tools/terraform/.gitignore create mode 100644 tools/terraform/.terraform.lock.hcl create mode 100644 tools/terraform/main.tf create mode 100644 tools/terraform/outputs.tf create mode 100644 tools/terraform/provider.tf create mode 100644 tools/terraform/variables.tf diff --git a/tools/terraform/.gitignore b/tools/terraform/.gitignore new file mode 100644 index 000000000..5111cb687 --- /dev/null +++ b/tools/terraform/.gitignore @@ -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 + diff --git a/tools/terraform/.terraform.lock.hcl b/tools/terraform/.terraform.lock.hcl new file mode 100644 index 000000000..c7ad6ad46 --- /dev/null +++ b/tools/terraform/.terraform.lock.hcl @@ -0,0 +1,24 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/clevercloud/clevercloud" { + version = "0.5.1" + constraints = "0.5.1" + hashes = [ + "h1:B9tZFOHvqPR8V9rAH/2O7dQvLtUv8p1fnxqy9KD97+Y=", + "zh:2806cdfe0e9b2c3f481d2594cddc792d894ef045320d8cc36b602d64a1aa386d", + "zh:3c6c3f89d5fa1c8bba1fd87363cd5b339d50ed3da69ac20ad153f94472201b6e", + "zh:51dc77db8d8e3cf8a77d729a24cdf0cc7a96dcb507feddd8042d269e802c2b3d", + "zh:59f833e63fa05387303e009d57621fd8a5b6e3027bfc7dd0e568cc88cfec73ee", + "zh:64f0434f7ce2db90276fa8fe83cf1ee7863b9595b5c53223a77f5db0d2b9a0c7", + "zh:6d11cda691bdefe679db00e8b10fdeb01c8a58420b9b4e84a0478706194c003f", + "zh:771e472aaf20a25cc0b8354d77e7b2fc62f22d8c5e7cb8ac76976c79bb5d0251", + "zh:7a5f21b5eeeaa7a725e2dd4fc5c4ca10d7a99265d277e2bd14f87fee3da53bc7", + "zh:94966c8392c97143d7847bfe90f67a41b30282d13bd629a13389479b2003cb14", + "zh:9b1a4fe5f8abdb6b31c167e41afe572cb895fda1c8d3dd68db5df659bee9e962", + "zh:ad187cb05085db55e61f85b7588688970c33551d4f91b10f4e576223c4c98de1", + "zh:b561b1438873df68856ed7cc66de3e3c5e48f33b75558619ec0b0877055a7a52", + "zh:efe5774d7a46ee68b9819a28fdb8530b899cba7237c640817e7078d16301adba", + "zh:fbd23dc82784b7329c566a350351496de76f2c57248a74b84857ed3aea9e8b08", + ] +} diff --git a/tools/terraform/main.tf b/tools/terraform/main.tf new file mode 100644 index 000000000..20ec11c5b --- /dev/null +++ b/tools/terraform/main.tf @@ -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" +} diff --git a/tools/terraform/outputs.tf b/tools/terraform/outputs.tf new file mode 100644 index 000000000..d6a860f7b --- /dev/null +++ b/tools/terraform/outputs.tf @@ -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 +# } diff --git a/tools/terraform/provider.tf b/tools/terraform/provider.tf new file mode 100644 index 000000000..df62ea811 --- /dev/null +++ b/tools/terraform/provider.tf @@ -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 +} diff --git a/tools/terraform/variables.tf b/tools/terraform/variables.tf new file mode 100644 index 000000000..0c12709b0 --- /dev/null +++ b/tools/terraform/variables.tf @@ -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) +}