gpt4 book ai didi

Azure Bicep 不会删除存储容器

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

我有一个 Azure Bicep 模板,用于部署存储帐户和容器。但是,当我重命名容器或注释掉模板中的容器资源时,不会触发删除操作。相反,它会创建一个新容器并且不会删除旧容器。有什么想法为什么会发生这种情况吗?

Note: I use Mode Complete to deploy

我有一个 main.bicep 文件,其中包含

param location string = resourceGroup().location

param storageAccountName string = 'test${uniqueString('newstring')}'
param storageContainerName string = 'testcontainer'

module storagAccounts '../resources/storage/storageAccounts.bicep' = {
name: 'storageAccounts'
params: {
location: location
storageAccountName: storageAccountName
}
}

module blobServices '../resources/storage/blobServices.bicep' = {
name: 'blobServices'
params: {
storageAccountName: storagAccounts.outputs.storageAccountName
}
}

module blobContainer '../resources/storage/containers.bicep' = {
name: 'blobContainer'
params: {
containerName: storageContainerName
blobServicesName: blobServices.outputs.blobServicesName
storageAccountName: storagAccounts.outputs.storageAccountName
}
}

我有一个 storageAccounts.bicep 包含

targetScope = 'resourceGroup'

@minLength(3)
@maxLength(24)
param storageAccountName string

param location string

resource storageAccount 'Microsoft.Storage/storageAccounts@2021-02-01' = {
name: storageAccountName
location: location
kind: 'StorageV2'
sku: {
name: 'Standard_LRS'
}

tags: {
environment: 'test'
}


}

output storageAccountId string = storageAccount.id
output storageAccountName string = storageAccountName

blobServices.bicep

param storageAccountName string 
param blobServicesName string = 'default'

resource blobServices 'Microsoft.Storage/storageAccounts/blobServices@2023-01-01' = {
name: '${storageAccountName}/${blobServicesName}'
}

output blobServicesName string = blobServicesName

和一个包含的container.bicep

param storageAccountName string
param blobServicesName string
param containerName string

resource storageContainer 'Microsoft.Storage/storageAccounts/blobServices/containers@2023-01-01' = {
name: '${storageAccountName}/${blobServicesName}/${containerName}'
properties: {
publicAccess: 'None'
}
}

output storageContainerName string = storageContainer.name

为了部署,我使用 PowerShell 脚本

Get-AzResourceGroupDeploymentWhatIfResult -Mode Complete -Location westeurope -TemplateFile modules/main.bicep -ResourceGroup testResourceGroup


New-AzResourceGroupDeployment -Name deployment1 -Mode Complete -Location westeurope -TemplateFile modules/main.bicep -ResourceGroup testResourceGroup -Force

最佳答案

根据documentation ,这是存储帐户的预期行为:

Resource types may handle complete mode deletions differently. Parent resources are automatically deleted when not defined in a template deployed in complete mode. Also, child resources are automatically deleted when the parent isn't included in the template. However, some child resources are deleted when not defined in the template but other child resources aren't deleted. For a list of how resource types handle deletion, see Deletion of Azure resources for complete mode deployments.

For example, if your resource group contains a storage account (Microsoft.Storage/storageAccounts resource type) and a blob service (Microsoft.Storage/storageAccounts/blobServices resource type), the storage account is the parent resource for the blob service. If you deploy with complete mode and don't include the storage account in your template, both the storage account and the blob service are deleted. If you include the storage account in your template but don't include the blob service, the blob service isn't deleted.

更多信息可以在这里找到:

关于Azure Bicep 不会删除存储容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77072505/

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