From e9a8c1632799c7a742afb2cc093caba8958dc507 Mon Sep 17 00:00:00 2001 From: Daniel Gross Date: Thu, 4 Sep 2025 10:39:54 +0200 Subject: [PATCH] Add terraform code --- terraform/main.tf | 51 +++++++++++++++++++++++++++++++++++++ terraform/outputs.tf | 3 +++ terraform/provider.tf | 26 +++++++++++++++++++ terraform/variables.tf | 58 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 138 insertions(+) create mode 100644 terraform/main.tf create mode 100644 terraform/outputs.tf create mode 100644 terraform/provider.tf create mode 100644 terraform/variables.tf diff --git a/terraform/main.tf b/terraform/main.tf new file mode 100644 index 0000000..63d2eb7 --- /dev/null +++ b/terraform/main.tf @@ -0,0 +1,51 @@ +# =========== STACKIT Resources =========== +# data "stackit_dns_zone" "zone" { +# project_id = var.project_id +# name = trimsuffix(var.moodle_domain, ".") +# } + +# resource "stackit_dns_record_set" "moodle_cname" { +# project_id = var.stackit_project_id +# zone_id = data.stackit_dns_zone.zone.id +# name = var.moodle_domain +# type = "CNAME" +# ttl = 300 +# records = ["console.apps.01.cf.eu01.stackit.cloud."] +# } + +# resource "stackit_object_storage_bucket" "moodle_bucket" { +# project_id = var.stackit_project_id +# name = var.s3_bucket_name +# } + +# resource "stackit_object_storage_credential" "s3_credentials" { +# project_id = var.stackit_project_id +# } + +# =========== Cloud Foundry Resources =========== +resource "cloudfoundry_org" "org" { + name = var.cf_org_name +} + +resource "cloudfoundry_space" "space" { + name = var.cf_space_name + org = cloudfoundry_org.org.id +} + +resource "cloudfoundry_app" "versatiles" { + name = var.cf_app_name + space = cloudfoundry_space.space.id + memory = "1G" + disk_quota = "1G" + instances = 1 + command = "versatiles serve -p $PORT -s frontend-dev.br.tar ${var.tiles_url}" + timeout = 10 + health_check_type = "http" + health_check_http_endpoint = "/" + docker_image = var.docker_image + docker_credentials = { + docker_username = var.docker_username + docker_password = var.docker_password + } + strategy = "rolling" +} \ No newline at end of file diff --git a/terraform/outputs.tf b/terraform/outputs.tf new file mode 100644 index 0000000..94d3c0d --- /dev/null +++ b/terraform/outputs.tf @@ -0,0 +1,3 @@ +output "app_url" { + value = cloudfoundry_app.versatiles.routes +} \ No newline at end of file diff --git a/terraform/provider.tf b/terraform/provider.tf new file mode 100644 index 0000000..66ae300 --- /dev/null +++ b/terraform/provider.tf @@ -0,0 +1,26 @@ +terraform { + required_providers { + stackit = { + source = "stackitcloud/stackit" + version = ">= 0.62.0" + } + cloudfoundry = { + source = "cloudfoundry-community/cloudfoundry" + version = ">= 0.53.0" + } + local = { + source = "hashicorp/local" + version = ">= 2.4.0" + } + } +} + +provider "stackit" { + service_account_key_path = var.service_account_key_path +} + +provider "cloudfoundry" { + api_url = "https://api.cf.eu01.stackit.cloud" + user = var.cf_user + password = var.cf_password +} \ No newline at end of file diff --git a/terraform/variables.tf b/terraform/variables.tf new file mode 100644 index 0000000..2a29c77 --- /dev/null +++ b/terraform/variables.tf @@ -0,0 +1,58 @@ +variable "project_id" { + type = string + description = "The id of your STACKIT project." +} + +variable "service_account_key_path" { + type = string + description = "Path to your service account key." + sensitive = true +} + +variable "cf_user" { + type = string + description = "Username (e-mail) of Cloud Foundry user." + sensitive = true +} + +variable "cf_password" { + type = string + description = "Password of Cloud Foundry user." + sensitive = true +} + +variable "cf_org_name" { + type = string + description = "Name of the Cloud Foundry organization." +} + +variable "cf_space_name" { + type = string + description = "Name of the Cloud Foundry space." + default = "dev" +} + +variable "cf_app_name" { + type = string + default = "versatiles" +} + +variable "tiles_url" { + type = string + description = "The url of the tiles file." +} + +variable "docker_image" { + type = string + description = "Application image." +} + +variable "docker_username" { + type = string + description = "Username for private docker registry." +} + +variable "docker_password" { + type = string + description = "Password for private docker registry." +}