azure - 如何将当前时间标记为 ARM 部署的标签

标签 azure azure-resource-manager azure-rm-template

我正在尝试使用 ARM 模板和参数文件创建 Log Analytics 工作区。我还考虑将当前时间标记为资源的 CreatedOn 标记。 下面是我的 ARM 模板-

{
    "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "LAWName": {
            "type": "string"
        },
        "LocationName": {
            "type": "string"
        },
        "SKUName": {
            "type": "string"
        },
        "Tags": {
            "type": "object"
        }
    },
    "resources": [
        {
            "apiVersion": "2017-03-15-preview",
            "name": "[parameters('LAWName')]",
            "location": "[parameters('LocationName')]",
            "tags": "[parameters('Tags')]",
            "type": "Microsoft.OperationalInsights/workspaces",
            "properties": {
                "sku": {
                    "name": "[parameters('SKUName')]"
                }
            }
        }
    ]
}

这是我的参数文件-

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "LAWName": {
            "value": "atifmtest1"
        },
        "LocationName": {
            "value": "westeurope"
        },
        "SKUName": {
            "value": "pergb2018"
        }
        "Tags": {
            "value": {
                "CreatedBy": "Atif",
                "CreatedOn": "[utcNow()]",
                "Purpose": "Monitoring"
            }
        }
    }
}

我在这里读到https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-date#utcnow ARM 模板有 utcNow() 函数,但此处被视为字符串,并且当前时间不会显示为资源的标签。 enter image description here 还有什么其他方法可以实现这一目标? 预先感谢!

最佳答案

这是一个工作示例:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "utcShort": {
            "type": "string",
            "defaultValue": "[utcNow('d')]"
        },
        "location": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]"
        }
    },
    "resources": [
        {
            "apiVersion": "2019-04-01",
            "type": "Microsoft.Storage/storageAccounts",
            "name": "[concat('storage', uniqueString(resourceGroup().id))]",
            "location": "[parameters('location')]",
            "tags": {
                "Dept": "Finance",
                "Environment": "Production",
                "LastDeployed": "[parameters('utcShort')]"
            },
            "sku": {
                "name": "Standard_LRS"
            },
            "kind": "Storage",
            "properties": {}
        }
    ]
}

Source.

关于azure - 如何将当前时间标记为 ARM 部署的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64766185/

相关文章:

powershell - 使用 Get-AzureStorageBlobContent 从 Azure 下载 - 内容出现乱码

azure-keyvault - 如何在ARM模板中输出secret uri?

powershell - 管理 azure 资源管理器存储 powershell

azure - 如何下载我在门户中创建的 Azure 资源组的模板 json?

azure - 这些 csdef 和 cscfg 值的 ARM 模板等效项是什么

python - 部署 ARM 模板时出错。找不到与模板文件模式匹配的任何文件

c# - 时间触发的 Azure Functions

Windows Azure :Do we need External Persisted storage for Web role having Multiple Instances

azure - 使用多个实例更新 azure 表中的 40+ 百万个实体如何处理并发问题

azure - 无法从 ARM 模板检索逻辑应用程序(标准)工作流程 URL