Skip to content

Commit

Permalink
update exposed module
Browse files Browse the repository at this point in the history
  • Loading branch information
Krusty93 committed Jan 10, 2025
1 parent 6689274 commit d19d7b0
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 3 deletions.
1 change: 1 addition & 0 deletions infra/modules/azure_app_service_exposed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ This module is used to create an Azure App Service, allowing it to be configured
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | Resource group to deploy resources to | `string` | n/a | yes |
| <a name="input_slot_app_settings"></a> [slot\_app\_settings](#input\_slot\_app\_settings) | Staging slot application settings | `map(string)` | `{}` | no |
| <a name="input_stack"></a> [stack](#input\_stack) | n/a | `string` | `"node"` | no |
| <a name="input_startup_command"></a> [startup\_command](#input\_startup\_command) | (Optional) The PM2 file used as PM2 process entry point | `string` | `""` | no |
| <a name="input_sticky_app_setting_names"></a> [sticky\_app\_setting\_names](#input\_sticky\_app\_setting\_names) | (Optional) A list of application setting names that are not swapped between slots | `list(string)` | `[]` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | Resources tags | `map(any)` | n/a | yes |
| <a name="input_tier"></a> [tier](#input\_tier) | Resource tiers depending on workload. Allowed values are 'xs', 's', 'm', 'l', 'xl'. Legacy values 'premium', 'standard', 'test' are also supported for backward compatibility. | `string` | `"l"` | no |
Expand Down
2 changes: 1 addition & 1 deletion infra/modules/azure_app_service_exposed/app_service.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ resource "azurerm_linux_web_app" "this" {
health_check_path = var.health_check_path
health_check_eviction_time_in_min = 2

app_command_line = local.app_service.command_line
app_command_line = local.app_service.startup_command

application_stack {
node_version = var.stack == "node" ? "${var.node_version}-lts" : null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ resource "azurerm_linux_web_app_slot" "this" {
health_check_path = var.health_check_path
health_check_eviction_time_in_min = 2

app_command_line = local.app_service.command_line
app_command_line = local.app_service.startup_command

application_stack {
node_version = var.stack == "node" ? "${var.node_version}-lts" : null
Expand Down
5 changes: 4 additions & 1 deletion infra/modules/azure_app_service_exposed/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ locals {
zone_balancing_enabled = local.tier != "s" && local.tier != "xs"
is_slot_enabled = local.tier == "s" || local.tier == "xs" ? 0 : 1
always_on = local.tier == "xs" ? false : true
command_line = var.pm2_startup_file_name == null ? null : "pm2 start ${var.pm2_startup_file_name} -i max --no-daemon"
startup_command = (var.stack == "node"
? (var.startup_command == "" ? "pm2 start index.js -i max --no-daemon" : var.startup_command)
: (var.stack == "java" && var.startup_command == "" ? null : var.startup_command)
)
}

application_insights = {
Expand Down
245 changes: 245 additions & 0 deletions infra/modules/azure_app_service_exposed/tests/appservice.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,248 @@ run "app_service_is_correct_plan" {
error_message = "The App Service should have Always On enabled"
}
}

run "app_service_node_default_startup_command" {
command = plan

plan_options {
target = [
azurerm_linux_web_app.this,
azurerm_linux_web_app_slot.this,
]
}

variables {
environment = {
prefix = "dx"
env_short = "d"
location = "italynorth"
domain = "modules"
app_name = "test"
instance_number = "01"
}

tags = {}

resource_group_name = run.setup_tests.resource_group_name
tier = "m"

app_settings = {}
slot_app_settings = {}

health_check_path = "/health"
}

assert {
condition = azurerm_linux_web_app.this.site_config[0].application_stack[0].node_version != null
error_message = "Node version is null"
}

assert {
condition = azurerm_linux_web_app_slot.this[0].site_config[0].application_stack[0].node_version != null
error_message = "Node version is null on staging slot"
}

assert {
condition = strcontains(azurerm_linux_web_app.this.site_config[0].app_command_line, "pm2 start")
error_message = "PM2 is not set as default for Node.js"
}

assert {
condition = strcontains(azurerm_linux_web_app_slot.this[0].site_config[0].app_command_line, "pm2 start")
error_message = "PM2 is not set as default for Node.js on staging slot"
}
}

run "app_service_node_custom_startup_command" {
command = plan

plan_options {
target = [
azurerm_linux_web_app.this,
azurerm_linux_web_app_slot.this,
]
}

variables {
environment = {
prefix = "dx"
env_short = "d"
location = "italynorth"
domain = "modules"
app_name = "test"
instance_number = "01"
}

tags = {}

resource_group_name = run.setup_tests.resource_group_name
tier = "m"

app_settings = {}
slot_app_settings = {}

health_check_path = "/health"

startup_command = "custom command"
}

assert {
condition = azurerm_linux_web_app.this.site_config[0].application_stack[0].node_version != null
error_message = "Node version is null"
}

assert {
condition = azurerm_linux_web_app.this.site_config[0].app_command_line == "custom command"
error_message = "Startup command override doesn't work on Node.js stack"
}
}

run "app_service_java_default_startup_command" {
command = plan

plan_options {
target = [
azurerm_linux_web_app.this,
azurerm_linux_web_app_slot.this,
]
}

variables {
environment = {
prefix = "dx"
env_short = "d"
location = "italynorth"
domain = "modules"
app_name = "test"
instance_number = "01"
}

tags = {}

resource_group_name = run.setup_tests.resource_group_name
tier = "m"

app_settings = {}
slot_app_settings = {}

health_check_path = "/health"

stack = "java"
}

assert {
condition = azurerm_linux_web_app.this.site_config[0].application_stack[0].java_version != null
error_message = "Java version is null"
}

assert {
condition = azurerm_linux_web_app_slot.this[0].site_config[0].application_stack[0].java_version != null
error_message = "Java version is null on staging slot"
}

assert {
condition = azurerm_linux_web_app.this.site_config[0].application_stack[0].java_server != null
error_message = "Java server is null"
}

assert {
condition = azurerm_linux_web_app_slot.this[0].site_config[0].application_stack[0].java_server != null
error_message = "Java server is null on staging slot"
}

assert {
condition = azurerm_linux_web_app.this.site_config[0].application_stack[0].java_server_version != null
error_message = "Java server version is null"
}

assert {
condition = azurerm_linux_web_app_slot.this[0].site_config[0].application_stack[0].java_server_version != null
error_message = "Java server version is null on staging slot"
}

assert {
condition = azurerm_linux_web_app.this.site_config[0].app_command_line == null
error_message = "Default startup command value is not null on Java stack"
}

assert {
condition = azurerm_linux_web_app_slot.this[0].site_config[0].app_command_line == null
error_message = "Default startup command value is not null on Java stack on staging slot"
}
}

run "app_service_java_custom_startup_command" {
command = plan

plan_options {
target = [
azurerm_linux_web_app.this,
azurerm_linux_web_app_slot.this,
]
}

variables {
environment = {
prefix = "dx"
env_short = "d"
location = "italynorth"
domain = "modules"
app_name = "test"
instance_number = "01"
}

tags = {}

resource_group_name = run.setup_tests.resource_group_name
tier = "m"

app_settings = {}
slot_app_settings = {}

health_check_path = "/health"

stack = "java"
startup_command = "custom command"
}

assert {
condition = azurerm_linux_web_app.this.site_config[0].application_stack[0].java_version != null
error_message = "Java version is null"
}

assert {
condition = azurerm_linux_web_app_slot.this[0].site_config[0].application_stack[0].java_version != null
error_message = "Java version is null on staging slot"
}

assert {
condition = azurerm_linux_web_app.this.site_config[0].application_stack[0].java_server != null
error_message = "Java server is null"
}

assert {
condition = azurerm_linux_web_app_slot.this[0].site_config[0].application_stack[0].java_server != null
error_message = "Java server is null on staging slot"
}

assert {
condition = azurerm_linux_web_app.this.site_config[0].application_stack[0].java_server_version != null
error_message = "Java server version is null"
}

assert {
condition = azurerm_linux_web_app_slot.this[0].site_config[0].application_stack[0].java_server_version != null
error_message = "Java server version is null on staging slot"
}

assert {
condition = azurerm_linux_web_app.this.site_config[0].app_command_line != null
error_message = "Startup command override doesn't work on Java stack"
}

assert {
condition = azurerm_linux_web_app_slot.this[0].site_config[0].app_command_line != null
error_message = "Startup command override doesn't work on Java stack on staging slot"
}
}
6 changes: 6 additions & 0 deletions infra/modules/azure_app_service_exposed/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,9 @@ variable "pm2_startup_file_name" {
default = null
description = "(Optional) Use this variable to enable PM2. The specified file is used as PM2 process entry point"
}

variable "startup_command" {
type = string
default = ""
description = "(Optional) The PM2 file used as PM2 process entry point"
}

0 comments on commit d19d7b0

Please sign in to comment.