From 560cad11559195666bca30646e5506ddf8f88886 Mon Sep 17 00:00:00 2001 From: Daniel Gross Date: Thu, 4 Sep 2025 10:35:50 +0200 Subject: [PATCH 01/10] Update gitignore for terraform --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4c23bf5..448313a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ vars.yaml -*.versatiles \ No newline at end of file +*.versatiles +.terraform/ +*.tfvars \ No newline at end of file From e9a8c1632799c7a742afb2cc093caba8958dc507 Mon Sep 17 00:00:00 2001 From: Daniel Gross Date: Thu, 4 Sep 2025 10:39:54 +0200 Subject: [PATCH 02/10] 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." +} From f67e4b878130a8aad9bb2becd603c6ae83792a51 Mon Sep 17 00:00:00 2001 From: Daniel Gross Date: Thu, 4 Sep 2025 10:40:29 +0200 Subject: [PATCH 03/10] Ignore todo list --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 448313a..109565f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ vars.yaml *.versatiles .terraform/ -*.tfvars \ No newline at end of file +*.tfvars +ToDo.md \ No newline at end of file From ed80defb3ff73996f462d78a1229afbfbc6b0f0b Mon Sep 17 00:00:00 2001 From: Daniel Gross Date: Thu, 4 Sep 2025 16:44:52 +0200 Subject: [PATCH 04/10] Use a newer provider --- terraform/main.tf | 36 +++++++++++++++++++++++------------- terraform/provider.tf | 10 +++------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/terraform/main.tf b/terraform/main.tf index 63d2eb7..3c6ddfb 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -23,29 +23,39 @@ # } # =========== Cloud Foundry Resources =========== -resource "cloudfoundry_org" "org" { +# resource "cloudfoundry_org" "org" { +# name = var.cf_org_name +# } + +# resource "cloudfoundry_space" "space" { +# name = var.cf_space_name +# org = cloudfoundry_org.org.id +# } + +data "cloudfoundry_org" "org" { name = var.cf_org_name } -resource "cloudfoundry_space" "space" { +data "cloudfoundry_space" "space" { name = var.cf_space_name - org = cloudfoundry_org.org.id + org = data.cloudfoundry_org.org.id } resource "cloudfoundry_app" "versatiles" { - name = var.cf_app_name - space = cloudfoundry_space.space.id - memory = "1G" - disk_quota = "1G" + name = var.cf_app_name + space_name = data.cloudfoundry_space.space.name + org_name = data.cloudfoundry_org.org.name + memory = "2G" + disk_quota = "2G" 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_image = var.docker_image docker_credentials = { - docker_username = var.docker_username - docker_password = var.docker_password + username = var.docker_username + password = var.docker_password } - strategy = "rolling" -} \ No newline at end of file + random_route = true + strategy = "rolling" +} diff --git a/terraform/provider.tf b/terraform/provider.tf index 66ae300..b7fb738 100644 --- a/terraform/provider.tf +++ b/terraform/provider.tf @@ -5,12 +5,8 @@ terraform { version = ">= 0.62.0" } cloudfoundry = { - source = "cloudfoundry-community/cloudfoundry" - version = ">= 0.53.0" - } - local = { - source = "hashicorp/local" - version = ">= 2.4.0" + source = "cloudfoundry/cloudfoundry" + version = ">= 1.8.0" } } } @@ -20,7 +16,7 @@ provider "stackit" { } provider "cloudfoundry" { - api_url = "https://api.cf.eu01.stackit.cloud" + api_url = "https://api.system.01.cf.eu01.stackit.cloud" user = var.cf_user password = var.cf_password } \ No newline at end of file From f1aadb639c58a0a5fabf99b86b416d2e2f1b2ff5 Mon Sep 17 00:00:00 2001 From: Daniel Gross Date: Thu, 4 Sep 2025 16:45:30 +0200 Subject: [PATCH 05/10] Update readme --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 4aeb700..d5fb82c 100644 --- a/README.md +++ b/README.md @@ -51,3 +51,11 @@ Push the app: `CF_DOCKER_PASSWORD= cf push --vars-file ` +* retrieve credentials: `cf service-key ` + From 48817fd90a45cbd30bea8809ffb14cee67be839b Mon Sep 17 00:00:00 2001 From: Daniel Gross Date: Thu, 4 Sep 2025 16:52:54 +0200 Subject: [PATCH 06/10] Minor Cleanup --- terraform/main.tf | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/terraform/main.tf b/terraform/main.tf index 3c6ddfb..e57c707 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -1,37 +1,3 @@ -# =========== 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 -# } - data "cloudfoundry_org" "org" { name = var.cf_org_name } From a2aca5e24aae8f1ecfe75e4f93a7f527e543ba0c Mon Sep 17 00:00:00 2001 From: Daniel Gross Date: Thu, 4 Sep 2025 16:55:36 +0200 Subject: [PATCH 07/10] Update readme --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d5fb82c..79eba3d 100644 --- a/README.md +++ b/README.md @@ -54,8 +54,14 @@ Please refer to official STACKIT [documentation](https://docs.stackit.cloud/stac ## Terraform -* create service account: `https://docs.stackit.cloud/stackit/en/how-to-create-cloud-foundry-service-accounts-67772133.html#HowtoCreateCloudFoundryServiceAccounts-StepBySteptotheServiceAccount` +### Prerequisites + +As for now, the Cloud Foundry organization and the Stage you deploy into have to be created beforehand. +Create service account: see the [docs](https://docs.stackit.cloud/stackit/en/how-to-create-cloud-foundry-service-accounts-67772133.html#HowtoCreateCloudFoundryServiceAccounts-StepBySteptotheServiceAccount). + * `cf create-service space-scoped-service-account space-deployer test-tf` * `cf create-service-key ` * retrieve credentials: `cf service-key ` + + From bafd9ab432bc39f810692dd5d6db6fa07165190c Mon Sep 17 00:00:00 2001 From: Daniel Gross Date: Fri, 5 Sep 2025 08:07:26 +0200 Subject: [PATCH 08/10] Update readme --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 79eba3d..00a3c4a 100644 --- a/README.md +++ b/README.md @@ -57,11 +57,13 @@ Please refer to official STACKIT [documentation](https://docs.stackit.cloud/stac ### Prerequisites As for now, the Cloud Foundry organization and the Stage you deploy into have to be created beforehand. -Create service account: see the [docs](https://docs.stackit.cloud/stackit/en/how-to-create-cloud-foundry-service-accounts-67772133.html#HowtoCreateCloudFoundryServiceAccounts-StepBySteptotheServiceAccount). +In order to create Cloud Foundry resources automatically, you will need a service account and service key. Please refer to the [docs](https://docs.stackit.cloud/stackit/en/how-to-create-cloud-foundry-service-accounts-67772133.html#HowtoCreateCloudFoundryServiceAccounts-StepBySteptotheServiceAccount). -* `cf create-service space-scoped-service-account space-deployer test-tf` -* `cf create-service-key ` -* retrieve credentials: `cf service-key ` +### Deployment + +Change to the `terraform` directory. +Create a `.tfvars` file and insert the required terraform variables, see [variables.tf](./terraform/variables.tf). +Call `terraform apply --var-file=`. From 377450a6639412258a1894de3e4a8550c7351ae6 Mon Sep 17 00:00:00 2001 From: Daniel Gross Date: Fri, 5 Sep 2025 09:42:39 +0200 Subject: [PATCH 09/10] Apply requested changes --- README.md | 20 ++++++++++++++++---- terraform/main.tf | 4 ++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 00a3c4a..3856e3b 100644 --- a/README.md +++ b/README.md @@ -62,8 +62,20 @@ In order to create Cloud Foundry resources automatically, you will need a servic ### Deployment Change to the `terraform` directory. -Create a `.tfvars` file and insert the required terraform variables, see [variables.tf](./terraform/variables.tf). +Create a `.tfvars` file and insert the required terraform variables, see [variables.tf](./terraform/variables.tf): + +``` +project_id = "" +service_account_key_path = "" +cf_user = "" +cf_password = "" +tiles_url = ".object.storage.eu01.onstackit.cloud/osm.versatiles>" +docker_image = "" +docker_username = "" +docker_password = "" +cf_app_name = "" +cf_org_name = "" +cf_space_name = "" +``` + Call `terraform apply --var-file=`. - - - diff --git a/terraform/main.tf b/terraform/main.tf index e57c707..dbe43ad 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -8,7 +8,7 @@ data "cloudfoundry_space" "space" { } resource "cloudfoundry_app" "versatiles" { - name = var.cf_app_name + name = var.cf_app_name space_name = data.cloudfoundry_space.space.name org_name = data.cloudfoundry_org.org.name memory = "2G" @@ -17,7 +17,7 @@ resource "cloudfoundry_app" "versatiles" { command = "versatiles serve -p $PORT -s frontend-dev.br.tar ${var.tiles_url}" health_check_type = "http" health_check_http_endpoint = "/" - docker_image = var.docker_image + docker_image = var.docker_image docker_credentials = { username = var.docker_username password = var.docker_password From 081a0c36bfab7ba8ba2d2f0632346556e0850385 Mon Sep 17 00:00:00 2001 From: Daniel Gross Date: Fri, 5 Sep 2025 09:53:44 +0200 Subject: [PATCH 10/10] Create an example var file --- README.md | 16 +--------------- terraform/.tfvars.example | 11 +++++++++++ terraform/main.tf | 4 ++-- terraform/provider.tf | 2 +- terraform/variables.tf | 2 +- 5 files changed, 16 insertions(+), 19 deletions(-) create mode 100644 terraform/.tfvars.example diff --git a/README.md b/README.md index 3856e3b..41c7c6d 100644 --- a/README.md +++ b/README.md @@ -62,20 +62,6 @@ In order to create Cloud Foundry resources automatically, you will need a servic ### Deployment Change to the `terraform` directory. -Create a `.tfvars` file and insert the required terraform variables, see [variables.tf](./terraform/variables.tf): - -``` -project_id = "" -service_account_key_path = "" -cf_user = "" -cf_password = "" -tiles_url = ".object.storage.eu01.onstackit.cloud/osm.versatiles>" -docker_image = "" -docker_username = "" -docker_password = "" -cf_app_name = "" -cf_org_name = "" -cf_space_name = "" -``` +Create a `.tfvars` file and insert the required terraform variables, see [.tfvars.example](./terraform/.tfvars.example): Call `terraform apply --var-file=`. diff --git a/terraform/.tfvars.example b/terraform/.tfvars.example new file mode 100644 index 0000000..b3a24a2 --- /dev/null +++ b/terraform/.tfvars.example @@ -0,0 +1,11 @@ +project_id = "" +service_account_key_path = "" +cf_user = "" +cf_password = "" +tiles_url = ".object.storage.eu01.onstackit.cloud/osm.versatiles>" +docker_image = "" +docker_username = "" +docker_password = "" +cf_app_name = "" +cf_org_name = "" +cf_space_name = "" \ No newline at end of file diff --git a/terraform/main.tf b/terraform/main.tf index dbe43ad..b7a8957 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -18,10 +18,10 @@ resource "cloudfoundry_app" "versatiles" { health_check_type = "http" health_check_http_endpoint = "/" docker_image = var.docker_image + random_route = true + strategy = "rolling" docker_credentials = { username = var.docker_username password = var.docker_password } - random_route = true - strategy = "rolling" } diff --git a/terraform/provider.tf b/terraform/provider.tf index b7fb738..4241340 100644 --- a/terraform/provider.tf +++ b/terraform/provider.tf @@ -16,7 +16,7 @@ provider "stackit" { } provider "cloudfoundry" { - api_url = "https://api.system.01.cf.eu01.stackit.cloud" + api_url = "https://api.system.01.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 index 2a29c77..43c1ec5 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -6,7 +6,7 @@ variable "project_id" { variable "service_account_key_path" { type = string description = "Path to your service account key." - sensitive = true + sensitive = true } variable "cf_user" {