Oktatóanyag: Címkék hozzáadása AZ ARM-sablonhoz

Ebből az oktatóanyagból megtudhatja, hogyan adhat hozzá címkéket az Azure Resource Manager-sablonban (ARM-sablonban) található erőforrásokhoz. A címkék kulcs-érték párokból álló metaadatelemek, amelyek segítenek az erőforrások azonosításában és a költségjelentésekben való megjelenítésben. Ez az utasítás 8 percet vesz igénybe.

Előfeltételek

Javasoljuk, hogy végezze el a gyorsindítási sablonokról szóló oktatóanyagot, de nem szükséges.

Rendelkeznie kell a Visual Studio Code-tal a Resource Manager Tools bővítménnyel, valamint Azure PowerShell vagy Azure Command-Line Interface (CLI) használatával. További információ: Sabloneszközök.

Sablon áttekintése

Az előző sablon üzembe helyezett egy tárfiókot, egy App Service csomagot és egy webalkalmazást.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "storagePrefix": {
      "type": "string",
      "minLength": 3,
      "maxLength": 11
    },
    "storageSKU": {
      "type": "string",
      "defaultValue": "Standard_LRS",
      "allowedValues": [
        "Standard_LRS",
        "Standard_GRS",
        "Standard_RAGRS",
        "Standard_ZRS",
        "Premium_LRS",
        "Premium_ZRS",
        "Standard_GZRS",
        "Standard_RAGZRS"
      ]
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]"
    },
    "appServicePlanName": {
      "type": "string",
      "defaultValue": "exampleplan"
    },
    "webAppName": {
      "type": "string",
      "metadata": {
        "description": "Base name of the resource such as web app name and app service plan "
      },
      "minLength": 2
    },
    "linuxFxVersion": {
      "type": "string",
      "defaultValue": "php|7.0",
      "metadata": {
        "description": "The Runtime stack of current web app"
      }
    }
  },
  "variables": {
    "uniqueStorageName": "[concat(parameters('storagePrefix'), uniqueString(resourceGroup().id))]",
    "webAppPortalName": "[concat(parameters('webAppName'), uniqueString(resourceGroup().id))]"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2021-09-01",
      "name": "[variables('uniqueStorageName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('storageSKU')]"
      },
      "kind": "StorageV2",
      "properties": {
        "supportsHttpsTrafficOnly": true
      }
    },
    {
      "type": "Microsoft.Web/serverfarms",
      "apiVersion": "2021-03-01",
      "name": "[parameters('appServicePlanName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "B1",
        "tier": "Basic",
        "size": "B1",
        "family": "B",
        "capacity": 1
      },
      "kind": "linux",
      "properties": {
        "perSiteScaling": false,
        "reserved": true,
        "targetWorkerCount": 0,
        "targetWorkerSizeId": 0
      }
    },
    {
      "type": "Microsoft.Web/sites",
      "apiVersion": "2021-03-01",
      "name": "[variables('webAppPortalName')]",
      "location": "[parameters('location')]",
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]"
      ],
      "kind": "app",
      "properties": {
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]",
        "siteConfig": {
          "linuxFxVersion": "[parameters('linuxFxVersion')]"
        }
      }
    }
  ],
  "outputs": {
    "storageEndpoint": {
      "type": "object",
      "value": "[reference(variables('uniqueStorageName')).primaryEndpoints]"
    }
  }
}

Előfordulhat, hogy az erőforrások üzembe helyezése után nyomon kell követnie a költségeket, és meg kell keresnie a kategóriához tartozó erőforrásokat. Címkék hozzáadásával megoldhatja ezeket a problémákat.

Címkék hozzáadása

Az erőforráscímkékkel az erőforrások felhasználási célját azonosító értékeket adhat meg. Hozzáadhat olyan címkéket, amelyek felsorolják a környezetet és a projektet. Hozzáadhatja őket egy költséghely vagy az erőforrás tulajdonos csapatának azonosításához is. Adjon hozzá olyan értékeket, amelyek a szervezet szempontjából jelentéssel bírnak.

