gpt4 book ai didi

azure - 从 Azure ARM 模板中检索订阅标签

转载 作者:行者123 更新时间:2023-12-02 23:25:43 25 4
gpt4 key购买 nike

我正在尝试从 ARM 模板中检索订阅标签。我尝试了各种方法,但无法检索它们,有什么想法吗?

我尝试过,但没有成功...

{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": { },
"variables": { },
"resources": [ ],
"outputs": {
"subscriptionId": {
"type": "string",
"value": "[subscription().subscriptionId]"
},
"subObj": {
"type": "object",
"value": "[subscription()]"
},
"subResource": {
"type": "object",
"value": "[reference(subscriptionResourceId('Microsoft.Resources/tags', 'default'), '2019-10-01', 'Full')]"
},
"rgName": {
"type": "string",
"value": "[reference(subscriptionResourceId('Microsoft.Resources/tags', 'default'), '2019-10-01', 'Full').resourceGroupName]"
},
"ext": {
"type": "string",
"value": "[extensionResourceId(concat('/subscriptions/', subscription().subscriptionId) , 'Microsoft.Resources/tags', 'default')]"
},
"subResource2": {
"type": "Object",
"value": "[reference(subscriptionResourceId(subscription().subscriptionId, 'Microsoft.Resources/tags', 'default'), '2019-10-01')]"
}
}
}

任何帮助,非常感谢。

最佳答案

是的,可以与 Azure Policy 一起使用。

这是一个例子:

{
"mode": "All",
"parameters": {
"diagnosticsSettingsName": {
"type": "String",
"metadata": {
"displayName": "Setting name",
"description": "Name of the policy for the diagnostics settings."
},
"defaultValue": "centalizedLogs"
}
},
"policyRule": {
"if": {
"field": "type",
"equals": "Microsoft.Network/networkSecurityGroups"
},
"then": {
"effect": "deployIfNotExists",
"details": {
"type": "Microsoft.Insights/diagnosticSettings",
"roleDefinitionIds": [
"/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
],
"existenceCondition": {
"allOf": [
{
"field": "Microsoft.Insights/diagnosticSettings/logs.enabled",
"equals": "True"
},
{
"field": "Microsoft.Insights/diagnosticSettings/metrics.enabled",
"equals": "True"
},
{
"field": "name",
"matchInsensitively": "[parameters('diagnosticsSettingsName')]"
}
]
},
"deployment": {
"properties": {
"mode": "incremental",
"template": {
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"diagnosticsSettingsName": {
"type": "string"
},
"resourceName": {
"type": "string"
},
"location": {
"type": "string"
}
},
"variables": {
"referenceSubscriptionTagsResourceId": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Resources/tags/default')]",
"referenceSubscriptionTagsApi": "2019-10-01"
},
"resources": [
{
"type": "Microsoft.Network/networkSecurityGroups/providers/diagnosticSettings",
"name": "[concat(parameters('resourceName'), '/microsoft.insights/', parameters('diagnosticsSettingsName'))]",
"apiVersion": "2017-05-01-preview",
"location": "[parameters('location')]",
"dependsOn": [],
"properties": {
"workspaceId": "[resourceId(subscription().subscriptionId, 'hub', 'Microsoft.OperationalInsights/workspaces', concat('logws-', reference(variables('referenceSubscriptionTagsResourceId'), variables('referenceSubscriptionTagsApi')).tags.applicationName))]",
"logs": [
{
"category": "NetworkSecurityGroupEvent",
"enabled": true
},
{
"category": "NetworkSecurityGroupRuleCounter",
"enabled": true
}
],
"metrics": []
}
}
],
"outputs": {}
},
"parameters": {
"diagnosticsSettingsName": {
"value": "[parameters('diagnosticsSettingsName')]"
},
"location": {
"value": "[field('location')]"
},
"resourceName": {
"value": "[field('fullName')]"
}
}
}
}
}
}
}
}

关于azure - 从 Azure ARM 模板中检索订阅标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63030262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com