Azure Bicep和租户范围(what-if vs create)



我正在使用Azure Bicep部署管理组。虽然create工作良好,但我面临着what-if意想不到的(至少对我来说不清楚)问题。我正在使用这种方法。我的"target"管理组不是根租户管理组。我得到的错误信息是:

DeploymentWhatIfResourceError - The request to predict template deployment changes to scope '/providers/Microsoft.Management/managementGroups/target-mg' has failed due to a resource error. See details for more information. AuthorizationFailed - The client '<<redacted>>' with object id '<<redacted>>' does not have authorization to perform action 'Microsoft.Management/managementGroups/read' over scope '/providers/Microsoft.Management/managementGroups/test-name' or the scope is invalid. If access was recently granted, please refresh your credentials.

what-if是否需要比create更多的权限?我有以下模板:

targetScope = 'managementGroup'
param name string = 'test-name'
param displayName string = 'test displayName'
resource managemagentGroup 'Microsoft.Management/managementGroups@2021-04-01' = {
name: name
scope: tenant()
properties: {
details: {
parent: {
id: managementGroup().id
}
}
displayName: displayName
}
}

然后像这样运行:

# this fails with the error above.
az deployment mg what-if -f main.bicep -m target-mg -l westeurope
# this works fine
az deployment mg validate -f main.bicep -m target-mg -l westeurope
# this works fine
az deployment mg create -f main.bicep -m target-mg -l westeurope

有人遇到同样的问题吗?

我认为您遇到了一个已知的问题,其中管理组资源提供程序对不存在的管理组返回一个403(而不是404)。

What-If执行GET查看当前状态并接收403。假设403的意思和它说的一样,而且你没有烫发。在这种情况下,What-if应该收到404。为了确认这是您所遇到的,如果您继续执行create,然后再次运行what-if,它应该成功。

re: perms—如果您有允许validatecreate成功运行的perms,那么您在作用域中有足够的perms—您不需要在租户(即"/")作用域中有任何perms。

作为一个变通的办法,你可以给校长更多的烫发来解决这个问题,但我还没能确定什么是最小的烫发…我知道如果您是租户所有者(即烫发在"/")这将工作-这就是为什么我不能复制它在我的端-但这不应该是必需的,它相当于sudo/root权限,所以不是一个很好的选择。另一种选择是,当您知道MG不存在时,跳过what-if,这将需要在管道中或模板外的某个地方执行单独的步骤来检测是否存在,因为您不能在模板中这样做。

帮助吗?

最新更新