From 6cb4daa425e6833e9f2475e050db88e6b260b013 Mon Sep 17 00:00:00 2001 From: Joseph Page Date: Fri, 15 Sep 2023 21:28:06 +0200 Subject: [PATCH] feat: add new type of log_drains and validate input --- README.md | 2 +- log_drains.tf | 9 ++++++++- variables.tf | 17 +++++++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8b94b6e..89ca046 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ An opinionated Terraform module to provision an application and database very ea | [environment](#input\_environment) | Map of environment variables to set on the application. Note that value of environment variables can be null or empty. | `map(string)` | `null` | no | | [github\_integration](#input\_github\_integration) | Configuration of the GitHub integration of the application. Only one of github\_integration or gitlab\_integration can be set. |
object({
repo_url = string
integration_uuid = optional(string)
branch = optional(string, "main")
auto_deploy_enabled = optional(bool, true)
})
| `null` | no | | [gitlab\_integration](#input\_gitlab\_integration) | Configuration of the GitLab integration of the application. Only one of github\_integration or gitlab\_integration can be set. |
object({
repo_url = string
integration_uuid = optional(string)
branch = optional(string, "main")
auto_deploy_enabled = optional(bool, true)
})
| `null` | no | -| [log\_drains](#input\_log\_drains) | n/a |
list(object({
type = string
url = optional(string, "")
}))
| `[]` | no | +| [log\_drains](#input\_log\_drains) | n/a |
list(object({
type = string
url = optional(string, "")
drain_region = optional(string, "")
addon = optional(string, "")
host = optional(string, "")
port = optional(string, "")
token = optional(string, "")
}))
| `[]` | no | | [name](#input\_name) | n/a | `string` | n/a | yes | | [review\_apps](#input\_review\_apps) | Configuration of the review apps of the application. |
object({
enabled = optional(bool, false)

# By default: delete review apps 0 hours after closing the PR
delete_on_close_enabled = optional(bool, true)
hours_before_delete_on_close = optional(string, "0")

# By default: delete review apps after 5 days of inactivity (= no new deployment)
delete_stale_enabled = optional(bool, true)
hours_before_delete_stale = optional(string, "168")

# By default: do not create review apps for PRs from forks
automatic_creation_from_forks_allowed = optional(bool, false)
})
| `{}` | no | | [router\_logs](#input\_router\_logs) | When true, the router logs are included in the application logs. (default: `false`) | `bool` | `false` | no | diff --git a/log_drains.tf b/log_drains.tf index afef088..ee2dbc1 100644 --- a/log_drains.tf +++ b/log_drains.tf @@ -7,5 +7,12 @@ resource "scalingo_log_drain" "log_drain" { app = scalingo_app.app.id type = each.value.type - url = sensitive(each.value.url) + + # Log drain parameters are different depending on the type + url = sensitive(each.value.url) + drain_region = each.value.drain_region + addon = each.value.addon + host = each.value.host + port = each.value.port + token = sensitive(each.value.token) } diff --git a/variables.tf b/variables.tf index 6325705..6610b49 100644 --- a/variables.tf +++ b/variables.tf @@ -184,9 +184,22 @@ variable "domain_aliases" { variable "log_drains" { type = list(object({ - type = string - url = optional(string, "") + type = string + url = optional(string, "") + drain_region = optional(string, "") + addon = optional(string, "") + host = optional(string, "") + port = optional(string, "") + token = optional(string, "") })) default = [] nullable = false + + validation { + condition = length([ + for drain in var.log_drains : + drain if !contains(["elk", "appsignal", "logtail", "datadog", "ovh-graylog", "papertrail", "logtail", "syslog"], drain.type) + ]) == 0 + error_message = "The list of log drains must contain only valid log drains type (elk/appsignal/logtail/datadog/ovh-graylog/papertrail/logtail/syslog)." + } }