gpt4 book ai didi

azure - 使用 ARM 模板删除现有资源

转载 作者:行者123 更新时间:2023-12-04 10:39:52 26 4
gpt4 key购买 nike

我使用 ARM 模板创建了包括存储帐户在内的资源。现在我想使用arm模板删除该存储帐户,而不是其他资源。我正在使用链接模板设计。以下是我的 masterAzureDeploy.json:

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"templateBaseUrl": {
"type": "string"
},
"parameterBaseUrl": {
"type": "string"
},
"storageAccessToken": {
"type": "string"
}
},
"variables": {
"templateBaseUrl": "[parameters('templateBaseUrl')]",
"parameterBaseUrl": "[parameters('parameterBaseUrl')]",
"keyVaultDeployTemplateUrl": "[uri(variables('templateBaseUrl'), 'keyvaultdeploy.json')]",
"cosmosdbDeployTemplateUrl": "[uri(variables('templateBaseUrl'), 'cosmosdeploy.json')]",
"managedidentityDeployTemplateUrl": "[uri(variables('templateBaseUrl'), 'managedidentitydeploy.json')]",
"aurorapostgresDeployTemplateUrl": "[uri(variables('templateBaseUrl'), 'aurorapostgresdeploy.json')]",
"redisDeployTemplateUrl": "[uri(variables('templateBaseUrl'), 'redisdeploy.json')]",
"storageDeployTemplateUrl": "[uri(variables('templateBaseUrl'), 'storagedeploy.json')]",
"dnszoneDeployTemplateUrl": "[uri(variables('templateBaseUrl'), 'dnszonedeploy.json')]",
"bhnsgDeployTemplateUrl": "[uri(variables('templateBaseUrl'), 'bhnsgdeploy.json')]",
"rdnsgDeployTemplateUrl": "[uri(variables('templateBaseUrl'), 'rdnsgdeploy.json')]",
"dbnsgDeployTemplateUrl": "[uri(variables('templateBaseUrl'), 'dbnsgdeploy.json')]",
"apiVersionResourceDeployment": "[providers('Microsoft.Resources', 'deployments').apiVersions[0]]",
"keyVaultparameterFileUrl": "[uri(variables('parameterBaseUrl'), 'keyvaultdeploy.parameters.json')]",
"cosmosdbparameterFileUrl": "[uri(variables('parameterBaseUrl'), 'cosmosdeploy.parameters.json')]",
"managedidentityparameterFileUrl": "[uri(variables('parameterBaseUrl'), 'managedidentitydeploy.parameters.json')]",
"aurorapostgresparameterFileUrl": "[uri(variables('parameterBaseUrl'), 'aurorapostgresdeploy.parameters.json')]",
"redisparameterFileUrl": "[uri(variables('parameterBaseUrl'), 'redisdeploy.parameters.json')]",
"storageparameterFileUrl": "[uri(variables('parameterBaseUrl'), 'storagedeploy.parameters.json')]",
"dnszoneparameterFileUrl": "[uri(variables('parameterBaseUrl'), 'dnszonedeploy.parameters.json')]",
"bhnsgparameterFileUrl": "[uri(variables('parameterBaseUrl'), 'bhnsgdeploy.parameters.json')]",
"rdnsgparameterFileUrl": "[uri(variables('parameterBaseUrl'), 'rdnsgdeploy.parameters.json')]",
"dbnsgparameterFileUrl": "[uri(variables('parameterBaseUrl'), 'dbnsgdeploy.parameters.json')]"
},
"resources": [
{
"apiVersion": "[variables('apiVersionResourceDeployment')]",
"name": "keyVaultDeployment",
"type": "Microsoft.Resources/deployments",
"properties": {
"templateLink": {
"uri": "[concat(variables('keyVaultDeployTemplateUrl'), parameters('storageAccessToken'))]"
},
"parametersLink": {
"uri": "[concat(variables('keyVaultparameterFileUrl'), parameters('storageAccessToken'))]"
}
}
},
{
"apiVersion": "[variables('apiVersionResourceDeployment')]",
"name": "cosmosDBDeployment",
"type": "Microsoft.Resources/deployments",
"properties": {
"templateLink": {
"uri": "[concat(variables('cosmosdbDeployTemplateUrl'), parameters('storageAccessToken'))]"
},
"parametersLink": {
"uri": "[concat(variables('cosmosdbparameterFileUrl'), parameters('storageAccessToken'))]"
}
}
},
{
"apiVersion": "[variables('apiVersionResourceDeployment')]",
"name": "storageDeployment",
"type": "Microsoft.Resources/deployments",
"properties": {
"templateLink": {
"uri": "[concat(variables('storageDeployTemplateUrl'), parameters('storageAccessToken'))]"
},
"parametersLink": {
"uri": "[concat(variables('storageparameterFileUrl'), parameters('storageAccessToken'))]"
}
}
},
{
"apiVersion": "[variables('apiVersionResourceDeployment')]",
"name": "redisDeployment",
"type": "Microsoft.Resources/deployments",
"properties": {
"templateLink": {
"uri": "[concat(variables('redisDeployTemplateUrl'), parameters('storageAccessToken'))]"
},
"parametersLink": {
"uri": "[concat(variables('redisparameterFileUrl'), parameters('storageAccessToken'))]"
}
}
},
{
"apiVersion": "[variables('apiVersionResourceDeployment')]",
"name": "aurorapostgresDeploy",
"type": "Microsoft.Resources/deployments",
"properties": {
"templateLink": {
"uri": "[concat(variables('aurorapostgresDeployTemplateUrl'), parameters('storageAccessToken'))]"
},
"parametersLink": {
"uri": "[concat(variables('aurorapostgresparameterFileUrl'), parameters('storageAccessToken'))]"
}
}
},
{
"apiVersion": "[variables('apiVersionResourceDeployment')]",
"name": "managedIdentityDeployment",
"type": "Microsoft.Resources/deployments",
"properties": {
"templateLink": {
"uri": "[concat(variables('managedidentityDeployTemplateUrl'), parameters('storageAccessToken'))]"
},
"parametersLink": {
"uri": "[concat(variables('managedidentityparameterFileUrl'), parameters('storageAccessToken'))]"
}
}
},
{
"apiVersion": "[variables('apiVersionResourceDeployment')]",
"name": "dnszoneDeployment",
"type": "Microsoft.Resources/deployments",
"properties": {
"templateLink": {
"uri": "[concat(variables('dnszoneDeployTemplateUrl'), parameters('storageAccessToken'))]"
},
"parametersLink": {
"uri": "[concat(variables('dnszoneparameterFileUrl'), parameters('storageAccessToken'))]"
}
}
},
{
"apiVersion": "[variables('apiVersionResourceDeployment')]",
"name": "bhnsgDeployment",
"type": "Microsoft.Resources/deployments",
"properties": {
"templateLink": {
"uri": "[concat(variables('bhnsgDeployTemplateUrl'), parameters('storageAccessToken'))]"
},
"parametersLink": {
"uri": "[concat(variables('bhnsgparameterFileUrl'), parameters('storageAccessToken'))]"
}
}
},
{
"apiVersion": "[variables('apiVersionResourceDeployment')]",
"name": "rdnsgDeployment",
"type": "Microsoft.Resources/deployments",
"properties": {
"templateLink": {
"uri": "[concat(variables('rdnsgDeployTemplateUrl'), parameters('storageAccessToken'))]"
},
"parametersLink": {
"uri": "[concat(variables('rdnsgparameterFileUrl'), parameters('storageAccessToken'))]"
}
}
},
{
"apiVersion": "[variables('apiVersionResourceDeployment')]",
"name": "dbnsgDeployment",
"type": "Microsoft.Resources/deployments",
"properties": {
"templateLink": {
"uri": "[concat(variables('dbnsgDeployTemplateUrl'), parameters('storageAccessToken'))]"
},
"parametersLink": {
"uri": "[concat(variables('dbnsgparameterFileUrl'), parameters('storageAccessToken'))]"
}
}
}
]
}

