Azure website resource template error

后端 未结 5 1880
醉话见心
醉话见心 2021-01-01 09:52

I\'m attempting to use the AzureResourceManager PowerShell module to create and configure a website. I started with a template file generated by Visual Studio, which works

5条回答
  •  南笙
    南笙 (楼主)
    2021-01-01 10:26

    I hit the same issue and neither of the other answers worked for me, turns out there's actually slightly more to this than the other answers show. Firstly, for a root level resource, the docs specify it must:

    ...have one less segment in the name than in the resource type

    In other words if you're creating a:

    "type": "Microsoft.Web/sites"
    

    Then as the name must have one less segment than the type, we can only use a single segment for the name in this example, i.e. one:

    "name": "MySite"
    

    For a nested resource the rule is:

    the type and name have the same number of segments

    However this assumes that you are shortening a nested resource's type e.g. creating a type of "Microsoft.Web/sites/config" as a nested resource within a parent of type "Microsoft.Web/sites" and for the nested resource specifying:

    "type": "config"
    

    So here you can also only specify a single segment name, e.g.:

    "name": "MyConfig"
    

    So putting that all together you have:

    {
      "type": "Microsoft.Web/sites",
      "name": "MySite",
      "various other properties": ...,
      "resources": [
        {
          "type": "config",
          "name": "MyConfig"
          "various other properties": ...
        }
      ]
    }
    

    If on the other hand you specify the full type name in the nested resource (as shown in the accepted answer) you need to resort to the root naming convention of having one less segment in the name than the type! Converting the above you'd have:

    {
      "type": "Microsoft.Web/sites",
      "name": "MySite",
      "various other properties": ...,
      "resources": [
        {
          "type": "Microsoft.Web/sites/config",
          "name": "MySite/MyConfig"
          "various other properties": ...
        }
      ]
    }
    

提交回复
热议问题