From 2c7ab50b02f90919086f55950c8f1f1a9b8c69e6 Mon Sep 17 00:00:00 2001 From: Sebastian <11445087+sebader@users.noreply.github.com> Date: Mon, 25 Apr 2022 09:30:02 +0200 Subject: [PATCH] Fix load generation function for Terraform 3.0 (#304) * use appinsights connstring attribute * run from package out * run from package out * no appsettings * settings back * runtime back * node runtime out * runtime out * move appinsights to LAW mode * fix law name * rename * try env * back to stack * package out * update tf to 3.3.0 * try setting * try ignore --- .../infra/application_insights.tf | 9 -------- src/testing/userload-generator/infra/main.tf | 2 +- .../infra/master_functionapp.tf | 20 +++++++++++++----- .../modules/regional_function/functionapp.tf | 9 +++++++- .../modules/regional_function/variables.tf | 4 ++++ .../userload-generator/infra/monitoring.tf | 21 +++++++++++++++++++ .../infra/regional_functions.tf | 4 ++-- 7 files changed, 51 insertions(+), 18 deletions(-) delete mode 100644 src/testing/userload-generator/infra/application_insights.tf create mode 100644 src/testing/userload-generator/infra/monitoring.tf diff --git a/src/testing/userload-generator/infra/application_insights.tf b/src/testing/userload-generator/infra/application_insights.tf deleted file mode 100644 index 561ec91a3..000000000 --- a/src/testing/userload-generator/infra/application_insights.tf +++ /dev/null @@ -1,9 +0,0 @@ -resource "azurerm_application_insights" "deployment" { - name = "${local.prefix}-loadgen-appi" - location = azurerm_resource_group.deployment.location - resource_group_name = azurerm_resource_group.deployment.name - application_type = "web" - daily_data_cap_in_gb = 30 - - tags = local.default_tags -} diff --git a/src/testing/userload-generator/infra/main.tf b/src/testing/userload-generator/infra/main.tf index 4e0a991b9..f9225fc06 100644 --- a/src/testing/userload-generator/infra/main.tf +++ b/src/testing/userload-generator/infra/main.tf @@ -2,7 +2,7 @@ terraform { required_providers { azurerm = { source = "hashicorp/azurerm" - version = "3.1.0" + version = "3.3.0" } } diff --git a/src/testing/userload-generator/infra/master_functionapp.tf b/src/testing/userload-generator/infra/master_functionapp.tf index 462d6fd1a..fc193f023 100644 --- a/src/testing/userload-generator/infra/master_functionapp.tf +++ b/src/testing/userload-generator/infra/master_functionapp.tf @@ -25,7 +25,13 @@ resource "azurerm_linux_function_app" "master" { identity_ids = [azurerm_user_assigned_identity.functions.id] } - site_config {} + site_config { + application_stack { + dotnet_version = "6.0" + } + + application_insights_connection_string = azurerm_application_insights.deployment.connection_string + } key_vault_reference_identity_id = azurerm_user_assigned_identity.functions.id @@ -33,10 +39,14 @@ resource "azurerm_linux_function_app" "master" { local.function_names_per_geo, { for secret in azurerm_key_vault_secret.functionkeys : replace(upper(secret.name), "-", "_") => "@Microsoft.KeyVault(VaultName=${azurerm_key_vault.deployment.name};SecretName=${secret.name})" }, { - "FUNCTIONS_WORKER_RUNTIME" = "dotnet", - "APPLICATIONINSIGHTS_CONNECTION_STRING" = azurerm_application_insights.deployment.connection_string - "WEBSITE_MOUNT_ENABLED" = "1" - "WEBSITE_RUN_FROM_PACKAGE" = "" # This value will be set by the Function deployment later + "WEBSITE_MOUNT_ENABLED" = "1" + "WEBSITE_RUN_FROM_PACKAGE" = "" # This value will be set by the Function deployment later } ) + + lifecycle { + ignore_changes = [ + app_settings["WEBSITE_RUN_FROM_PACKAGE"], # prevent TF reporting configuration drift after app code is deployed + ] + } } \ No newline at end of file diff --git a/src/testing/userload-generator/infra/modules/regional_function/functionapp.tf b/src/testing/userload-generator/infra/modules/regional_function/functionapp.tf index 308ce8c4c..74451aed8 100644 --- a/src/testing/userload-generator/infra/modules/regional_function/functionapp.tf +++ b/src/testing/userload-generator/infra/modules/regional_function/functionapp.tf @@ -32,18 +32,25 @@ resource "azurerm_linux_function_app" "regional" { application_stack { node_version = "14" } + + application_insights_connection_string = var.application_insights_connection_string } app_settings = merge( var.additional_app_settings, { - "FUNCTIONS_WORKER_RUNTIME" = "node" "PLAYWRIGHT_BROWSERS_PATH" = "0" "ENABLE_ORYX_BUILD" = "true" "SCM_DO_BUILD_DURING_DEPLOYMENT" = "true" "WEBSITE_MOUNT_ENABLED" = "1" "WEBSITE_RUN_FROM_PACKAGE" = "" # This value will be set by the Function deployment later }) + + lifecycle { + ignore_changes = [ + app_settings["WEBSITE_RUN_FROM_PACKAGE"], # prevent TF reporting configuration drift after app code is deployed + ] + } } data "azurerm_function_app_host_keys" "regional" { diff --git a/src/testing/userload-generator/infra/modules/regional_function/variables.tf b/src/testing/userload-generator/infra/modules/regional_function/variables.tf index 999c963d5..7001dd982 100644 --- a/src/testing/userload-generator/infra/modules/regional_function/variables.tf +++ b/src/testing/userload-generator/infra/modules/regional_function/variables.tf @@ -22,4 +22,8 @@ variable "function_user_managed_identity_resource_id" { type = string } +variable "application_insights_connection_string" { + type = string +} + variable "default_tags" {} \ No newline at end of file diff --git a/src/testing/userload-generator/infra/monitoring.tf b/src/testing/userload-generator/infra/monitoring.tf new file mode 100644 index 000000000..0b80924b8 --- /dev/null +++ b/src/testing/userload-generator/infra/monitoring.tf @@ -0,0 +1,21 @@ +resource "azurerm_log_analytics_workspace" "deployment" { + name = "${local.prefix}-loadgen-log" + location = azurerm_resource_group.deployment.location + resource_group_name = azurerm_resource_group.deployment.name + sku = "PerGB2018" + retention_in_days = 30 # has to be between 30 and 730 + daily_quota_gb = 30 + + tags = local.default_tags +} + +resource "azurerm_application_insights" "deployment" { + name = "${local.prefix}-loadgen-appi" + location = azurerm_resource_group.deployment.location + resource_group_name = azurerm_resource_group.deployment.name + application_type = "web" + workspace_id = azurerm_log_analytics_workspace.deployment.id + daily_data_cap_in_gb = 30 + + tags = local.default_tags +} diff --git a/src/testing/userload-generator/infra/regional_functions.tf b/src/testing/userload-generator/infra/regional_functions.tf index 49f313fa9..94f5e6387 100644 --- a/src/testing/userload-generator/infra/regional_functions.tf +++ b/src/testing/userload-generator/infra/regional_functions.tf @@ -6,10 +6,10 @@ module "regional_functions" { prefix = local.prefix resource_group_name = azurerm_resource_group.deployment.name additional_app_settings = { - "APPLICATIONINSIGHTS_CONNECTION_STRING" = azurerm_application_insights.deployment.connection_string - "TEST_BASEURL" = var.targeturl + "TEST_BASEURL" = var.targeturl } + application_insights_connection_string = azurerm_application_insights.deployment.connection_string function_user_managed_identity_resource_id = azurerm_user_assigned_identity.functions.id default_tags = local.default_tags