Merge pull request 'add-tf-code' (#2) from add-tf-code into main

Reviewed-on: #2
This commit is contained in:
Daniel_Groß 2025-09-05 07:55:48 +00:00
commit f7a0c2bab3
Signed by: professional-service.git.onstackit.cloud
GPG key ID: 004207B7C5DED9F7
7 changed files with 139 additions and 1 deletions

5
.gitignore vendored
View file

@ -1,2 +1,5 @@
vars.yaml
*.versatiles
*.versatiles
.terraform/
*.tfvars
ToDo.md

View file

@ -51,3 +51,17 @@ Push the app: `CF_DOCKER_PASSWORD=<YOUR_PASSWORD> cf push --vars-file <PATH-TO-V
## Custom Domains
Please refer to official STACKIT [documentation](https://docs.stackit.cloud/stackit/en/how-to-register-custom-domains-for-apps-on-stackit-cloud-foundry-67771947.html).
## Terraform
### Prerequisites
As for now, the Cloud Foundry organization and the Stage you deploy into have to be created beforehand.
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).
### Deployment
Change to the `terraform` directory.
Create a `.tfvars` file and insert the required terraform variables, see [.tfvars.example](./terraform/.tfvars.example):
Call `terraform apply --var-file=<PATH-TO-TFVARS-FILE>`.

11
terraform/.tfvars.example Normal file
View file

@ -0,0 +1,11 @@
project_id = "<YOUR-PROJECT-ID>"
service_account_key_path = "<PATH-TO-YOUR-SA-KEY>"
cf_user = "<CLOUD-FOUNDRY-USER-MAIL>"
cf_password = "<CLOUD-FOUNDRY-USER-PASSWORD>"
tiles_url = "<https://<YOUR-BUCKET>.object.storage.eu01.onstackit.cloud/osm.versatiles>"
docker_image = "<DOCKER-IMAGE-URL>"
docker_username = "<DOCKER-USERNAME>"
docker_password = "<DOCKER-PASSWORD>"
cf_app_name = "<NAME-OFF-YOUR-APP>"
cf_org_name = "<NAME-OF-YOUR-CLOUD-FOUNDRY-ORGANIZATION>"
cf_space_name = "<NAME-OF-YOUR-CLOUD-FOUNDRY-SPACE>"

27
terraform/main.tf Normal file
View file

@ -0,0 +1,27 @@
data "cloudfoundry_org" "org" {
name = var.cf_org_name
}
data "cloudfoundry_space" "space" {
name = var.cf_space_name
org = data.cloudfoundry_org.org.id
}
resource "cloudfoundry_app" "versatiles" {
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}"
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
}
}

3
terraform/outputs.tf Normal file
View file

@ -0,0 +1,3 @@
output "app_url" {
value = cloudfoundry_app.versatiles.routes
}

22
terraform/provider.tf Normal file
View file

@ -0,0 +1,22 @@
terraform {
required_providers {
stackit = {
source = "stackitcloud/stackit"
version = ">= 0.62.0"
}
cloudfoundry = {
source = "cloudfoundry/cloudfoundry"
version = ">= 1.8.0"
}
}
}
provider "stackit" {
service_account_key_path = var.service_account_key_path
}
provider "cloudfoundry" {
api_url = "https://api.system.01.cf.eu01.stackit.cloud"
user = var.cf_user
password = var.cf_password
}

58
terraform/variables.tf Normal file
View file

@ -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."
}