From 1b0212fb942167d744e7544007296d223db46cc7 Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Thu, 31 Oct 2024 19:11:12 -0700 Subject: [PATCH 01/11] Initial put --- quickstart/101-azure-functions/README.md | 25 +++++++ quickstart/101-azure-functions/main.tf | 82 +++++++++++++++++++++ quickstart/101-azure-functions/outputs.tf | 19 +++++ quickstart/101-azure-functions/providers.tf | 18 +++++ quickstart/101-azure-functions/variables.tf | 42 +++++++++++ 5 files changed, 186 insertions(+) create mode 100644 quickstart/101-azure-functions/README.md create mode 100644 quickstart/101-azure-functions/main.tf create mode 100644 quickstart/101-azure-functions/outputs.tf create mode 100644 quickstart/101-azure-functions/providers.tf create mode 100644 quickstart/101-azure-functions/variables.tf diff --git a/quickstart/101-azure-functions/README.md b/quickstart/101-azure-functions/README.md new file mode 100644 index 00000000..836b04fa --- /dev/null +++ b/quickstart/101-azure-functions/README.md @@ -0,0 +1,25 @@ +# Azure Function App +This template deploys an Azure Function App. + +## Terraform resource types + +- [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) +- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) +- [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) +- [azurerm_storage_account](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account) +- [azurerm_app_service_plan](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/app_service_plan) +- [azurerm_function_app](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/function_app) +- [azurerm_application_insights](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/application_insights) + +## Variables + +| Name | Description | Default value | +|-|-|-| +| `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg | +| `resource_group_location` | Location of the resource group. | eastus | +| `appName` | The name of the function app that you wish to create. | fnapp${random_string.unique_id.result} | +| `storageAccountType` | Storage Account type. Possible values are: Standard_LRS, Standard_GRS, Standard_RAGRS. | Standard_LRS | +| `appInsightsLocation` | Location for Application Insights. | "" | +| `runtime` | The language worker runtime to load in the function app. Possible values are: node, dotnet, java. | node | + +## Example \ No newline at end of file diff --git a/quickstart/101-azure-functions/main.tf b/quickstart/101-azure-functions/main.tf new file mode 100644 index 00000000..dcc6cddf --- /dev/null +++ b/quickstart/101-azure-functions/main.tf @@ -0,0 +1,82 @@ +resource "random_pet" "rg_name" { + prefix = var.resource_group_name_prefix +} + +resource "azurerm_resource_group" "rg" { + location = var.resource_group_location + name = random_pet.rg_name.id +} + +resource "random_string" "unique_id" { + length = 8 + special = false +} + +locals { + functionAppName = var.appName + hostingPlanName = var.appName + applicationInsightsName = var.appName + storageAccountName = "${random_string.unique_id.result}azfunctions" + functionWorkerRuntime = var.runtime +} + +resource "azurerm_storage_account" "storageAccount" { + name = local.storageAccountName + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + account_tier = "Standard" + account_replication_type = var.storageAccountType + + enable_https_traffic_only = true + allow_blob_public_access = false +} + +resource "azurerm_app_service_plan" "hostingPlan" { + name = local.hostingPlanName + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + kind = "FunctionApp" + sku { + tier = "Dynamic" + size = "Y1" + } +} + +resource "azurerm_function_app" "functionApp" { + name = local.functionAppName + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + app_service_plan_id = azurerm_app_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" + } + + https_only = true +} + +resource "azurerm_application_insights" "applicationInsights" { + name = local.applicationInsightsName + location = var.appInsightsLocation + resource_group_name = azurerm_resource_group.rg.name + application_type = "web" +} \ No newline at end of file diff --git a/quickstart/101-azure-functions/outputs.tf b/quickstart/101-azure-functions/outputs.tf new file mode 100644 index 00000000..829eb646 --- /dev/null +++ b/quickstart/101-azure-functions/outputs.tf @@ -0,0 +1,19 @@ +output "resource_group_name" { + value = azurerm_resource_group.rg.name +} + +output "storage_account_name" { + value = azurerm_storage_account.storageAccount.name +} + +output "app_service_plan_name" { + value = azurerm_app_service_plan.hostingPlan.name +} + +output "function_app_name" { + value = azurerm_function_app.functionApp.name +} + +output "application_insights_name" { + value = azurerm_application_insights.applicationInsights.name +} \ No newline at end of file diff --git a/quickstart/101-azure-functions/providers.tf b/quickstart/101-azure-functions/providers.tf new file mode 100644 index 00000000..058b6871 --- /dev/null +++ b/quickstart/101-azure-functions/providers.tf @@ -0,0 +1,18 @@ +terraform { + required_version = ">=1.0" + + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~>3.0" + } + random = { + source = "hashicorp/random" + version = "~>3.0" + } + } +} + +provider "azurerm" { + features {} +} \ No newline at end of file diff --git a/quickstart/101-azure-functions/variables.tf b/quickstart/101-azure-functions/variables.tf new file mode 100644 index 00000000..bbaf671b --- /dev/null +++ b/quickstart/101-azure-functions/variables.tf @@ -0,0 +1,42 @@ +variable "resource_group_name_prefix" { + type = string + default = "rg" + description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." +} + +variable "resource_group_location" { + type = string + default = "eastus" + description = "Location of the resource group." +} + +variable "appName" { + type = string + default = "fnapp${random_string.unique_id.result}" + description = "The name of the function app that you wish to create." +} + +variable "storageAccountType" { + type = string + default = "Standard_LRS" + validation { + condition = contains(["Standard_LRS", "Standard_GRS", "Standard_RAGRS"], var.storageAccountType) + error_message = "Must be one of Standard_LRS, Standard_GRS, Standard_RAGRS" + } + description = "Storage Account type" +} + +variable "appInsightsLocation" { + type = string + description = "Location for Application Insights" +} + +variable "runtime" { + type = string + default = "node" + validation { + condition = contains(["node", "dotnet", "java"], var.runtime) + error_message = "Must be one of node, dotnet, java" + } + description = "The language worker runtime to load in the function app." +} \ No newline at end of file From 3ee47f573aa1fdb6904ead4cc2d8b106c83b2006 Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Thu, 31 Oct 2024 19:25:06 -0700 Subject: [PATCH 02/11] Changes to storage --- quickstart/101-azure-functions/main.tf | 28 +++++++++++++-------- quickstart/101-azure-functions/variables.tf | 2 +- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/quickstart/101-azure-functions/main.tf b/quickstart/101-azure-functions/main.tf index dcc6cddf..9e50a36d 100644 --- a/quickstart/101-azure-functions/main.tf +++ b/quickstart/101-azure-functions/main.tf @@ -13,22 +13,28 @@ resource "random_string" "unique_id" { } locals { - functionAppName = var.appName - hostingPlanName = var.appName - applicationInsightsName = var.appName + 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 } -resource "azurerm_storage_account" "storageAccount" { - name = local.storageAccountName - location = azurerm_resource_group.rg.location - resource_group_name = azurerm_resource_group.rg.name - account_tier = "Standard" - account_replication_type = var.storageAccountType +# Generate random value for the storage account name +resource "random_string" "storage_account_name" { + length = 8 + lower = true + numeric = false + special = false + upper = false +} - enable_https_traffic_only = true - allow_blob_public_access = false +resource "azurerm_storage_account" "storageAccount" { + name = random_string.storage_account_name.result + resource_group_name = azurerm_resource_group.rg.name + location = azurerm_resource_group.rg.location + account_tier = "Standard" + account_replication_type = "LRS" } resource "azurerm_app_service_plan" "hostingPlan" { diff --git a/quickstart/101-azure-functions/variables.tf b/quickstart/101-azure-functions/variables.tf index bbaf671b..f1914d8f 100644 --- a/quickstart/101-azure-functions/variables.tf +++ b/quickstart/101-azure-functions/variables.tf @@ -12,7 +12,7 @@ variable "resource_group_location" { variable "appName" { type = string - default = "fnapp${random_string.unique_id.result}" + default = "fnapp" description = "The name of the function app that you wish to create." } From c02b5a12505338c506387a8bed677ad5e17cd1f6 Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Thu, 31 Oct 2024 19:33:38 -0700 Subject: [PATCH 03/11] Changed appinsights location --- quickstart/101-azure-functions/main.tf | 2 +- quickstart/101-azure-functions/variables.tf | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/quickstart/101-azure-functions/main.tf b/quickstart/101-azure-functions/main.tf index 9e50a36d..f4741653 100644 --- a/quickstart/101-azure-functions/main.tf +++ b/quickstart/101-azure-functions/main.tf @@ -82,7 +82,7 @@ resource "azurerm_function_app" "functionApp" { resource "azurerm_application_insights" "applicationInsights" { name = local.applicationInsightsName - location = var.appInsightsLocation + location = var.resource_group_location resource_group_name = azurerm_resource_group.rg.name application_type = "web" } \ No newline at end of file diff --git a/quickstart/101-azure-functions/variables.tf b/quickstart/101-azure-functions/variables.tf index f1914d8f..ca1576b6 100644 --- a/quickstart/101-azure-functions/variables.tf +++ b/quickstart/101-azure-functions/variables.tf @@ -26,11 +26,6 @@ variable "storageAccountType" { description = "Storage Account type" } -variable "appInsightsLocation" { - type = string - description = "Location for Application Insights" -} - variable "runtime" { type = string default = "node" From 966d469033ab68d48b17558655a1200d6de3a09b Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Thu, 31 Oct 2024 19:56:45 -0700 Subject: [PATCH 04/11] Changed app_service_plan to service_plan; updated vars --- quickstart/101-azure-functions/README.md | 7 +++---- quickstart/101-azure-functions/main.tf | 11 ++++------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/quickstart/101-azure-functions/README.md b/quickstart/101-azure-functions/README.md index 836b04fa..3a25d02b 100644 --- a/quickstart/101-azure-functions/README.md +++ b/quickstart/101-azure-functions/README.md @@ -1,4 +1,5 @@ -# Azure Function App +# Azure Functions app + This template deploys an Azure Function App. ## Terraform resource types @@ -7,7 +8,7 @@ This template deploys an Azure Function App. - [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) - [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) - [azurerm_storage_account](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account) -- [azurerm_app_service_plan](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/app_service_plan) +- [azurerm_service_plan](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/service_plan) - [azurerm_function_app](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/function_app) - [azurerm_application_insights](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/application_insights) @@ -18,8 +19,6 @@ This template deploys an Azure Function App. | `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg | | `resource_group_location` | Location of the resource group. | eastus | | `appName` | The name of the function app that you wish to create. | fnapp${random_string.unique_id.result} | -| `storageAccountType` | Storage Account type. Possible values are: Standard_LRS, Standard_GRS, Standard_RAGRS. | Standard_LRS | -| `appInsightsLocation` | Location for Application Insights. | "" | | `runtime` | The language worker runtime to load in the function app. Possible values are: node, dotnet, java. | node | ## Example \ No newline at end of file diff --git a/quickstart/101-azure-functions/main.tf b/quickstart/101-azure-functions/main.tf index f4741653..5dc245a8 100644 --- a/quickstart/101-azure-functions/main.tf +++ b/quickstart/101-azure-functions/main.tf @@ -37,15 +37,12 @@ resource "azurerm_storage_account" "storageAccount" { account_replication_type = "LRS" } -resource "azurerm_app_service_plan" "hostingPlan" { +resource "azurerm_service_plan" "hostingPlan" { name = local.hostingPlanName - location = azurerm_resource_group.rg.location resource_group_name = azurerm_resource_group.rg.name - kind = "FunctionApp" - sku { - tier = "Dynamic" - size = "Y1" - } + location = azurerm_resource_group.rg.location + os_type = "Linux" + sku_name = "P1v2" } resource "azurerm_function_app" "functionApp" { From 53b548c81b775a89a0b0c61d2a68d0af81549cbc Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Thu, 31 Oct 2024 20:16:36 -0700 Subject: [PATCH 05/11] 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" { From 19fb9b1d527185a21d3532b5694bcccf21845acd Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Fri, 1 Nov 2024 08:25:36 -0700 Subject: [PATCH 06/11] trying diff technique --- quickstart/101-azure-functions/main.tf | 93 +++++---------------- quickstart/101-azure-functions/outputs.tf | 19 ----- quickstart/101-azure-functions/variables.tf | 61 +++++++------- 3 files changed, 55 insertions(+), 118 deletions(-) diff --git a/quickstart/101-azure-functions/main.tf b/quickstart/101-azure-functions/main.tf index eb502418..8ccf27b5 100644 --- a/quickstart/101-azure-functions/main.tf +++ b/quickstart/101-azure-functions/main.tf @@ -1,79 +1,32 @@ -resource "random_pet" "rg_name" { - prefix = var.resource_group_name_prefix +resource "azurerm_resource_group" "az_rg" { + name = var.az_rg_name + location = var.location } -resource "azurerm_resource_group" "rg" { - location = var.resource_group_location - name = random_pet.rg_name.id +resource "azurerm_storage_account" "az_sa" { + name = var.az_sa_name + resource_group_name = azurerm_resource_group.az_rg.name + location = azurerm_resource_group.az_rg.location + account_tier = var.az_sa_account_tier + account_replication_type = var.az_sa_account_replication_type } -resource "random_string" "unique_id" { - length = 8 - lower = true - numeric = false - special = false - upper = false -} +resource "azurerm_app_service_plan" "az_asp" { + name = var.az_asp_name + location = azurerm_resource_group.az_rg.location + resource_group_name = azurerm_resource_group.az_rg.name -resource "azurerm_storage_account" "storageAccount" { - name = random_string.unique_id.result - resource_group_name = azurerm_resource_group.rg.name - location = azurerm_resource_group.rg.location - account_tier = "Standard" - account_replication_type = "LRS" -} - -resource "azurerm_service_plan" "hostingPlan" { - 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_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 - 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 - - identity { - type = "SystemAssigned" - } - - site_config { - application_stack { - python_version = "3.9" - } + sku { + tier = var.az_asp_sku_tier + size = "S1" } } -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" - }, - ] - }) +resource "azurerm_function_app" "az_fa" { + name = var.az_fa_name + location = azurerm_resource_group.az_rg.location + resource_group_name = azurerm_resource_group.az_rg.name + app_service_plan_id = azurerm_app_service_plan.az_asp.id + storage_account_name = azurerm_storage_account.az_sa.name + storage_account_access_key = azurerm_storage_account.az_sa.primary_access_key } diff --git a/quickstart/101-azure-functions/outputs.tf b/quickstart/101-azure-functions/outputs.tf index eb0bc817..e69de29b 100644 --- a/quickstart/101-azure-functions/outputs.tf +++ b/quickstart/101-azure-functions/outputs.tf @@ -1,19 +0,0 @@ -output "resource_group_name" { - value = azurerm_resource_group.rg.name -} - -output "storage_account_name" { - value = azurerm_storage_account.storageAccount.name -} - -output "app_service_plan_name" { - value = azurerm_service_plan.hostingPlan.name -} - -output "function_app_name" { - value = azurerm_function_app.functionApp.name -} - -output "application_insights_name" { - value = azurerm_application_insights.applicationInsights.name -} \ No newline at end of file diff --git a/quickstart/101-azure-functions/variables.tf b/quickstart/101-azure-functions/variables.tf index ca1576b6..0df68e2a 100644 --- a/quickstart/101-azure-functions/variables.tf +++ b/quickstart/101-azure-functions/variables.tf @@ -1,37 +1,40 @@ -variable "resource_group_name_prefix" { - type = string - default = "rg" - description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." +variable "az_rg_name" { + type = string + default = "azure-functions-example-rg" } -variable "resource_group_location" { - type = string - default = "eastus" - description = "Location of the resource group." +variable "location" { + type = string + default = "East US" } -variable "appName" { - type = string - default = "fnapp" - description = "The name of the function app that you wish to create." +variable "az_sa_account_tier" { + type = string + default = "Standard" } -variable "storageAccountType" { - type = string - default = "Standard_LRS" - validation { - condition = contains(["Standard_LRS", "Standard_GRS", "Standard_RAGRS"], var.storageAccountType) - error_message = "Must be one of Standard_LRS, Standard_GRS, Standard_RAGRS" - } - description = "Storage Account type" +variable "az_sa_account_replication_type" { + type = string + default = "LRS" +} + +variable "az_sa_name" { + type = string + default = "examplefunctionssa" +} + +variable "az_asp_name" { + type = string + default = "example-functions-service-plan" +} + +variable "az_asp_sku_tier" { + type = string + default = "Standard" +} + +variable "az_fa_name" { + type = string + default = "example-functions-app" } -variable "runtime" { - type = string - default = "node" - validation { - condition = contains(["node", "dotnet", "java"], var.runtime) - error_message = "Must be one of node, dotnet, java" - } - description = "The language worker runtime to load in the function app." -} \ No newline at end of file From a75d5d0f916ada47495882ede295fb55a2fab6d1 Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Fri, 1 Nov 2024 09:13:01 -0700 Subject: [PATCH 07/11] cleaning up --- quickstart/101-azure-functions/README.md | 9 ++- quickstart/101-azure-functions/main.tf | 54 +++++++++++------- quickstart/101-azure-functions/variables.tf | 61 +++++++++++++-------- 3 files changed, 76 insertions(+), 48 deletions(-) diff --git a/quickstart/101-azure-functions/README.md b/quickstart/101-azure-functions/README.md index 3a25d02b..2b7b8b4f 100644 --- a/quickstart/101-azure-functions/README.md +++ b/quickstart/101-azure-functions/README.md @@ -10,7 +10,6 @@ This template deploys an Azure Function App. - [azurerm_storage_account](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account) - [azurerm_service_plan](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/service_plan) - [azurerm_function_app](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/function_app) -- [azurerm_application_insights](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/application_insights) ## Variables @@ -18,7 +17,11 @@ This template deploys an Azure Function App. |-|-|-| | `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg | | `resource_group_location` | Location of the resource group. | eastus | -| `appName` | The name of the function app that you wish to create. | fnapp${random_string.unique_id.result} | -| `runtime` | The language worker runtime to load in the function app. Possible values are: node, dotnet, java. | node | +| `sa_account_tier` | The tier of the storage account. Possible values are Standard and Premium. | "Standard" | +| `sa_account_replication_type` | The replication type of the storage account. Possible values are LRS, GRS, RAGRS, and ZRS. | "LRS" | +| `sa_name` | The name of the storage account. | Randomly generated | +| `asp_name` | The name of the App Service Plan. | Randomly generated | +| `asp_sku_tier` | The SKU tier of the App Service Plan. Possible values are Free, Shared, Basic, Standard, Premium, PremiumV2, and PremiumV3. | "Standard" | +| `fa_name` | The name of the Function App." | Randomly generated | ## Example \ No newline at end of file diff --git a/quickstart/101-azure-functions/main.tf b/quickstart/101-azure-functions/main.tf index 8ccf27b5..ff9f9dc2 100644 --- a/quickstart/101-azure-functions/main.tf +++ b/quickstart/101-azure-functions/main.tf @@ -1,32 +1,44 @@ -resource "azurerm_resource_group" "az_rg" { - name = var.az_rg_name - location = var.location +resource "random_pet" "rg_name" { + prefix = var.resource_group_name_prefix } -resource "azurerm_storage_account" "az_sa" { - name = var.az_sa_name - resource_group_name = azurerm_resource_group.az_rg.name - location = azurerm_resource_group.az_rg.location - account_tier = var.az_sa_account_tier - account_replication_type = var.az_sa_account_replication_type +resource "azurerm_resource_group" "rg" { + location = var.resource_group_location + name = coalesce(var.resource_group_name, random_pet.rg_name.id) } -resource "azurerm_app_service_plan" "az_asp" { - name = var.az_asp_name - location = azurerm_resource_group.az_rg.location - resource_group_name = azurerm_resource_group.az_rg.name +resource "random_string" "name" { + length = 13 + lower = true + numeric = false + special = false + upper = false +} + +resource "azurerm_storage_account" "example" { + name = coalesce(var.sa_name, "sa${random_string.name.result}") + resource_group_name = azurerm_resource_group.rg.name + location = azurerm_resource_group.rg.location + account_tier = var.sa_account_tier + account_replication_type = var.sa_account_replication_type +} + +resource "azurerm_app_service_plan" "example" { + name = coalesce(var.asp_name, "sp${random_string.name.result}") + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name sku { - tier = var.az_asp_sku_tier + tier = var.asp_sku_tier size = "S1" } } -resource "azurerm_function_app" "az_fa" { - name = var.az_fa_name - location = azurerm_resource_group.az_rg.location - resource_group_name = azurerm_resource_group.az_rg.name - app_service_plan_id = azurerm_app_service_plan.az_asp.id - storage_account_name = azurerm_storage_account.az_sa.name - storage_account_access_key = azurerm_storage_account.az_sa.primary_access_key +resource "azurerm_function_app" "example" { + name = coalesce(var.fa_name, "fa${random_string.name.result}") + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + app_service_plan_id = azurerm_app_service_plan.example.id + storage_account_name = azurerm_storage_account.example.name + storage_account_access_key = azurerm_storage_account.example.primary_access_key } diff --git a/quickstart/101-azure-functions/variables.tf b/quickstart/101-azure-functions/variables.tf index 0df68e2a..f8988b22 100644 --- a/quickstart/101-azure-functions/variables.tf +++ b/quickstart/101-azure-functions/variables.tf @@ -1,40 +1,53 @@ -variable "az_rg_name" { - type = string - default = "azure-functions-example-rg" +variable "resource_group_name" { + type = string + default = "" + description = "The name of the Azure resource group. If blank, a random name will be generated." } -variable "location" { - type = string - default = "East US" +variable "resource_group_name_prefix" { + type = string + default = "rg" + description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." } -variable "az_sa_account_tier" { - type = string - default = "Standard" +variable "resource_group_location" { + type = string + default = "eastus" + description = "Location of the resource group." } -variable "az_sa_account_replication_type" { - type = string - default = "LRS" +variable "sa_account_tier" { + description = "The tier of the storage account. Possible values are Standard and Premium." + type = string + default = "Standard" } -variable "az_sa_name" { - type = string - default = "examplefunctionssa" +variable "sa_account_replication_type" { + description = "The replication type of the storage account. Possible values are LRS, GRS, RAGRS, and ZRS." + type = string + default = "LRS" } -variable "az_asp_name" { - type = string - default = "example-functions-service-plan" +variable "sa_name" { + description = "The name of the storage account. If blank, a random name will be generated." + type = string + default = "" } -variable "az_asp_sku_tier" { - type = string - default = "Standard" +variable "asp_name" { + description = "The name of the App Service Plan. If blank, a random name will be generated." + type = string + default = "" } -variable "az_fa_name" { - type = string - default = "example-functions-app" +variable "asp_sku_tier" { + description = "The SKU tier of the App Service Plan. Possible values are Free, Shared, Basic, Standard, Premium, PremiumV2, and PremiumV3." + type = string + default = "Standard" } +variable "fa_name" { + description = "The name of the Function App. If blank, a random name will be generated." + type = string + default = "" +} \ No newline at end of file From b73933a978810fc39d4f0ef45cefa815b10d4454 Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Fri, 1 Nov 2024 10:58:20 -0700 Subject: [PATCH 08/11] changing region; adding outputs --- quickstart/101-azure-functions/outputs.tf | 47 +++++++++++++++++++++ quickstart/101-azure-functions/variables.tf | 2 +- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/quickstart/101-azure-functions/outputs.tf b/quickstart/101-azure-functions/outputs.tf index e69de29b..8e8ca2e1 100644 --- a/quickstart/101-azure-functions/outputs.tf +++ b/quickstart/101-azure-functions/outputs.tf @@ -0,0 +1,47 @@ +output "resource_group_name" { + value = azurerm_resource_group.rg.name +} + +output "sa_name" { + value = azurerm_storage_account.example.name +} + +output "asp_name" { + value = azurerm_app_service_plan.example.name +} + +output "fa_name" { + value = azurerm_function_app.example.name +} + +output "sa_primary_access_key" { + value = azurerm_storage_account.example.primary_access_key +} + +output "sa_primary_connection_string" { + value = azurerm_storage_account.example.primary_connection_string +} + +output "sa_secondary_access_key" { + value = azurerm_storage_account.example.secondary_access_key +} + +output "sa_secondary_connection_string" { + value = azurerm_storage_account.example.secondary_connection_string +} + +output "asp_id" { + value = azurerm_app_service_plan.example.id +} + +output "fa_id" { + value = azurerm_function_app.example.id +} + +output "fa_default_hostname" { + value = azurerm_function_app.example.default_hostname +} + +output "fa_outbound_ip_addresses" { + value = azurerm_function_app.example.outbound_ip_addresses +} diff --git a/quickstart/101-azure-functions/variables.tf b/quickstart/101-azure-functions/variables.tf index f8988b22..9bb24798 100644 --- a/quickstart/101-azure-functions/variables.tf +++ b/quickstart/101-azure-functions/variables.tf @@ -12,7 +12,7 @@ variable "resource_group_name_prefix" { variable "resource_group_location" { type = string - default = "eastus" + default = "westus" description = "Location of the resource group." } From da94aaabca03cc6d2fb00f51d71e043b06cb4db3 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 4 Nov 2024 05:56:07 +0000 Subject: [PATCH 09/11] fix quota issue --- quickstart/101-azure-functions/main.tf | 2 +- quickstart/101-azure-functions/outputs.tf | 12 ++++++++---- quickstart/101-azure-functions/variables.tf | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/quickstart/101-azure-functions/main.tf b/quickstart/101-azure-functions/main.tf index ff9f9dc2..09eb3f32 100644 --- a/quickstart/101-azure-functions/main.tf +++ b/quickstart/101-azure-functions/main.tf @@ -30,7 +30,7 @@ resource "azurerm_app_service_plan" "example" { sku { tier = var.asp_sku_tier - size = "S1" + size = "P0V3" } } diff --git a/quickstart/101-azure-functions/outputs.tf b/quickstart/101-azure-functions/outputs.tf index 8e8ca2e1..06db90a0 100644 --- a/quickstart/101-azure-functions/outputs.tf +++ b/quickstart/101-azure-functions/outputs.tf @@ -15,19 +15,23 @@ output "fa_name" { } output "sa_primary_access_key" { - value = azurerm_storage_account.example.primary_access_key + value = azurerm_storage_account.example.primary_access_key + sensitive = true } output "sa_primary_connection_string" { - value = azurerm_storage_account.example.primary_connection_string + value = azurerm_storage_account.example.primary_connection_string + sensitive = true } output "sa_secondary_access_key" { - value = azurerm_storage_account.example.secondary_access_key + value = azurerm_storage_account.example.secondary_access_key + sensitive = true } output "sa_secondary_connection_string" { - value = azurerm_storage_account.example.secondary_connection_string + value = azurerm_storage_account.example.secondary_connection_string + sensitive = true } output "asp_id" { diff --git a/quickstart/101-azure-functions/variables.tf b/quickstart/101-azure-functions/variables.tf index 9bb24798..c19b6072 100644 --- a/quickstart/101-azure-functions/variables.tf +++ b/quickstart/101-azure-functions/variables.tf @@ -12,14 +12,14 @@ variable "resource_group_name_prefix" { variable "resource_group_location" { type = string - default = "westus" + default = "westeurope" description = "Location of the resource group." } variable "sa_account_tier" { description = "The tier of the storage account. Possible values are Standard and Premium." type = string - default = "Standard" + default = "Premium" } variable "sa_account_replication_type" { From d0a185d05197b228f58f260619bff86c6779a8d8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 4 Nov 2024 06:10:18 +0000 Subject: [PATCH 10/11] make config idempotent --- quickstart/101-azure-functions/main.tf | 2 +- quickstart/101-azure-functions/variables.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/quickstart/101-azure-functions/main.tf b/quickstart/101-azure-functions/main.tf index 09eb3f32..2da9227e 100644 --- a/quickstart/101-azure-functions/main.tf +++ b/quickstart/101-azure-functions/main.tf @@ -30,7 +30,7 @@ resource "azurerm_app_service_plan" "example" { sku { tier = var.asp_sku_tier - size = "P0V3" + size = "P0v3" } } diff --git a/quickstart/101-azure-functions/variables.tf b/quickstart/101-azure-functions/variables.tf index c19b6072..7749d76f 100644 --- a/quickstart/101-azure-functions/variables.tf +++ b/quickstart/101-azure-functions/variables.tf @@ -43,7 +43,7 @@ variable "asp_name" { variable "asp_sku_tier" { description = "The SKU tier of the App Service Plan. Possible values are Free, Shared, Basic, Standard, Premium, PremiumV2, and PremiumV3." type = string - default = "Standard" + default = "Premium0V3" } variable "fa_name" { From 32aaf3ff00678f05598fc141822fc4d88b0f50a7 Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Tue, 5 Nov 2024 14:55:44 -0800 Subject: [PATCH 11/11] updated readme & test endpoint --- quickstart/101-azure-functions/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/quickstart/101-azure-functions/README.md b/quickstart/101-azure-functions/README.md index 2b7b8b4f..6e5749bf 100644 --- a/quickstart/101-azure-functions/README.md +++ b/quickstart/101-azure-functions/README.md @@ -16,12 +16,12 @@ This template deploys an Azure Function App. | Name | Description | Default value | |-|-|-| | `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg | -| `resource_group_location` | Location of the resource group. | eastus | -| `sa_account_tier` | The tier of the storage account. Possible values are Standard and Premium. | "Standard" | +| `resource_group_location` | Location of the resource group. | westeurope | +| `sa_account_tier` | The tier of the storage account. Possible values are Standard and Premium. | "Premium" | | `sa_account_replication_type` | The replication type of the storage account. Possible values are LRS, GRS, RAGRS, and ZRS. | "LRS" | | `sa_name` | The name of the storage account. | Randomly generated | | `asp_name` | The name of the App Service Plan. | Randomly generated | -| `asp_sku_tier` | The SKU tier of the App Service Plan. Possible values are Free, Shared, Basic, Standard, Premium, PremiumV2, and PremiumV3. | "Standard" | +| `asp_sku_tier` | The SKU tier of the App Service Plan. Possible values are Free, Shared, Basic, Standard, Premium, PremiumV2, and PremiumV3. | "Premium0V3" | | `fa_name` | The name of the Function App." | Randomly generated | ## Example \ No newline at end of file