From c6dae6cd83298a3a8319ffe5dad761823c376ede Mon Sep 17 00:00:00 2001 From: Mher Poghosyan Date: Fri, 19 Jan 2024 18:40:21 +0400 Subject: [PATCH] add new funtions --- local_environment/main.tf | 35 +++++++++++++++++++++++++ local_environment/variables.tf | 47 +++++++++++++++++++++++++++++++++- 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/local_environment/main.tf b/local_environment/main.tf index 25c6580..1a4b424 100644 --- a/local_environment/main.tf +++ b/local_environment/main.tf @@ -32,3 +32,38 @@ resource "local_file" "env_file" { depends_on = [resource.null_resource.clone_repo] } + +data "template_file" "supervisor" { + template = file(var.supervisor_template_path) + + vars = { + service_name = var.service_name + service_repo = var.service_repo + } +} + +resource "local_file" "supervisor_file" { + count = var.supervisor_file != null ? ((anytrue([for suffix in var.valid_suffixes_supervisor : endswith(var.proxy_pass, suffix)])) != true ? 1 : 0) : 0 + content = data.template_file.supervisor.rendered + filename = var.supervisor_file + depends_on = [resource.null_resource.clone_repo] + +} +data "template_file" "nginx" { + template = file(var.nginx_template_path) + + vars = { + service_name = var.service_name + server_host = var.server_host + proxy_pass = var.proxy_pass + proxy_header = anytrue([for suffix in var.valid_suffixes_supervisor : endswith(var.proxy_pass, suffix)]) == true ? var.proxy_pass : "$host" + } +} + +resource "local_file" "nginx_file" { + count = endswith(var.nginx_template_path, "none") != true ? ((anytrue([for suffix in var.valid_suffixes_supervisor : endswith(var.server_host, suffix)])) != true ? 1 : 0) : 0 + content = data.template_file.nginx.rendered + filename = var.nginx_file + depends_on = [resource.null_resource.clone_repo] + +} diff --git a/local_environment/variables.tf b/local_environment/variables.tf index 709dcfc..3c78d9d 100644 --- a/local_environment/variables.tf +++ b/local_environment/variables.tf @@ -13,6 +13,26 @@ variable "env_file" { type = string default = null } +variable "supervisor_template_path" { + description = "supervisor template path" + type = string + default = "templates/supervisord/supervisord.ini" +} +variable "supervisor_file" { + description = "supervisor template path" + type = string + default = null +} +variable "nginx_template_path" { + description = "nginx template path" + type = string + default = null +} +variable "nginx_file" { + description = "nginx template path" + type = string + default = null +} variable "microservice_catalog_path" { description = "Microservice Catalog Folder Path" type = string @@ -33,7 +53,32 @@ variable "github_base" { default = "git@github.com:ucraft-com" } variable "username" { - description = "A map of variables to pass to the template" + description = "A string of variables to pass to the template" type = string default = null } +variable "service_name" { + description = "A string of variables to pass to the template" + type = string + default = null +} +variable "server_host" { + description = "A string of variables to pass to the template" + type = string + default = "remote" +} +variable "proxy_pass" { + description = "A string of variables to pass to the template" + type = string + default = "" +} +variable "proxy_header" { + description = "A string of variables to pass to the template" + type = string + default = "" +} +variable "valid_suffixes_supervisor" { + description = "List of valid suffixes for server_host" + type = list(string) + default = [".ucraft.ai", "ucraft.ai/"] +}