From ccffe42995ff42893789ae2234f1008d25bc376b Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Thu, 31 Oct 2024 20:16:36 -0700 Subject: [PATCH] many chgs --- quickstart/101-azure-functions/main.tf | 76 +++++++++++------------ quickstart/101-azure-functions/outputs.tf | 2 +- 2 files changed, 36 insertions(+), 42 deletions(-) diff --git a/quickstart/101-azure-functions/main.tf b/quickstart/101-azure-functions/main.tf index 5dc245a8..eb502418 100644 --- a/quickstart/101-azure-functions/main.tf +++ b/quickstart/101-azure-functions/main.tf @@ -8,20 +8,6 @@ resource "azurerm_resource_group" "rg" { } resource "random_string" "unique_id" { - length = 8 - special = false -} - -locals { - functionAppName = "fnapp${random_string.unique_id.result}" - hostingPlanName = "fnapp${random_string.unique_id.result}" - applicationInsightsName = "fnapp${random_string.unique_id.result}" - storageAccountName = "${random_string.unique_id.result}azfunctions" - functionWorkerRuntime = var.runtime -} - -# Generate random value for the storage account name -resource "random_string" "storage_account_name" { length = 8 lower = true numeric = false @@ -30,7 +16,7 @@ resource "random_string" "storage_account_name" { } resource "azurerm_storage_account" "storageAccount" { - name = random_string.storage_account_name.result + name = random_string.unique_id.result resource_group_name = azurerm_resource_group.rg.name location = azurerm_resource_group.rg.location account_tier = "Standard" @@ -38,48 +24,56 @@ resource "azurerm_storage_account" "storageAccount" { } resource "azurerm_service_plan" "hostingPlan" { - name = local.hostingPlanName + name = random_string.unique_id.result resource_group_name = azurerm_resource_group.rg.name location = azurerm_resource_group.rg.location os_type = "Linux" sku_name = "P1v2" } -resource "azurerm_function_app" "functionApp" { - name = local.functionAppName +resource "azurerm_linux_function_app" "example" { + name = "fnapp${random_string.unique_id.result}" location = azurerm_resource_group.rg.location resource_group_name = azurerm_resource_group.rg.name - app_service_plan_id = azurerm_app_service_plan.hostingPlan.id + service_plan_id = azurerm_service_plan.hostingPlan.id storage_account_name = azurerm_storage_account.storageAccount.name storage_account_access_key = azurerm_storage_account.storageAccount.primary_access_key - os_type = "linux" - version = "~4" - - app_settings = { - "AzureWebJobsStorage" = "DefaultEndpointsProtocol=https;AccountName=${azurerm_storage_account.storageAccount.name};EndpointSuffix=${azurerm_storage_account.storageAccount.primary_blob_endpoint};AccountKey=${azurerm_storage_account.storageAccount.primary_access_key}" - "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING" = "DefaultEndpointsProtocol=https;AccountName=${azurerm_storage_account.storageAccount.name};EndpointSuffix=${azurerm_storage_account.storageAccount.primary_blob_endpoint};AccountKey=${azurerm_storage_account.storageAccount.primary_access_key}" - "WEBSITE_CONTENTSHARE" = lower(local.functionAppName) - "FUNCTIONS_EXTENSION_VERSION" = "~4" - "WEBSITE_NODE_DEFAULT_VERSION" = "~14" - "APPINSIGHTS_INSTRUMENTATIONKEY" = azurerm_application_insights.applicationInsights.instrumentation_key - "FUNCTIONS_WORKER_RUNTIME" = local.functionWorkerRuntime - } identity { type = "SystemAssigned" } site_config { - ftps_state = "FtpsOnly" - min_tls_version = "1.2" + application_stack { + python_version = "3.9" + } } - - https_only = true } -resource "azurerm_application_insights" "applicationInsights" { - name = local.applicationInsightsName - location = var.resource_group_location - resource_group_name = azurerm_resource_group.rg.name - application_type = "web" -} \ No newline at end of file +resource "azurerm_function_app_function" "example" { + name = "fnappfcn${random_string.unique_id.result}" + function_app_id = azurerm_linux_function_app.example.id + language = "Python" + test_data = jsonencode({ + "name" = "Azure" + }) + config_json = jsonencode({ + "bindings" = [ + { + "authLevel" = "function" + "direction" = "in" + "methods" = [ + "get", + "post", + ] + "name" = "req" + "type" = "httpTrigger" + }, + { + "direction" = "out" + "name" = "$return" + "type" = "http" + }, + ] + }) +} diff --git a/quickstart/101-azure-functions/outputs.tf b/quickstart/101-azure-functions/outputs.tf index 829eb646..eb0bc817 100644 --- a/quickstart/101-azure-functions/outputs.tf +++ b/quickstart/101-azure-functions/outputs.tf @@ -7,7 +7,7 @@ output "storage_account_name" { } output "app_service_plan_name" { - value = azurerm_app_service_plan.hostingPlan.name + value = azurerm_service_plan.hostingPlan.name } output "function_app_name" {