Add MariaDB CRUD Terraform stand
This commit is contained in:
@@ -0,0 +1,19 @@
|
|||||||
|
# MariaDB CRUD test stand
|
||||||
|
|
||||||
|
This Terraform root manages one MariaDB cluster, the `maria` database, three CRUD apps, and an HTTP readiness check.
|
||||||
|
|
||||||
|
The Lucee, Flask, and Node.js apps share the `crud_items` table. Their source repositories are the corresponding repositories under `terraform/` on Gitea. The HTTP service uses the image `naeel/mariadb-check:0.1`; build and publish that image before applying this configuration.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
`terraform.tfvars` contains the Nubes API token and the resource realm. It is ignored by Git. The example file contains no credentials.
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
```sh
|
||||||
|
terraform init
|
||||||
|
terraform validate
|
||||||
|
terraform plan
|
||||||
|
```
|
||||||
|
|
||||||
|
Review the plan before applying it. The database is a managed resource and may be deleted by Terraform destroy.
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
terraform {
|
||||||
|
required_providers {
|
||||||
|
nubes = {
|
||||||
|
source = "tf-registry.containerk8s.services.ngcloud.ru/nubes-test/nubes"
|
||||||
|
version = "3.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "api_token" {
|
||||||
|
type = string
|
||||||
|
sensitive = true
|
||||||
|
description = "Nubes API token"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "realm" {
|
||||||
|
type = string
|
||||||
|
description = "Resource platform shared by the MariaDB cluster and its apps"
|
||||||
|
}
|
||||||
|
|
||||||
|
provider "nubes" {
|
||||||
|
api_token = var.api_token
|
||||||
|
api_endpoint = "https://lk-api-gateway-test.ngcloud.ru/api/v1/svc"
|
||||||
|
}
|
||||||
@@ -0,0 +1,179 @@
|
|||||||
|
resource "nubes_mariadb" "main" {
|
||||||
|
resource_name = "maria-crud-db"
|
||||||
|
|
||||||
|
startup_configuration = {
|
||||||
|
resource_realm = var.realm
|
||||||
|
}
|
||||||
|
|
||||||
|
cluster_configuration = {
|
||||||
|
cpu = 500
|
||||||
|
memory = 1024
|
||||||
|
replicas = 1
|
||||||
|
disk = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
access_configuration = {
|
||||||
|
master_ip_space = "no-needed"
|
||||||
|
master_access_list = jsonencode(["10.0.0.0/8"])
|
||||||
|
}
|
||||||
|
|
||||||
|
mariadb_configuration = {
|
||||||
|
version = "9.4.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
backup_configuration = {
|
||||||
|
s3_uid = "s01325"
|
||||||
|
retain = 14
|
||||||
|
schedule = "0 0 * * *"
|
||||||
|
}
|
||||||
|
|
||||||
|
autoscale_configuration = {
|
||||||
|
enabled = false
|
||||||
|
schedule = 0
|
||||||
|
percent = 10
|
||||||
|
quota = 100
|
||||||
|
}
|
||||||
|
|
||||||
|
adopt_existing_on_create = true
|
||||||
|
keep_on_destroy = true
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "nubes_mariadb_database" "crud" {
|
||||||
|
mariadb_id = nubes_mariadb.main.id
|
||||||
|
db_name = "maria"
|
||||||
|
adopt_existing_on_create = true
|
||||||
|
keep_on_destroy = true
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "nubes_lucee" "crud" {
|
||||||
|
resource_name = "maria-crud-lucee"
|
||||||
|
|
||||||
|
startup_configuration = {
|
||||||
|
resource_realm = var.realm
|
||||||
|
}
|
||||||
|
|
||||||
|
cluster_configuration = {
|
||||||
|
cpu = 300
|
||||||
|
memory = 512
|
||||||
|
replicas = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
access_configuration = {
|
||||||
|
domain = "maria-crud-lucee"
|
||||||
|
}
|
||||||
|
|
||||||
|
app_configuration = {
|
||||||
|
git_path = "https://gitea.services.ngcloud.ru/terraform/maria_lucee.git"
|
||||||
|
version = "5.4"
|
||||||
|
}
|
||||||
|
|
||||||
|
json_env = jsonencode({
|
||||||
|
TABLE_NAME = "crud_items"
|
||||||
|
SERVICE_NAME = "lucee"
|
||||||
|
testds_class = "org.mariadb.jdbc.Driver"
|
||||||
|
testds_bundleName = "org.mariadb.jdbc"
|
||||||
|
testds_bundleVersion = "3.3.2"
|
||||||
|
testds_connectionString = "jdbc:mariadb://${nubes_mariadb.main.state_out_flat["internalConnect.master"]}:3306/${nubes_mariadb_database.crud.db_name}"
|
||||||
|
testds_username = nubes_mariadb.main.vault_secrets["adminUser"]
|
||||||
|
testds_password = nubes_mariadb.main.vault_secrets["adminPass"]
|
||||||
|
testds_connectionLimit = "5"
|
||||||
|
testds_liveTimeout = "15"
|
||||||
|
testds_validate = "false"
|
||||||
|
})
|
||||||
|
|
||||||
|
adopt_existing_on_create = true
|
||||||
|
depends_on = [nubes_mariadb_database.crud]
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "nubes_flask" "crud" {
|
||||||
|
resource_name = "maria-crud-flask"
|
||||||
|
|
||||||
|
startup_configuration = {
|
||||||
|
resource_realm = var.realm
|
||||||
|
}
|
||||||
|
|
||||||
|
cluster_configuration = {
|
||||||
|
cpu = 300
|
||||||
|
memory = 256
|
||||||
|
replicas = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
access_configuration = {
|
||||||
|
domain = "maria-crud-flask"
|
||||||
|
}
|
||||||
|
|
||||||
|
app_configuration = {
|
||||||
|
git_path = "https://gitea.services.ngcloud.ru/terraform/maria_flask.git"
|
||||||
|
version = "3.12"
|
||||||
|
}
|
||||||
|
|
||||||
|
json_env = jsonencode({
|
||||||
|
TABLE_NAME = "crud_items"
|
||||||
|
SERVICE_NAME = "flask"
|
||||||
|
DB_HOST = nubes_mariadb.main.state_out_flat["internalConnect.master"]
|
||||||
|
DB_PORT = "3306"
|
||||||
|
DB_USER = nubes_mariadb.main.vault_secrets["adminUser"]
|
||||||
|
DB_PASSWORD = nubes_mariadb.main.vault_secrets["adminPass"]
|
||||||
|
DB_NAME = nubes_mariadb_database.crud.db_name
|
||||||
|
})
|
||||||
|
|
||||||
|
adopt_existing_on_create = true
|
||||||
|
depends_on = [nubes_mariadb_database.crud]
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "nubes_nodejs" "crud" {
|
||||||
|
resource_name = "maria-crud-nodejs"
|
||||||
|
|
||||||
|
startup_configuration = {
|
||||||
|
resource_realm = var.realm
|
||||||
|
}
|
||||||
|
|
||||||
|
cluster_configuration = {
|
||||||
|
cpu = 300
|
||||||
|
memory = 256
|
||||||
|
replicas = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
access_configuration = {
|
||||||
|
domain = "maria-crud-nodejs"
|
||||||
|
}
|
||||||
|
|
||||||
|
app_configuration = {
|
||||||
|
git_path = "https://gitea.services.ngcloud.ru/terraform/maria_nodejs.git"
|
||||||
|
version = "23"
|
||||||
|
}
|
||||||
|
|
||||||
|
json_env = jsonencode({
|
||||||
|
TABLE_NAME = "crud_items"
|
||||||
|
SERVICE_NAME = "nodejs"
|
||||||
|
DB_HOST = nubes_mariadb.main.state_out_flat["internalConnect.master"]
|
||||||
|
DB_PORT = "3306"
|
||||||
|
DB_USER = nubes_mariadb.main.vault_secrets["adminUser"]
|
||||||
|
DB_PASSWORD = nubes_mariadb.main.vault_secrets["adminPass"]
|
||||||
|
DB_NAME = nubes_mariadb_database.crud.db_name
|
||||||
|
})
|
||||||
|
|
||||||
|
adopt_existing_on_create = true
|
||||||
|
depends_on = [nubes_mariadb_database.crud]
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "nubes_http" "crud_check" {
|
||||||
|
resource_name = "maria-crud-http"
|
||||||
|
resource_realm = var.realm
|
||||||
|
domain = "maria-crud-http"
|
||||||
|
registry_path = "naeel/mariadb-check:0.1"
|
||||||
|
resource_cpu = 100
|
||||||
|
resource_memory = 256
|
||||||
|
resource_instances = 1
|
||||||
|
|
||||||
|
json_env = jsonencode({
|
||||||
|
DB_HOST = nubes_mariadb.main.state_out_flat["internalConnect.master"]
|
||||||
|
DB_PORT = "3306"
|
||||||
|
DB_USER = nubes_mariadb.main.vault_secrets["adminUser"]
|
||||||
|
DB_PASSWORD = nubes_mariadb.main.vault_secrets["adminPass"]
|
||||||
|
DB_NAME = nubes_mariadb_database.crud.db_name
|
||||||
|
})
|
||||||
|
|
||||||
|
adopt_existing_on_create = true
|
||||||
|
depends_on = [nubes_mariadb_database.crud]
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
api_token = ""
|
||||||
|
realm = "k8s-4-sandbox-nubes-ru"
|
||||||
Reference in New Issue
Block a user