Azure 使用ARM模板删除现有资源

Azure 使用ARM模板删除现有资源,azure,azure-resource-manager,arm-template,Azure,Azure Resource Manager,Arm Template,我已经使用ARM模板创建了包括存储帐户在内的资源。现在,我想使用arm模板而不是其他资源删除该存储帐户。我使用链接模板设计。 下面是我的masterAzureDeploy.json: { "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "templa

我已经使用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": []
}

如何做到这一点。

我认为您观察到这种行为的原因是因为只有根级模板支持完整的部署模式。对于,必须使用增量模式。不支持完整模式。目前,门户不支持完整模式

有关更多信息,请参阅文档中的注释

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

希望这有帮助