如何使用 REST API 创建 Azure 资源?

How to create Azure Resources using REST API?

我想创建 CosmosDB、Azure Kubernetes 服务等资源 我浏览了以下文档:

https://docs.microsoft.com/en-us/rest/api/resources/resources/create-or-update

我看到请求 URL 有如下参数:-

https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}?api-version=2021-04-01

在哪里可以找到 resourceProviderNamespaceparentResourcePathresourceType 等字段的值, 等每个资源,如 cosmosDB、AKS 等?

还有每个资源期望的属性,如位置、备份等??

根据Gaurav Mantri, you can refer to Azure FarmBeats control plane and data plane operations

的建议

谢谢你和AnuragSharma-MSFT and MarcoPapst-5675。将您的建议作为答案发布以帮助社区成员。

CosmosDB角色分配可参考以下脚本:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "roleDefinitionId": {
            "type": "string",
            "metadata": {
                "description": "Name of the Role Definition"
            }
        },
        "roleAssignmentName": {
            "type": "string",
            "metadata": {
                "description": "Name of the Assignment"
            }
        },
        "scope": {
            "type": "string",
            "metadata": {
                "description": "Scope of the Role Assignment"
            }
        },
        "principalId": {
            "type": "string",
            "metadata": {
                "description": "Object ID of the AAD identity. Must be a GUID."
            }
        }
    },
    "variables": { },
    "resources": [
        {
            "name": "[concat(parameters('roleAssignmentName'), '/', guid(parameters('scope')))]",
            "type": "Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignments",
            "apiVersion": "2021-04-15",
            "properties": {
                "roleDefinitionId": "[parameters('roleDefinitionId')]",
                "principalId": "[parameters('principalId')]",
                "scope": "[parameters('scope')]"
            }
        }
    ]
}

可以参考Create a CosmosDB Role Assignment using an ARM Template, and Resources - Get By Id