这是我的 storagedeploy.json

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"Project": {
"type": "string",
"metadata": {
"description": "Project name"
}
},
"Environment": {
"type": "string",
"metadata": {
"description": "Project name"
}
},
"location": {
"type": "string",
"metadata": {
"description": "Location for all resources."
}
},
"principalId": {
"type": "string",
"metadata": {
"description": "PrincipalId is Object Id of MSi created. Check Azure Active Directory. Ref https://stackoverflow.com/questions/56440883/arm-template-looking-up-a-user-object-id."
}
}
},
"variables": {
"storageAccountName": "[toLower(concat(parameters('Project'), parameters('Environment'), uniqueString(resourceGroup().id)))]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2019-04-01",
"name": "[variables('storageAccountName')]",
"location": "[parameters('location')]",
"sku": {
"name": "Standard_LRS",
"tier": "Standard"
},
"kind": "StorageV2",
"properties": {
"networkAcls": {
"bypass": "AzureServices",
"virtualNetworkRules": [],
"ipRules": [],
"defaultAction": "Allow"
},
"supportsHttpsTrafficOnly": true,
"encryption": {
"services": {
"file": {
"enabled": true
},
"blob": {
"enabled": true
}
},
"keySource": "Microsoft.Storage"
},
"accessTier": "Hot"
}
},
{
"type": "Microsoft.Storage/storageAccounts/blobServices",
"apiVersion": "2019-04-01",
"name": "[concat(variables('storageAccountName'), '/default')]",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
],
"properties": {
"cors": {
"corsRules": []
},
"deleteRetentionPolicy": {
"enabled": false
}
}
},
{
"type": "Microsoft.Storage/storageAccounts/blobServices/containers",
"apiVersion": "2019-04-01",
"name": "[concat(variables('storageAccountName'), '/default/project-test-dev-data-store-ue1')]",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts/blobServices', variables('storageAccountName'), 'default')]",
"[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
],
"properties": {
"publicAccess": "None"
}
},
{
"type": "Microsoft.Storage/storageAccounts/providers/roleAssignments",
"name": "[concat(variables('storageAccountName'),'/Microsoft.Authorization/',guid(subscription().subscriptionId))]",
"apiVersion": "2019-04-01-preview",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts/blobServices', variables('storageAccountName'), 'default')]",
"[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
],
"properties": {
"roleDefinitionId": "[concat(resourceGroup().id, '/providers/Microsoft.Authorization/roleDefinitions/17d1049b-9a84-46fb-8f53-869881c3d3ab')]",
"principalId": "[parameters('principalId')]",
"scope": "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
}
}
]
}

在命令行中,我使用 --modecomplete。

我尝试修改 storagedeploy.json 模板,但没有成功:

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"Project": {
"type": "string",
"metadata": {
"description": "Project name"
}
},
"Environment": {
"type": "string",
"metadata": {
"description": "Project name"
}
},
"location": {
"type": "string",
"metadata": {
"description": "Location for all resources."
}
},
"principalId": {
"type": "string",
"metadata": {
"description": "PrincipalId is Object Id of MSi created. Check Azure Active Directory. Ref https://stackoverflow.com/questions/56440883/arm-template-looking-up-a-user-object-id."
}
}
},
"variables": {
"storageAccountName": "[toLower(concat(parameters('Project'), parameters('Environment'), uniqueString(resourceGroup().id)))]"
},
"resources": []
}

如何做。

最佳答案

我相信您所观察到的这种行为的原因是因为只有根级模板支持完整的部署模式。对于 linked or nested templates ,必须使用增量模式。 Subscription level deployments不支持完整模式。目前,该门户不支持完整模式。

有关详细信息,请参阅 this 中提供的注释文档。

因此,为了满足您的要求,您可能不必使用链接或嵌套模板。

希望这有帮助!

关于azure - 使用 ARM 模板删除现有资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59982369/

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