Skip to content

Commit

Permalink
chore(DO-1060): Add support for http & custom scale rule
Browse files Browse the repository at this point in the history
  • Loading branch information
x418 committed Aug 26, 2024
1 parent 5f22ba5 commit ce64c34
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
31 changes: 31 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,36 @@ resource "azurerm_container_app" "container_app" {
storage_type = volume.value.storage_type
}
}
dynamic "http_scale_rule" {
for_each = each.value.template.http_scale_rules
content {
name = http_scale_rule.value.name
concurrent_requests = http_scale_rule.value.concurrent_requests
dynamic "authentication" {
for_each = http_scale_rule.value.authentication != null ? [http_scale_rule.value.authentication] : []
content {
secret_name = authentication.value.secret_name
trigger_parameter = authentication.value.trigger_parameter
}
}
}
}

dynamic "custom_scale_rule" {
for_each = each.value.template.custom_scale_rules
content {
name = custom_scale_rule.value.name
custom_rule_type = custom_scale_rule.value.custom_rule_type
metadata = custom_scale_rule.value.metadata
dynamic "authentication" {
for_each = custom_scale_rule.value.authentication != null ? [custom_scale_rule.value.authentication] : []
content {
secret_name = authentication.value.secret_name
trigger_parameter = authentication.value.trigger_parameter
}
}
}
}
}
dynamic "dapr" {
for_each = each.value.dapr == null ? [] : [each.value.dapr]
Expand Down Expand Up @@ -327,4 +357,5 @@ resource "azurerm_container_app" "container_app" {
value = local.container_app_secrets[each.key][secret.key]
}
}

}
27 changes: 26 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,23 @@ variable "container_apps" {
max_replicas = optional(number)
min_replicas = optional(number)
revision_suffix = optional(string)

http_scale_rules = optional(list(object({
name = string
concurrent_requests = number
authentication = optional(object({
secret_name = string
trigger_parameter = string
}))
})))
custom_scale_rules = optional(list(object({
name = string
custom_rule_type = string # See https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_app#custom_rule_type
metadata = map(string)
authentication = optional(object({
secret_name = string
trigger_parameter = string
}))
})))
volume = optional(set(object({
name = string
storage_name = optional(string)
Expand Down Expand Up @@ -134,6 +150,7 @@ variable "container_apps" {
password_secret_name = optional(string)
identity = optional(string)
})))

}))
description = "The container apps to deploy."
nullable = false
Expand All @@ -146,6 +163,14 @@ variable "container_apps" {
condition = alltrue([for n, c in var.container_apps : c.ingress == null ? true : (c.ingress.ip_security_restrictions == null ? true : (length(distinct([for r in c.ingress.ip_security_restrictions : r.action])) <= 1))])
error_message = "The `action` types in an all `ip_security_restriction` blocks must be the same for the `ingress`, mixing `Allow` and `Deny` rules is not currently supported by the service."
}
validation {
condition = alltrue([for n, c in var.container_apps : c.template.custom_scale_rules == null || alltrue([for _, r in c.template.custom_scale_rules : can(regex("^[a-z0-9][a-z0-9-.]*[a-z0-9]$", r.name))])])
error_message = "The `name` in `custom_scale_rule` must consist of lower case alphanumeric characters, '-', or '.', and should start and end with an alphanumeric character."
}
validation {
condition = alltrue([for n, c in var.container_apps : c.template.http_scale_rules == null || alltrue([for _, r in c.template.http_scale_rules : can(regex("^[a-z0-9][a-z0-9-.]*[a-z0-9]$", r.name))])])
error_message = "The `name` in `http_scale_rule` must consist of lower case alphanumeric characters, '-', or '.', and should start and end with an alphanumeric character."
}
}

variable "location" {
Expand Down

0 comments on commit ce64c34

Please sign in to comment.