Skip to content

Commit

Permalink
Merge branch 'main' into feat/configure-ftps-state
Browse files Browse the repository at this point in the history
  • Loading branch information
kov117 authored Nov 22, 2024
2 parents b857491 + 562a282 commit 3dd0c77
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 2 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@ jobs:
test:
name: Unit Tests
uses: equinor/terraform-baseline/.github/workflows/terraform-test.yml@main
with:
test-filter: tests/unit.tftest.hcl
6 changes: 6 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ resource "azurerm_linux_function_app" "this" {
app_settings = var.app_settings
functions_extension_version = var.functions_extension_version

ftp_publish_basic_authentication_enabled = var.ftp_publish_basic_authentication_enabled
webdeploy_publish_basic_authentication_enabled = var.webdeploy_publish_basic_authentication_enabled

key_vault_reference_identity_id = var.key_vault_reference_identity_id

virtual_network_subnet_id = var.virtual_network_subnet_id
Expand Down Expand Up @@ -162,6 +165,9 @@ resource "azurerm_windows_function_app" "this" {
app_settings = var.app_settings
functions_extension_version = var.functions_extension_version

ftp_publish_basic_authentication_enabled = var.ftp_publish_basic_authentication_enabled
webdeploy_publish_basic_authentication_enabled = var.webdeploy_publish_basic_authentication_enabled

key_vault_reference_identity_id = var.key_vault_reference_identity_id

virtual_network_subnet_id = var.virtual_network_subnet_id
Expand Down
113 changes: 113 additions & 0 deletions tests/configuration.unit.tftest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
mock_provider "azurerm" {}

run "setup_tests" {
module {
source = "./tests/setup-unit-tests"
}
}

run "linux_basic_authentication_disabled" {
command = plan

variables {
app_name = run.setup_tests.app_name
resource_group_name = run.setup_tests.resource_group_name
location = run.setup_tests.location
app_service_plan_id = run.setup_tests.app_service_plan_id
storage_account_id = run.setup_tests.storage_account_id
log_analytics_workspace_id = run.setup_tests.log_analytics_workspace_id

ftp_publish_basic_authentication_enabled = false
webdeploy_publish_basic_authentication_enabled = false
}

assert {
condition = azurerm_linux_function_app.this[0].ftp_publish_basic_authentication_enabled == false
error_message = "Basic authentication enabled for the FTP client."
}

assert {
condition = azurerm_linux_function_app.this[0].webdeploy_publish_basic_authentication_enabled == false
error_message = "Basic authentication enabled for the WebDeploy client."
}
}

run "linux_basic_authentication_enabled" {
command = plan

variables {
app_name = run.setup_tests.app_name
resource_group_name = run.setup_tests.resource_group_name
location = run.setup_tests.location
app_service_plan_id = run.setup_tests.app_service_plan_id
storage_account_id = run.setup_tests.storage_account_id
log_analytics_workspace_id = run.setup_tests.log_analytics_workspace_id

ftp_publish_basic_authentication_enabled = true
webdeploy_publish_basic_authentication_enabled = true
}

assert {
condition = azurerm_linux_function_app.this[0].ftp_publish_basic_authentication_enabled == true
error_message = "Basic authentication disabled for the FTP client."
}

assert {
condition = azurerm_linux_function_app.this[0].webdeploy_publish_basic_authentication_enabled == true
error_message = "Basic authentication disabled for the WebDeploy client."
}
}

run "windows_basic_authentication_disabled" {
command = plan

variables {
app_name = run.setup_tests.app_name
resource_group_name = run.setup_tests.resource_group_name
location = run.setup_tests.location
kind = "Windows"
app_service_plan_id = run.setup_tests.app_service_plan_id
storage_account_id = run.setup_tests.storage_account_id
log_analytics_workspace_id = run.setup_tests.log_analytics_workspace_id

ftp_publish_basic_authentication_enabled = false
webdeploy_publish_basic_authentication_enabled = false
}

assert {
condition = azurerm_windows_function_app.this[0].ftp_publish_basic_authentication_enabled == false
error_message = "Basic authentication enabled for the FTP client."
}

assert {
condition = azurerm_windows_function_app.this[0].webdeploy_publish_basic_authentication_enabled == false
error_message = "Basic authentication enabled for the WebDeploy client."
}
}

run "windows_basic_authentication_enabled" {
command = plan

variables {
app_name = run.setup_tests.app_name
resource_group_name = run.setup_tests.resource_group_name
location = run.setup_tests.location
kind = "Windows"
app_service_plan_id = run.setup_tests.app_service_plan_id
storage_account_id = run.setup_tests.storage_account_id
log_analytics_workspace_id = run.setup_tests.log_analytics_workspace_id

ftp_publish_basic_authentication_enabled = true
webdeploy_publish_basic_authentication_enabled = true
}

assert {
condition = azurerm_windows_function_app.this[0].ftp_publish_basic_authentication_enabled == true
error_message = "Basic authentication disabled for the FTP client."
}

assert {
condition = azurerm_windows_function_app.this[0].webdeploy_publish_basic_authentication_enabled == true
error_message = "Basic authentication disabled for the WebDeploy client."
}
}
20 changes: 20 additions & 0 deletions tests/unit.tftest.hcl → tests/defaults.unit.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ run "linux_app" {
condition = length(azurerm_windows_function_app.this) == 0
error_message = "Trying to create Windows Function App"
}

assert {
condition = azurerm_linux_function_app.this[0].ftp_publish_basic_authentication_enabled == false
error_message = "Basic authentication enabled for the FTP client."
}

assert {
condition = azurerm_linux_function_app.this[0].webdeploy_publish_basic_authentication_enabled == false
error_message = "Basic authentication enabled for the WebDeploy client."
}
}

run "windows_app" {
Expand All @@ -51,4 +61,14 @@ run "windows_app" {
condition = length(azurerm_linux_function_app.this) == 0
error_message = "Trying to create Linux Function App"
}

assert {
condition = azurerm_windows_function_app.this[0].ftp_publish_basic_authentication_enabled == false
error_message = "Basic authentication enabled for the FTP client."
}

assert {
condition = azurerm_windows_function_app.this[0].webdeploy_publish_basic_authentication_enabled == false
error_message = "Basic authentication enabled for the WebDeploy client."
}
}
13 changes: 13 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,19 @@ variable "ftps_state" {
condition = contains(["AllAllowed", "FtpsOnly", "Disabled"], var.ftps_state)
error_message = "FTPS state must be \"AllAllowed\", \"FtpsOnly\" or \"Disabled\"."
}

variable "ftp_publish_basic_authentication_enabled" {
description = "Should basic (username and password) authentication be enabled for the FTP client?"
type = bool
default = false
nullable = false
}

variable "webdeploy_publish_basic_authentication_enabled" {
description = "Should basic (username and password) authentication be enabled for the WebDeploy client?"
type = bool
default = false
nullable = false
}

variable "tags" {
Expand Down

0 comments on commit 3dd0c77

Please sign in to comment.