commit c3bc6ab80644741ffae8570e3f49602851196eeb Author: Stanislav Kopp Date: Tue May 6 09:30:27 2025 +0200 Init diff --git a/README.md b/README.md new file mode 100644 index 0000000..66c946d --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# Terraform modules for STACKIT resources + +## Overview + +You can find general overview of Terraform in [ITDOC](https://itdoc.schwarz/display/STACKIT/Terraform+overview) + +## How to use + +You can find examples in README.md of each module folder, e.g. for [Redis](./redis/README.md) + diff --git a/create-secret/providers.tf b/create-secret/providers.tf new file mode 100644 index 0000000..1247803 --- /dev/null +++ b/create-secret/providers.tf @@ -0,0 +1,9 @@ +provider "vault" { + address = "https://prod.sm.eu01.stackit.cloud" + skip_child_token = true + + auth_login_userpass { + username = var.secret_manager_username + password = var.secret_manager_password + } +} \ No newline at end of file diff --git a/create-secret/secret.tf b/create-secret/secret.tf new file mode 100644 index 0000000..22f04e8 --- /dev/null +++ b/create-secret/secret.tf @@ -0,0 +1,7 @@ +resource "vault_kv_secret_v2" "this" { + mount = var.secret_manager_instance_id + name = var.secrets_path + cas = 1 + delete_all_versions = true + data_json = jsonencode(var.secret_data) +} \ No newline at end of file diff --git a/create-secret/variables.tf b/create-secret/variables.tf new file mode 100644 index 0000000..35c588b --- /dev/null +++ b/create-secret/variables.tf @@ -0,0 +1,29 @@ +# Secret Manager +variable "secret_manager_instance_id" { + description = "instance id of the secret mangert to store credentials" + type = string + default = "" +} + +variable "secret_manager_username" { + description = "username of the secret mangert to store credentials" + type = string + sensitive = true +} + +variable "secret_manager_password" { + description = "password of the secret mangert to store credentials" + type = string + sensitive = true +} + +variable "secrets_path" { + description = "path in secret manager to store the postgres credentials" + type = string + default = "" +} + +variable "secret_data" { + description = "Secret data in JSON format" + type = map(string) +} diff --git a/mongodb/mongodb.tf b/mongodb/mongodb.tf new file mode 100644 index 0000000..5ee3a58 --- /dev/null +++ b/mongodb/mongodb.tf @@ -0,0 +1,48 @@ +// MongoDB Instance +resource "stackit_mongodbflex_instance" "this" { + project_id = var.stackit_project_id + name = var.mongodb_instance_name + acl = var.mongodb_instance_acl + backup_schedule = var.mongodb_instance_backup_schedule + flavor = var.mongodb_instance_flavor + options = var.mongodb_instance_options + replicas = var.mongodb_instance_replicas + storage = var.mongodb_instance_storage + version = var.mongodb_instance_version +} + +// MongoDB User +resource "stackit_mongodbflex_user" "this" { + project_id = var.stackit_project_id + instance_id = stackit_mongodbflex_instance.this.instance_id + username = var.mongodb_user_name + roles = var.mongodb_user_roles + database = var.mongodb_user_database +} + +# // Configure Secret Manager Provider +# provider "vault" { +# address = "https://prod.sm.eu01.stackit.cloud" +# skip_child_token = true +# auth_login_userpass { +# username = var.secret_manager_username +# password = var.secret_manager_password +# } +# } + +# // Store MongoDB Credentials in Secret Manager +# resource "vault_kv_secret_v2" "mongodb_cred_save" { +# mount = var.secret_manager_instance_id +# name = var.mongodb_secrets_path +# cas = 1 +# delete_all_versions = true +# data_json = jsonencode( +# { +# username = stackit_mongodbflex_user.mongodb_user.username, +# password = stackit_mongodbflex_user.mongodb_user.password, +# host = stackit_mongodbflex_user.mongodb_user.host, +# port = stackit_mongodbflex_user.mongodb_user.port, +# uri = stackit_mongodbflex_user.mongodb_user.uri +# } +# ) +# } diff --git a/mongodb/outputs.tf b/mongodb/outputs.tf new file mode 100644 index 0000000..20dc715 --- /dev/null +++ b/mongodb/outputs.tf @@ -0,0 +1,29 @@ + +# MongoDB Instance +output "mongodb_instance_id" { + value = stackit_mongodbflex_instance.this.instance_id +} + +# MongoDB User +output "mongodb_host" { + value = stackit_mongodbflex_user.this.host +} + +output "mongodb_password" { + value = stackit_mongodbflex_user.this.password + sensitive = true +} + +output "mongodb_port" { + value = stackit_mongodbflex_user.this.port +} + +output "mongodb_uri" { + #value = format("mongodb://%s:%s@%s:%s/%s", stackit_mongodbflex_user.this.username, stackit_mongodbflex_user.this.password, stackit_mongodbflex_instance.mongodb_instance.host, stackit_mongodbflex_instance.mongodb_instance.port + value = stackit_mongodbflex_user.this.uri + sensitive = true +} + +output "mongodb_user_id" { + value = stackit_mongodbflex_user.this.user_id +} diff --git a/mongodb/providers.tf b/mongodb/providers.tf new file mode 100644 index 0000000..792bab1 --- /dev/null +++ b/mongodb/providers.tf @@ -0,0 +1,8 @@ +terraform { + required_providers { + stackit = { + source = "stackitcloud/stackit" + version = "~> 0.50.0" + } + } +} diff --git a/mongodb/variables.tf b/mongodb/variables.tf new file mode 100644 index 0000000..e69bd6f --- /dev/null +++ b/mongodb/variables.tf @@ -0,0 +1,68 @@ +# STACKIT Project +variable "stackit_project_id" { + description = "ID of the stackit Project" + type = string +} +# MongoDB Instance +variable "mongodb_instance_name" { + description = "name of the mongodb instance" + type = string +} + +variable "mongodb_instance_acl" { + description = "access control list for mongodb" + type = list(string) +} + +variable "mongodb_instance_backup_schedule" { + description = "backup schedule for mongodb as crontab expression" + type = string +} + +variable "mongodb_instance_flavor" { + description = "resources for mongodb" + type = object({ + cpu = number + ram = number + }) +} + +variable "mongodb_instance_options" { + description = "options for mongodb" + type = object({ + type = string + }) +} + +variable "mongodb_instance_replicas" { + description = "number of replicas for mongodb" + type = number +} + +variable "mongodb_instance_storage" { + description = "storage for mongodb" + type = object({ + class = string + size = number + }) +} + +variable "mongodb_instance_version" { + description = "version of the mongodb instance" + type = string +} + +# MongoDB User +variable "mongodb_user_name" { + description = "(optional) name of the user" + type = string +} +variable "mongodb_user_roles" { + description = "Database access levels for the user. Some of the possible values are: [read, readWrite, readWriteAnyDatabase]" + type = list(string) +} + +variable "mongodb_user_database" { + description = "name of the database for user to gain access to." + type = string +} diff --git a/objectstorage/objectstorage.tf b/objectstorage/objectstorage.tf new file mode 100644 index 0000000..8f3c0bc --- /dev/null +++ b/objectstorage/objectstorage.tf @@ -0,0 +1,15 @@ +resource "stackit_objectstorage_bucket" "this" { + name = var.objectstorage_bucket_name + project_id = var.stackit_project_id +} + +resource "stackit_objectstorage_credentials_group" "this" { + name = var.objectstorage_credentials_group_name + project_id = var.stackit_project_id +} + +resource "stackit_objectstorage_credential" "this" { + depends_on = [stackit_objectstorage_credentials_group.this] + credentials_group_id = stackit_objectstorage_credentials_group.this.credentials_group_id + project_id = var.stackit_project_id +} diff --git a/objectstorage/outputs.tf b/objectstorage/outputs.tf new file mode 100644 index 0000000..ad4defb --- /dev/null +++ b/objectstorage/outputs.tf @@ -0,0 +1,15 @@ +output "objectstorage_access_key" { + value = stackit_objectstorage_credential.this.access_key +} + +output "objectstorage_secret_access_key" { + value = stackit_objectstorage_credential.this.secret_access_key +} + +output "objectstorage_url_path_style" { + value = stackit_objectstorage_bucket.this.url_path_style +} + +output "objectstorage_url_virtual_hosted_style" { + value = stackit_objectstorage_bucket.this.url_virtual_hosted_style +} diff --git a/objectstorage/providers.tf b/objectstorage/providers.tf new file mode 100644 index 0000000..792bab1 --- /dev/null +++ b/objectstorage/providers.tf @@ -0,0 +1,8 @@ +terraform { + required_providers { + stackit = { + source = "stackitcloud/stackit" + version = "~> 0.50.0" + } + } +} diff --git a/objectstorage/variables.tf b/objectstorage/variables.tf new file mode 100644 index 0000000..11daa26 --- /dev/null +++ b/objectstorage/variables.tf @@ -0,0 +1,19 @@ +variable "stackit_project_id" { + description = "ID of the STACKIT Portal Project" + type = string +} + +variable "objectstorage_bucket_name" { + description = "Name of the bucket which will be used in object storage" + type = string +} + +variable "objectstorage_region" { + description = "Name of the resource region" + type = string +} + +variable "objectstorage_credentials_group_name" { + description = "Name of the credentials group where access keys will be stored" + type = string +} \ No newline at end of file diff --git a/observability/alerts.tf b/observability/alerts.tf new file mode 100644 index 0000000..d147825 --- /dev/null +++ b/observability/alerts.tf @@ -0,0 +1,49 @@ +locals { + basic_auth = base64encode("${stackit_observability_credential.observability_credentials.username}:${stackit_observability_credential.observability_credentials.password}") +} + +resource "local_sensitive_file" "alert_configs" { + content = templatefile("../../monitoring/alerts/dev/alertconfigs.json", { + msTeamWebhook = var.msTeamWebhook + }) + filename = ".temp/alertconfigs.json" +} + +resource "null_resource" "alert_configs" { + triggers = { + config = local_sensitive_file.alert_configs.content_sha1 + url = var.observability_url + } + provisioner "local-exec" { + command = <