
locals {
  gitea_path    = "${var.persistent_folder}/gitea"
  gitea_db_path = "${var.database_folder}/mysql.gitea"

  config = templatefile("${path.module}/resources/app.ini.tpl", {
    APP_NAME                         = var.app_config.app_name
    RUN_MODE                         = var.app_config.run_mode
    DOMAIN                           = var.app_config.domain
    HTTP_PORT                        = var.app_config.http_port
    TLS_ENABLED                      = var.tls_enabled
    DISABLE_SSH                      = var.app_config.disable_ssh
    SSH_PORT                         = var.app_config.ssh_port
    LFS_JWT_SECRET                   = var.app_config.lfs_jwt_secret
    DB_HOST                          = var.app_config.db_host
    DB_PORT                          = var.app_config.db_port
    DB_NAME                          = var.app_config.db_name
    DB_USER                          = var.app_config.db_user
    DB_PASSWD                        = var.app_config.db_passwd
    DB_SSL_MODE                      = var.tls_enabled ? "skip-verify" : "false"
    SECRET_KEY                       = var.app_config.secret_key
    INTERNAL_TOKEN                   = var.app_config.internal_token
    DISABLE_REGISTRATION             = var.app_config.disable_registration
    REQUIRE_SIGNIN_VIEW              = var.app_config.require_signin_view
    REGISTER_EMAIL_CONFIRM           = var.app_config.register_email_confirm
    ENABLE_NOTIFY_MAIL               = var.app_config.enable_notify_mail
    ALLOW_ONLY_EXTERNAL_REGISTRATION = var.app_config.allow_only_external_registration
    ENABLE_CAPTCHA                   = var.app_config.enable_captcha
    NO_REPLY_ADDRESS                 = var.app_config.no_reply_address
    JWT_SECRET                       = var.app_config.jwt_secret
    MAIL_FROM                        = var.app_config.mail_from
    SMTP_USER                        = var.app_config.smtp_user
    SMTP_PASSWD                      = var.app_config.smtp_passwd
    SMTP_PROTOCOL                    = var.app_config.smtp_protocol
    SMTP_HOST                        = var.app_config.smtp_host
    SMTP_PORT                        = var.app_config.smtp_port
  })
  config_checksum = sha256(local.config)
}
