我想使用 bicep 在 Azure 上使用 PowerShell 创建一些自动化运行手册。为此,我需要下面列出的一些自定义模块。
var modules = [
'Microsoft.Graph.Authentication'
'Microsoft.Graph.Groups'
'Microsoft.Graph.Mail'
'Microsoft.Graph.Planner'
'Microsoft.Graph.Teams'
'Microsoft.Graph.Users'
'Microsoft.Graph.Users.Actions'
]
以下是我创建模块的方式:
resource automationResource 'Microsoft.Automation/automationAccounts@2022-08-08' = {
// Some other properties
resource moduleResources 'modules' = [for module in modules: {
name: module
properties: {
contentLink: {
uri: 'https://www.powershellgallery.com/api/v2/'
}
}
}]
}
当我将其部署到 Azure 时,所有模块都出现下一个错误:
{
"status": "Failed",
"error": {
"code": "ResourceDeploymentFailure",
"target": "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Automation/automationAccounts/xxx/modules/Microsoft.Graph.Teams",
"message": "The resource write operation failed to complete successfully, because it reached terminal provisioning state 'Failed'."
}
}
为什么模块不会添加到自动化帐户中?
这里有几件事:
这里,所有的包都依赖于
Microsoft.Graph.Authentication
包。
实现这一目标的最简单方法是按顺序部署模块,但速度会很慢:
var modules = [
{
name: 'Microsoft.Graph.Authentication'
version: '2.0.0-preview8'
}
{
name: 'Microsoft.Graph.Groups'
version: '2.0.0-preview8'
}
{
name: 'Microsoft.Graph.Mail'
version: '2.0.0-preview8'
}
{
name: 'Microsoft.Graph.Planner'
version: '2.0.0-preview8'
}
{
name: 'Microsoft.Graph.Teams'
version: '2.0.0-preview8'
}
{
name: 'Microsoft.Graph.Users'
version: '2.0.0-preview8'
}
{
name: 'Microsoft.Graph.Users.Actions'
version: '2.0.0-preview8'
}
]
resource automationAccount 'Microsoft.Automation/automationAccounts@2022-08-08' existing = {
name: automationAccountName
}
@batchSize(1)
resource automationAccountModules 'Microsoft.Automation/automationAccounts/modules@2022-08-08' = [for module in modules: {
parent: automationAccount
name: module.name
properties: {
contentLink: {
uri: toLower('https://devopsgallerystorage.blob.core.windows.net:443/packages/${module.name}.${module.version}.nupkg')
}
}
}]
或者您可以在导入其他模块之前导入
Microsoft.Graph.Authentication
:
var modules = [
{
name: 'Microsoft.Graph.Authentication'
version: '2.0.0-preview8'
}
{
name: 'Microsoft.Graph.Groups'
version: '2.0.0-preview8'
}
{
name: 'Microsoft.Graph.Mail'
version: '2.0.0-preview8'
}
{
name: 'Microsoft.Graph.Planner'
version: '2.0.0-preview8'
}
{
name: 'Microsoft.Graph.Teams'
version: '2.0.0-preview8'
}
{
name: 'Microsoft.Graph.Users'
version: '2.0.0-preview8'
}
{
name: 'Microsoft.Graph.Users.Actions'
version: '2.0.0-preview8'
}
]
resource automationAccount 'Microsoft.Automation/automationAccounts@2022-08-08' existing = {
name: automationAccountName
}
var authPackage = first(modules)
resource authModule 'Microsoft.Automation/automationAccounts/modules@2022-08-08' = {
parent: automationAccount
name: authPackage.name
properties: {
contentLink: {
uri: toLower('https://devopsgallerystorage.blob.core.windows.net:443/packages/${authPackage.name}.${authPackage.version}.nupkg')
}
}
}
var otherPackages = skip(modules, 1)
resource automationAccountModules 'Microsoft.Automation/automationAccounts/modules@2022-08-08' = [for module in otherPackages: {
dependsOn: [ authModule ]
parent: automationAccount
name: module.name
properties: {
contentLink: {
uri: toLower('https://devopsgallerystorage.blob.core.windows.net:443/packages/${module.name}.${module.version}.nupkg')
}
}
}]