Azure-Samples / azure-functions-flex-consumption-samples

Samples for Azure Functions Flex Consumption
MIT License
17 stars 16 forks source link

Creating a flex consumption function app from arm template is erroring out #7

Closed ashwinvenkatesha closed 1 month ago

ashwinvenkatesha commented 2 months ago

Attempting to deploy this template https://github.com/Azure-Samples/azure-functions-flex-consumption-samples/blob/main/IaC/armtemplate/azuredeploy.json

Any log messages given by the failure

Deployment template validation failed: 'The template resource 'default/app-package-flexapp-qydycyt' for type 'containers' at line '158' and column '34' has incorrect segment lengths. A nested resource type must have identical number of segments as its resource name. A root resource type must have segment length one greater than its resource name. Please see https://aka.ms/arm-syntax-resources for usage details.'. (Code: InvalidTemplate)

Second issue: i tried to deploy a custom template that attempts to create flex consumption function app, that failed with {"code":"BadRequest","message":"Site.FunctionAppConfig is invalid. The FunctionAppConfig section was not specified in the request, which is required for Flex Consumption sites. To proceed, please add the FunctionAppConfig section in your request.","details":[{"message":"Site.FunctionAppConfig is invalid. The FunctionAppConfig section was not specified in the request, which is required for Flex Consumption sites. To proceed, please add the FunctionAppConfig section in your request."},{"code":"BadRequest"},{}]} Here is the template I am using { "type": "Microsoft.Web/serverfarms", "apiVersion": "2023-12-01", "name": "[variables('functionName')]", "location": "[variables('logAnalyticsWorkspaceLocation')]", "tags": "[ if(contains(variables('tagsByResource'), 'Microsoft.Web/serverfarms'), variables('tagsByResource')['Microsoft.Web/serverfarms'], json('{}')) ]", "sku": { "tier": "FlexConsumption", "name": "FC1" }, "kind": "functionapp", "properties": { "reserved": true }, "condition": "[equals(variables('functionAppHostingPlan'),'flex')]" },

Expected/desired behavior

Deployment should work as expected

Mention any other details that might be useful

I chose to deploy a python flex function app in log analytics workspace


Thanks! We'll be in touch soon.

nzthiago commented 2 months ago

Thank you for reporting - I have just fixed the issue with the storage container create. Please pull the latest from the repo and try again, let me know if you still get errors.

Note that Flex Consumption has a new section where the storage container to use for the deployment package, as well as the app runtime and scaling settings are configured, you need to ensure this section exists: https://github.com/Azure-Samples/azure-functions-flex-consumption-samples/blob/b8eb32a6e88bd9637ff549c76234b36b6f905951/IaC/armtemplate/azuredeploy.json#L161-L179

ashwinvenkatesha commented 2 months ago

I see, thanks. So in case, I have an arm template where I define "type": "Microsoft.Web/sites" for premium and consumption apps, how to ensure the additional section you have listed above gets incorporated? A conditional based section? Here is my arm template: https://github.com/illumio-shield/Azure-Sentinel/blob/Illumio-Integration-GA-branch/Solutions/IllumioSaaS/Data%20Connectors/azuredeploy_IllumioSaaS_FunctionApp.json#L811

nzthiago commented 2 months ago

Yes - for the hosting plan ('serverfarm') you can reuse it the section, but for the Microsoft.Web/sites there's enough differences that warrants a conditional based switch between the plans.

Here's one way we did it with Bicep for example, with different modules being called depending on the value of the azFunctionHostingPlanType parameter: https://github.com/Azure-Samples/Azure-Functions-OpenAI-Demo/blob/7dfa6ea002ee165b5bee1b29f9d3f17797517c57/infra/main.bicep#L167-L209

BigMorty commented 1 month ago

@ashwinvenkatesha - OK if I close this issue?

nzthiago commented 1 month ago

Closing this issue - please create a new one if the replies haven't addressed it.