首页 > 解决方案 > ARM 模板:获取 IOT hub 的 SKU

问题描述

使用“reference”关键字,我可以访问我的 iot hub 并列出它的属性。但是我找不到对 SKU 的任何引用。如何列出要输出的物联网中心的 sku 名称/层?

ARM 模板段

标签: azureazure-devopsazure-resource-manager

解决方案


如果要获取iot hub的sku inarm模板,可以使用arm模板函数“reference”

[reference(resourceId('Microsoft.Devices/IotHubs', 'hubname'),'2018-04-01','Full')]

例如

模板

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "hubname": {
            "type": "String"
        },
        "location": {
            "type": "String"
        },
        "sku_name": {
            "type": "String"
        },
        "sku_units": {
            "type": "String"
        },
        "d2c_partitions": {
            "type": "String"
        },
        "features": {
            "type": "String"
        },
        "tags": {
            "type": "Object"
        },
        "cloudEnvironment": {
            "defaultValue": "public",
            "allowedValues": [
                "public",
                "china",
                "usgov"
            ],
            "type": "String",
            "metadata": {
                "description": "Cloud environment to deploy (i.e. usgov/china/ ...)"
            }
        }
    },
    "resources": [
        {
            "type": "Microsoft.Devices/IotHubs",
            "apiVersion": "2020-07-10-preview",
            "name": "[parameters('hubname')]",
            "location": "[parameters('location')]",
            "tags": "[parameters('tags')]",
            "sku": {
                "name": "[parameters('sku_name')]",
                "capacity": "[parameters('sku_units')]"
            },
            "properties": {
                "eventHubEndpoints": {
                    "events": {
                        "retentionTimeInDays": 1,
                        "partitionCount": "[parameters('d2c_partitions')]"
                    }
                },
                "features": "[parameters('features')]"
            }
        },
        {
            "type": "Microsoft.Security/IoTSecuritySolutions",
            "apiVersion": "2019-08-01",
            "name": "[parameters('hubname')]",
            "location": "[parameters('location')]",
            "dependsOn": [
                "[resourceId('Microsoft.Devices/IotHubs', parameters('hubname'))]"
            ],
            "properties": {
                "status": "Enabled",
                "unmaskedIpLoggingStatus": "Enabled",
                "disabledDataSources": [],
                "displayName": "[parameters('hubname')]",
                "iotHubs": [
                    "[resourceId('Microsoft.Devices/IotHubs', parameters('hubname'))]"
                ],
                "recommendationsConfiguration": []
            }
        }
    ],
    "outputs": {
        "iot": {
            "type": "Object",
            "value": "[reference(resourceId('Microsoft.Devices/IotHubs', parameters('hubname')),'2018-04-01','Full').sku]"
        }
    }
}

范围

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "hubname": {
      "value": "testiot05"
    },
    "location": {
      "value": "eastasia"
    },
    "sku_name": {
      "value": "S1"
    },
    "sku_units": {
      "value": "1"
    },
    "d2c_partitions": {
      "value": "4"
    },
    "features": {
      "value": "None"
    },
    "tags": {
      "value": {}
    },
    "cloudEnvironment": {
      "value": "public"
    }
  }
}

在此处输入图像描述


推荐阅读