'Creating Azure Function Key using ARM template fails

I cannot figure out how to create azure function key for my function using ARM

I am creating a child resource inside the function itself, so this resource block lives within the main resource block of the function.

 "resources": [
        {
          "type": "Microsoft.Web/sites/functions/keys",
          "apiVersion": "2021-03-01",
          "name": "slapifd-dev",
          "properties": {
            "value": "xxxxxxx"
          }
        }
      ]

but I get this error message

##[error]Deployment template validation failed: 'The template resource 'slapifd-dev' for type 'Microsoft.Web/sites/functions/keys' at line '1' and column '1633' 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-template/#resources for usage details.'.

What am I missing here?



Solution 1:[1]

The 'name' property should be set with the nested resource names too, according to the resource type hierarchy. In your scenario, the 'name' property should be {site name}/{function name}/{key name}. For example: slapifd-dev/MyFunction/MyKey

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Matan Shabtay