### Example ARM Parameters File Source: https://github.com/azure-samples/azure-functions-flex-consumption-samples/blob/main/IaC/armtemplate/README.md This JSON file defines the parameters for deploying the Azure Functions Flex Consumption plan. Modify values for location, names, and runtime before deployment. ```json { "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", "contentVersion": "1.0.0.0", "parameters": { "location": { "value": "eastasia" }, "functionPlanName": { "value": "fcthiarmplan" }, "functionAppName": { "value": "fcthiarmapp" }, "functionAppRuntime": { "value": "dotnet-isolated" }, "functionAppRuntimeVersion": { "value": "8.0" }, "storageAccountName": { "value": "fcthiarmstor" }, "logAnalyticsName": { "value": "fcthiarmlog" }, "applicationInsightsName": { "value": "fcthiarmai" }, "zoneRedundant": { "value": false } } } ``` -------------------------------- ### Example variables.tfvars for Flex Consumption Plan Source: https://github.com/azure-samples/azure-functions-flex-consumption-samples/blob/main/IaC/terraformazurerm/README.md This is an example of a variables.tfvars file that you need to modify with your specific parameter values before deploying the Terraform configuration. ```terraform subscriptionId = "00000000-0000-0000-0000-000000000000" resourceGroupName = "fcthitf" location = "eastasia" applicationInsightsName = "fcthitfai" functionAppName = "fcthitfapp" functionPlanName = "fcthitfplan" logAnalyticsName = "fcthitflog" storageAccountName = "fcthitfstor" functionAppRuntime = "dotnet-isolated" functionAppRuntimeVersion = "9.0" zoneRedundant = false ``` -------------------------------- ### Terraform AzAPI Provider Deployment Steps Source: https://context7.com/azure-samples/azure-functions-flex-consumption-samples/llms.txt This sequence of commands initializes, plans, and applies a Terraform configuration using the `azure/azapi` provider. It requires a variables file to be created first. ```bash # 1. Create a variables file (variablescopy.tfvars) cat > variablescopy.tfvars <<'EOF' subscriptionId = "00000000-0000-0000-0000-000000000000" resourceGroupName = "fcthitf" location = "eastasia" applicationInsightsName = "fcthitfai" functionAppName = "fcthitfapp" functionPlanName = "fcthitfplan" logAnalyticsName = "fcthitflog" storageAccountName = "fcthitfstor" functionAppRuntime = "dotnet-isolated" functionAppRuntimeVersion = "9.0" zoneRedundant = false EOF # 2. Initialize, plan, and apply cd IaC/terraformazapi terraform init -upgrade terraform plan -var-file="variablescopy.tfvars" -out main.tfplan terraform apply main.tfplan # Resources created: # azurerm_resource_group # azapi_resource (serverfarm — FC1/FlexConsumption) # azurerm_storage_account (shared key disabled) # azurerm_storage_container (deploymentpackage, private) # azurerm_log_analytics_workspace (30-day retention, PerGB2018) # azurerm_application_insights # azapi_resource (functionapp,linux — SystemAssigned identity) # azurerm_role_assignment (Storage Blob Data Owner → managed identity) ``` -------------------------------- ### Terraform Deployment Steps for Azure Functions Flex Consumption Source: https://context7.com/azure-samples/azure-functions-flex-consumption-samples/llms.txt Steps to initialize, plan, and apply Terraform configurations for deploying Azure Functions Flex Consumption. A variables file is created first. ```bash # 1. Create a variables file cat > variablescopy.tfvars <<'EOF' subscriptionId = "00000000-0000-0000-0000-000000000000" resourceGroupName = "fcthitfrm" location = "eastus2" applicationInsightsName = "fcthitfrmai" functionAppName = "fcthitfrmapp" functionPlanName = "fcthitfrmplan" logAnalyticsName = "fcthitfrmlog" storageAccountName = "fcthitfrmstor" functionAppRuntime = "python" functionAppRuntimeVersion = "3.11" zoneRedundant = false EOF # 2. Deploy cd IaC/terraformazurerm terraform init -upgrade terraform plan -var-file="variablescopy.tfvars" -out main.tfplan terraform apply main.tfplan ``` -------------------------------- ### Terraform CLI Deployment Commands Source: https://github.com/azure-samples/azure-functions-flex-consumption-samples/blob/main/IaC/terraformazurerm/README.md These commands demonstrate how to initialize Terraform, create a plan based on your variable file, and apply the plan to deploy the Azure resources. ```bash terraform init -upgrade terraform plan -var-file="variablescopy.tfvars" -out main.tfplan terraform apply main.tfplan ``` -------------------------------- ### Deploy Bicep Template (Minimal Parameters) Source: https://github.com/azure-samples/azure-functions-flex-consumption-samples/blob/main/IaC/bicep/README.md Deploy the Bicep template to your Azure subscription with minimal required parameters. This is useful for initial testing in a specific region. ```bash az deployment sub create \ --template-file main.bicep \ --parameters environmentName=test-env location=eastus2 \ --location eastus2 \ --name flexconsumption-test ``` -------------------------------- ### Deploy Bicep Template (with User Access) Source: https://github.com/azure-samples/azure-functions-flex-consumption-samples/blob/main/IaC/bicep/README.md Deploy the Bicep template and grant the deploying user access to Storage and App Insights resources. This requires fetching the user's principal ID. ```bash az deployment sub create \ --template-file main.bicep \ --parameters environmentName=test-env location=eastus2 \ --parameters principalId=$(az ad signed-in-user show --query id -o tsv) \ --location eastus2 \ --name flexconsumption-test ``` -------------------------------- ### Deploy Bicep Template (Development/Testing) Source: https://context7.com/azure-samples/azure-functions-flex-consumption-samples/llms.txt Deploy the Bicep template with user access granted to Storage and App Insights. This is suitable for development and testing scenarios. ```bash az deployment sub create \ --template-file IaC/bicep/main.bicep \ --parameters environmentName=myapp location=eastus2 \ --parameters principalId=$(az ad signed-in-user show --query id -o tsv) \ --location eastus2 \ --name flexconsumption-dev ``` -------------------------------- ### Deploy Bicep Template (Production) Source: https://context7.com/azure-samples/azure-functions-flex-consumption-samples/llms.txt Deploy the Bicep template for a production environment. This minimal deployment does not grant user access to Storage or App Insights. ```bash az deployment sub create \ --template-file IaC/bicep/main.bicep \ --parameters environmentName=myapp location=eastus2 \ --location eastus2 \ --name flexconsumption-prod ``` -------------------------------- ### Deploy Flex Consumption Function App with ARM Template Source: https://context7.com/azure-samples/azure-functions-flex-consumption-samples/llms.txt Deploys Azure Functions resources using an ARM template. Requires a parameters file for configuration. Creates a Function App with system-assigned identity and role assignments for storage access. ```bash # 1. Create a parameters file (azuredeploycopy.parameters.json) for a .NET Isolated 8.0 app cat > azuredeploycopy.parameters.json <<'EOF' { "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", "contentVersion": "1.0.0.0", "parameters": { "location": { "value": "eastasia" }, "functionPlanName": { "value": "fcthiarmplan" }, "functionAppName": { "value": "fcthiarmapp" }, "functionAppRuntime": { "value": "dotnet-isolated" }, "functionAppRuntimeVersion": { "value": "8.0" }, "storageAccountName": { "value": "fcthiarmstor" }, "logAnalyticsName": { "value": "fcthiarmlog" }, "applicationInsightsName": { "value": "fcthiarmai" }, "zoneRedundant": { "value": false } } } EOF # 2. Create the resource group az group create --location eastus --resource-group fcarm # 3. Deploy the ARM template az deployment group create \ --resource-group fcarm \ --template-file IaC/armtemplate/azuredeploy.json \ --parameters azuredeploycopy.parameters.json # Expected output: provisioningState: Succeeded # Resources created: Log Analytics Workspace, Application Insights, # Storage Account + blob container, App Service Plan (FC1), # Function App (linux, systemAssigned identity), Role Assignment ``` -------------------------------- ### Preview Bicep Template Changes Source: https://github.com/azure-samples/azure-functions-flex-consumption-samples/blob/main/IaC/bicep/README.md Use this command to preview the changes that will be made to your Azure resources before applying them. This helps in understanding the impact of the deployment. ```bash az deployment sub what-if \ --template-file main.bicep \ --parameters environmentName=test-env location=eastus2 \ --location eastus2 ``` -------------------------------- ### Azure.yaml Hooks for Script Execution Source: https://github.com/azure-samples/azure-functions-flex-consumption-samples/blob/main/IaC/scripts/README.md Configure `azure.yaml` to run deployment scripts after provisioning. Supports both Windows (PowerShell) and POSIX (Bash) environments, with options for interactive execution and error handling. ```yaml # yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json name: my-template metadata: template: my-template@0.0.4-beta hooks: postprovision: windows: shell: pwsh run: cd ./src;../scripts/deploy.ps1 interactive: true continueOnError: false posix: shell: sh run: cd ./src;../scripts/deploy.sh interactive: true continueOnError: false ``` -------------------------------- ### Azure CLI Deployment Commands Source: https://github.com/azure-samples/azure-functions-flex-consumption-samples/blob/main/IaC/armtemplate/README.md These Azure CLI commands create a resource group and deploy the ARM template using the specified parameters file. Ensure you have an 'azuredeploy.json' template and a modified parameters file. ```bash az group create --location eastus --resource-group fcarm az deployment group create --resource-group fcarm --template-file azuredeploy.json --parameters azuredeploycopy.parameters.json ``` -------------------------------- ### List Flex Consumption Supported Regions Source: https://github.com/azure-samples/azure-functions-flex-consumption-samples/blob/main/IaC/bicep/README.md This command lists the Azure regions that support the Flex Consumption plan for Azure Functions. Ensure your deployment target region is in this list. ```bash az functionapp list-flexconsumption-locations ``` -------------------------------- ### ARM Template Key Parameters for Flex Consumption Function App Source: https://context7.com/azure-samples/azure-functions-flex-consumption-samples/llms.txt Defines configurable parameters for an ARM template deploying a Flex Consumption Function App. Includes options for runtime, instance memory, maximum instances, and zone redundancy. ```json { "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "functionAppRuntime": { "type": "string", "allowedValues": ["dotnet-isolated", "python", "java", "node", "powerShell", "custom"], "defaultValue": "dotnet-isolated" }, "functionAppRuntimeVersion": { "type": "string", "defaultValue": "10.0", "metadata": { "description": "Supported: '3.10','3.11','7.4','8.0','9.0','10','11','17','20','21','22'. Use '1.0' for custom." } }, "maximumInstanceCount": { "type": "int", "defaultValue": 100 }, "instanceMemoryMB": { "type": "int", "allowedValues": [512, 2048, 4096], "defaultValue": 2048 }, "zoneRedundant": { "type": "bool", "defaultValue": false } } } ``` -------------------------------- ### Publish Azure Function App (Bash) Source: https://context7.com/azure-samples/azure-functions-flex-consumption-samples/llms.txt This script publishes a .NET isolated Azure Function app using Azure Functions Core Tools. It first loads environment variables from 'azd env get-values' and then executes the publish command. ```bash # IaC/scripts/deploy.sh — run standalone (bash) # Pre-requisites: az CLI, func (Azure Functions Core Tools), azd # Load azd environment variables into shell output=$(azd env get-values) while IFS= read -r line; do name=$(echo $line | cut -d'=' -f1) value=$(echo $line | cut -d'=' -f2 | sed 's/^"|"$//g') export $name=$value done <<<$output # Publish the function app (dotnet-isolated example) func azure functionapp publish $AZURE_FUNCTION_NAME --dotnet-isolated # Output: Deployment completed. ``` -------------------------------- ### AZD Hook Configuration for Post-Provision Deployment Source: https://context7.com/azure-samples/azure-functions-flex-consumption-samples/llms.txt Configures Azure Developer CLI (AZD) to run deployment scripts after infrastructure provisioning. Specifies shell and script path for both Windows and POSIX systems. ```yaml # azure.yaml — hook configuration to trigger post-provision deployment # yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json name: my-flex-app metadata: template: my-flex-app@0.0.4-beta hooks: postprovision: windows: shell: pwsh run: cd ./src;../scripts/deploy.ps1 interactive: true continueOnError: false posix: shell: sh run: cd ./src;../scripts/deploy.sh interactive: true continueOnError: false ``` -------------------------------- ### Validate Bicep Template Syntax Source: https://context7.com/azure-samples/azure-functions-flex-consumption-samples/llms.txt Use this command to validate the Bicep template syntax without creating any resources. Ensure your template is well-formed before proceeding to deployment. ```bash az deployment sub validate \ --template-file IaC/bicep/main.bicep \ --parameters environmentName=myapp location=eastus2 \ --location eastus2 ``` -------------------------------- ### Rebase and Force Push for PR Updates Source: https://github.com/azure-samples/azure-functions-flex-consumption-samples/blob/main/CONTRIBUTING.md Use this command to update your pull request after making changes. Ensure you rebase your local branch onto the master branch and then force push to your GitHub repository. ```shell git rebase master -i git push -f ``` -------------------------------- ### Publish Azure Function App (PowerShell) Source: https://context7.com/azure-samples/azure-functions-flex-consumption-samples/llms.txt This PowerShell script publishes a .NET isolated Azure Function app. It retrieves environment variables using 'azd env get-values', sets them in the PowerShell environment, and then publishes the function app. ```powershell # IaC/scripts/deploy.ps1 — run standalone (PowerShell) $output = azd env get-values foreach ($line in $output) { if (!($line)) { break } $name = $line.Split('=')[0] $value = $line.Split('=')[1].Trim('"') Set-Item -Path "env:\$name" -Value $value } func azure functionapp publish $env:AZURE_FUNCTION_NAME --dotnet-isolated # Output: Deployment completed. ``` -------------------------------- ### Bicep Function App Module Configuration Source: https://context7.com/azure-samples/azure-functions-flex-consumption-samples/llms.txt This Bicep code configures a function app module, specifying deployment storage, scaling, runtime, and managed identity credentials. It ensures secure and efficient operation. ```bicep // IaC/bicep/main.bicep (excerpt — function app module) module functionApp 'br/public:avm/res/web/site:0.16.0' = { name: 'functionapp' scope: rg params: { kind: 'functionapp,linux' name: functionAppName_resolved // auto-generated or overridden via param location: location serverFarmResourceId: appServicePlan.outputs.resourceId managedIdentities: { systemAssigned: true } functionAppConfig: { deployment: { storage: { type: 'blobContainer' value: '${storage.outputs.primaryBlobEndpoint}${deploymentStorageContainerName}' authentication: { type: 'SystemAssignedIdentity' } } } scaleAndConcurrency: { maximumInstanceCount: maximumInstanceCount // default 100, range 40–1000 instanceMemoryMB: instanceMemoryMB // 512 | 2048 | 4096 } runtime: { name: functionAppRuntime // e.g. 'python' version: functionAppRuntimeVersion // e.g. '3.11' } } configs: [{ name: 'appsettings' properties: { AzureWebJobsStorage__credential: 'managedidentity' AzureWebJobsStorage__blobServiceUri: 'https://${storage.outputs.name}.blob.${environment().suffixes.storage}' AzureWebJobsStorage__queueServiceUri: 'https://${storage.outputs.name}.queue.${environment().suffixes.storage}' AzureWebJobsStorage__tableServiceUri: 'https://${storage.outputs.name}.table.${environment().suffixes.storage}' APPLICATIONINSIGHTS_CONNECTION_STRING: applicationInsights.outputs.connectionString APPLICATIONINSIGHTS_AUTHENTICATION_STRING: 'Authorization=AAD' } }] } } ``` -------------------------------- ### Validate Bicep Template Source: https://github.com/azure-samples/azure-functions-flex-consumption-samples/blob/main/IaC/bicep/README.md Use this command to validate your Bicep template before deployment. It checks for syntax errors and ensures the template is well-formed. ```bash az deployment sub validate \ --template-file main.bicep \ --parameters environmentName=test-env location=eastus2 \ --location eastus2 ``` -------------------------------- ### Terraform Resource for Azure Functions Flex Consumption Source: https://context7.com/azure-samples/azure-functions-flex-consumption-samples/llms.txt Configures the `azurerm_function_app_flex_consumption` resource, specifying runtime, storage, identity, and application settings. Managed identity is used for storage authentication. ```hcl # IaC/terraformazurerm/main.tf (key resource excerpt) resource "azurerm_function_app_flex_consumption" "functionApps" { name = var.functionAppName resource_group_name = azurerm_resource_group.rg.name location = var.location service_plan_id = azurerm_service_plan.example.id # Deployment package stored in blob container via managed identity storage_container_type = "blobContainer" storage_container_endpoint = "${azurerm_storage_account.storageAccount.primary_blob_endpoint}deploymentpackage" storage_authentication_type = "SystemAssignedIdentity" runtime_name = var.functionAppRuntime # e.g. "python" runtime_version = var.functionAppRuntimeVersion # e.g. "3.11" maximum_instance_count = var.maximumInstanceCount # default 100 instance_memory_in_mb = var.instanceMemoryMB # default 2048 identity { type = "SystemAssigned" } site_config { application_insights_connection_string = azurerm_application_insights.appInsights.connection_string } app_settings = { "AzureWebJobsStorage__accountName" = azurerm_storage_account.storageAccount.name } } resource "azurerm_role_assignment" "storage_roleassignment" { scope = azurerm_storage_account.storageAccount.id role_definition_name = "Storage Blob Data Owner" principal_id = azurerm_function_app_flex_consumption.functionApps.identity.0.principal_id principal_type = "ServicePrincipal" } ``` -------------------------------- ### Bicep RBAC Module for Managed Identity Role Assignments Source: https://context7.com/azure-samples/azure-functions-flex-consumption-samples/llms.txt This Bicep module assigns least-privilege roles to a function app's system-assigned managed identity for Storage and Application Insights. It can optionally grant roles to a user principal for local development. ```bicep // IaC/bicep/rbac.bicep (called from main.bicep as module rbacAssignments) // Parameters param storageAccountName string param appInsightsName string param managedIdentityPrincipalId string param userIdentityPrincipalId string = '' param allowUserIdentityPrincipal bool = false // Role Definition IDs (Azure built-in) var roleDefinitions = { storageBlobDataOwner: 'b7e6dc6d-f1e8-4753-8033-0f276bb0955b' storageQueueDataContributor: '974c5e8b-45b9-4653-ba55-5f855dd0fb88' storageTableDataContributor: '0a9a7e1f-b9d0-4cc4-a60d-0319b160aaa3' monitoringMetricsPublisher: '3913510d-42f4-4e42-8a64-420c390055eb' } // Example: Blob Data Owner for system-assigned managed identity module storageRoleAssignment 'br/public:avm/ptn/authorization/resource-role-assignment:0.1.2' = if (!empty(managedIdentityPrincipalId)) { name: 'storageRoleAssignment-${uniqueString(storageAccount.id, managedIdentityPrincipalId)}' params: { resourceId: storageAccount.id roleDefinitionId: roleDefinitions.storageBlobDataOwner principalId: managedIdentityPrincipalId principalType: 'ServicePrincipal' roleName: 'Storage Blob Data Owner' } } // Called from main.bicep: // module rbacAssignments 'rbac.bicep' = { // name: 'rbacAssignments' // scope: rg // params: { // storageAccountName: storage.outputs.name // appInsightsName: applicationInsights.outputs.name // managedIdentityPrincipalId: functionApp.outputs.?systemAssignedMIPrincipalId ?? '' // userIdentityPrincipalId: principalId // allowUserIdentityPrincipal: !empty(principalId) // } // } ``` -------------------------------- ### Terraform Variables for Azure Functions Flex Consumption Source: https://context7.com/azure-samples/azure-functions-flex-consumption-samples/llms.txt Defines input variables for Terraform to configure Azure Functions Flex Consumption resources. Ensure values like location are valid for your Azure region. ```hcl variable "subscriptionId" { description = "Azure Subscription ID" } variable "resourceGroupName" { description = "Resource group name to create" } variable "location" { description = "Azure region (use az functionapp list-flexconsumption-locations)" } variable "applicationInsightsName" { description = "Application Insights instance name" } variable "logAnalyticsName" { description = "Log Analytics Workspace name" } variable "functionAppName" { description = "Flex Consumption app name" } variable "functionPlanName" { description = "Flex Consumption plan name" } variable "storageAccountName" { description = "Storage account name" } variable "maximumInstanceCount" { default = 100 description = "Maximum scale-out instance count" } variable "instanceMemoryMB" { default = 2048 description = "Per-instance memory: 512, 2048, or 4096 MB" } variable "functionAppRuntime" { default = "dotnet-isolated" description = "Runtime: dotnet-isolated | python | java | node | powershell | custom" } variable "functionAppRuntimeVersion" { default = "9.0" description = "Runtime version: 3.10, 3.11, 7.4, 8.0, 9.0, 10, 11, 17, 20, 21, 22. Use '1.0' for custom." } variable "zoneRedundant" { default = false description = "Enable zone redundancy" } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.