Az alábbi példa a sablon módosításait emeli ki. Másolja ki a teljes fájlt, és cserélje le a sablont annak tartalmára.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "storagePrefix": {
      "type": "string",
      "minLength": 3,
      "maxLength": 11
    },
    "storageSKU": {
      "type": "string",
      "defaultValue": "Standard_LRS",
      "allowedValues": [
        "Standard_LRS",
        "Standard_GRS",
        "Standard_RAGRS",
        "Standard_ZRS",
        "Premium_LRS",
        "Premium_ZRS",
        "Standard_GZRS",
        "Standard_RAGZRS"
      ]
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]"
    },
    "appServicePlanName": {
      "type": "string",
      "defaultValue": "exampleplan"
    },
    "webAppName": {
      "type": "string",
      "metadata": {
        "description": "Base name of the resource such as web app name and app service plan "
      },
      "minLength": 2
    },
    "linuxFxVersion": {
      "type": "string",
      "defaultValue": "php|7.0",
      "metadata": {
        "description": "The Runtime stack of current web app"
      }
    },
    "resourceTags": {
      "type": "object",
      "defaultValue": {
        "Environment": "Dev",
        "Project": "Tutorial"
      }
    }
  },
  "variables": {
    "uniqueStorageName": "[concat(parameters('storagePrefix'), uniqueString(resourceGroup().id))]",
    "webAppPortalName": "[concat(parameters('webAppName'), uniqueString(resourceGroup().id))]"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2021-09-01",
      "name": "[variables('uniqueStorageName')]",
      "location": "[parameters('location')]",
      "tags": "[parameters('resourceTags')]",
      "sku": {
        "name": "[parameters('storageSKU')]"
      },
      "kind": "StorageV2",
      "properties": {
        "supportsHttpsTrafficOnly": true
      }
    },
    {
      "type": "Microsoft.Web/serverfarms",
      "apiVersion": "2021-03-01",
      "name": "[parameters('appServicePlanName')]",
      "location": "[parameters('location')]",
      "tags": "[parameters('resourceTags')]",
      "sku": {
        "name": "B1",
        "tier": "Basic",
        "size": "B1",
        "family": "B",
        "capacity": 1
      },
      "kind": "linux",
      "properties": {
        "perSiteScaling": false,
        "reserved": true,
        "targetWorkerCount": 0,
        "targetWorkerSizeId": 0
      }
    },
    {
      "type": "Microsoft.Web/sites",
      "apiVersion": "2021-03-01",
      "name": "[variables('webAppPortalName')]",
      "location": "[parameters('location')]",
      "dependsOn": [
        "[parameters('appServicePlanName')]"
      ],
      "tags": "[parameters('resourceTags')]",
      "kind": "app",
      "properties": {
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]",
        "siteConfig": {
          "linuxFxVersion": "[parameters('linuxFxVersion')]"
        }
      }
    }
  ],
  "outputs": {
    "storageEndpoint": {
      "type": "object",
      "value": "[reference(variables('uniqueStorageName')).primaryEndpoints]"
    }
  }
}

Sablon üzembe helyezése

Ideje üzembe helyezni a sablont, és megnézni az eredményeket.

Ha még nem hozta létre az erőforráscsoportot, olvassa el az Erőforráscsoport létrehozása című témakört. A példa feltételezi, hogy a változót templateFile a sablonfájl elérési útjára állította, ahogy az első oktatóanyagban is látható.

New-AzResourceGroupDeployment `
  -Name addtags `
  -ResourceGroupName myResourceGroup `
  -TemplateFile $templateFile `
  -storagePrefix "store" `
  -storageSKU Standard_LRS `
  -webAppName demoapp

Megjegyzés

Ha az üzembe helyezés sikertelen, a verbose kapcsolóval információkat kaphat a létrehozott erőforrásokról. A kapcsolóval debug további információt kaphat a hibakeresésről.

Az üzembe helyezés ellenőrzése

Az üzembe helyezés ellenőrzéséhez tekintse meg az erőforráscsoportot a Azure Portal.

  1. Jelentkezzen be az Azure Portalra.

  2. A bal oldali menüben válassza az Erőforráscsoportok lehetőséget.

  3. Válassza ki azt az erőforráscsoportot, amelybe üzembe helyezett.

  4. Válassza ki az egyik erőforrást, például a tárfiók-erőforrást. Láthatja, hogy már címkéket is tartalmaznak.

    Képernyőkép Azure Portal egy tárfiók-erőforrás címkéiről.

Az erőforrások eltávolítása

Ha továbblép a következő oktatóanyagra, nem kell törölnie az erőforráscsoportot.

Ha most leáll, érdemes lehet törölnie az erőforráscsoportot.

  1. A Azure Portal válassza az Erőforráscsoportok lehetőséget a bal oldali menüben.
  2. Írja be az erőforráscsoport nevét a Szűrő bármely mezőhöz... szövegmezőbe.
  3. Jelölje be a myResourceGroup melletti jelölőnégyzetet, és válassza a myResourceGroup vagy az erőforráscsoport nevét.
  4. Válassza az Erőforráscsoport törlése lehetőséget a felső menüben.

Következő lépések

Ebben az oktatóanyagban címkéket ad hozzá az erőforrásokhoz. A következő oktatóanyagból megtudhatja, hogyan használhat paraméterfájlokat az értékek sablonba való átadásának egyszerűsítésére.