我尝试创建一个 Azure 策略,在新创建的资源上附加 created-on : dd/mm/yyyy
标记。
我正在使用以下默认策略:
{
"properties": {
"displayName": "Append a tag and its value to resources",
"policyType": "BuiltIn",
"mode": "Indexed",
"description": "Appends the specified tag and value when any resource which is missing this tag is created or updated. Does not modify the tags of resources created before this policy was applied until those resources are changed. Does not apply to resource groups. New 'modify' effect policies are available that support remediation of tags on existing resources (see https://aka.ms/modifydoc).",
"metadata": {
"version": "1.0.1",
"category": "Tags"
},
"parameters": {
"tagName": {
"type": "String",
"metadata": {
"displayName": "Tag Name",
"description": "Name of the tag, such as 'environment'"
}
},
"tagValue": {
"type": "String",
"metadata": {
"displayName": "Tag Value",
"description": "Value of the tag, such as 'production'"
}
}
},
"policyRule": {
"if": {
"field": "[concat('tags[', parameters('tagName'), ']')]",
"exists": "false"
},
"then": {
"effect": "append",
"details": [
{
"field": "[concat('tags[', parameters('tagName'), ']')]",
"value": "[parameters('tagValue')]"
}
]
}
}
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/2a0e14a6-b0a6-4fab-991a-187a4f81c498",
"type": "Microsoft.Authorization/policyDefinitions",
"name": "2a0e14a6-b0a6-4fab-991a-187a4f81c498"
}
具有以下参数:[utcNow('d')]
不幸的是,正如您所看到的,我不断收到此错误消息。
The inner exception 'The policy language function 'utcNow' has '1' argument(s). Expected number of arguments is '0'.
根据to the documentation ,我不应该能够为函数设置 'd'
参数吗?
如果我删除了参数,它就会起作用,并按照文档所述以 yyyyMMddTHHmmssZ
格式提供日期。
如何获取 dd/mm/yyyy
格式的日期?
最佳答案
某些 ARM 模板函数不允许在策略定义中使用。您可以查看here .
utcNow() - 与 ARM 模板不同,此属性可以在 defaultValue 之外使用。 返回设置为通用 ISO 8601 DateTime 格式 yyyy-MM-ddTHH:mm:ss.fffffffZ 的当前日期和时间的字符串。
关于azure - 无法将格式参数传递给 uctNow() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72886759/