gpt4 book ai didi

azure 二头肌 : deploy modules in specific order

转载 作者:行者123 更新时间:2023-12-03 06:12:17 26 4
gpt4 key购买 nike

我有一个具有命名值资源的模块,另一个具有 api 和操作资源的模块。然后我有一个二头肌文件(main.bicep),它将调用这两个文件。缩短版本(只是为了更容易解释):

namedValue 模块:

param apimServiceName string
param namedvalues_prefix string
param aud string

resource apimService 'Microsoft.ApiManagement/service@2022-09-01-preview' existing = {
name:apimServiceName
}


//named values:
resource la_triggerurl 'Microsoft.ApiManagement/service/namedValues@2022-08-01' = {
parent: apimService
name: '${namedvalues_prefix}-url'
properties: {
displayName: '${namedvalues_prefix}-url'
secret: true
value: workflow_triggerUrl
}
}

//...

API模块:

param apimServiceName string
param apiName string


resource apimService 'Microsoft.ApiManagement/service@2022-09-01-preview' existing = {
name:apimServiceName
}


resource apiOperationSend 'Microsoft.ApiManagement/service/apis/operations@2022-09-01-preview' = {
parent: api
name: 'send'
properties: {
displayName: 'Send'
method: 'POST'
urlTemplate: '/send'
templateParameters: []
responses: []
}
}

resource apiPolicySend 'Microsoft.ApiManagement/service/apis/operations/policies@2022-09-01-preview' = {
parent: apiOperationSend
name: 'policy'
properties: {
value: loadTextContent('../Policies/policy.xml')
}
}

//main.bicep:

param aud string

var apimServiceName = 'apim'
var apimRg = 'apim-rg'


module namedValues 'Modules/namedvalues.bicep' = {
name: 'namedValue'
scope:resourceGroup(apimRg)
params: {
apimServiceName: apimServiceName
namedvalues_prefix: 'somePrefix'
aud:aud
}
}

// The api and its resources need to be deployed after the deployment of the named values
module apiModule 'Modules/apiAndOperations.bicep' = {
name:'apiDeployment'
scope:resourceGroup(apimRg)
params:{
apiName:'personnelfromoracleint'
apimServiceName:apimServiceName
}
}

问题是我需要在 api 模块之前部署命名值模块,因为这些命名值用于policy.xml 文件内的策略。

因此,在调用 apiModule 时,我尝试在 main.bicep 中添加 parent:namedValues 字段,但 VS code 给出了此错误:

The property "parent" is not allowed on objects of type "module". Permissible properties include "dependsOn"

当我尝试使用 dependsOn:namedValues 时,它给了我这个错误:

The property "dependsOn" expected a value of type "(module[] | (resource | module) | resource[])[]" but the provided value is of type "module"

对于如何解决这个问题有什么建议吗?

最佳答案

您可以使用资源中的 dependsOn block 来添加显式依赖项,但是如果您以正确的方式引用依赖资源,bicep 也可以通过为您构建依赖关系图来工作。这种隐式方法更好,并且需要更少的代码行。

例如。

output apimName string = apimService.name 添加到您的 api 模块。然后在您的namedValues声明中使用apiModule.outputs.apimName引用它。

module namedValues 'Modules/namedvalues.bicep' = {
name: 'namedValue'
scope:resourceGroup(apimRg)
params: {
apimServiceName: apiModule.outputs.apimName
namedvalues_prefix: 'somePrefix'
aud:aud
}
}

named values
module apiModule 'Modules/apiAndOperations.bicep' = {
name:'apiDeployment'
scope:resourceGroup(apimRg)
params:{
apiName:'personnelfromoracleint'
apimServiceName:apimServiceName
}
}

关于 azure 二头肌 : deploy modules in specific order,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76619435/

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