英文:
How to configure "All APIs" policy using Bicep?
问题
I configured APIM in Bicep like this:
resource apiManagement 'Microsoft.ApiManagement/service@2019-12-01' = {
name: appName
location: location
sku: {
name: 'Developer'
capacity: 1
}
identity: {
type: 'SystemAssigned'
}
properties: {
publisherEmail: publisherEmail
publisherName: publisherName
}
resource policy 'policies@2021-01-01-preview' = {
name: 'allApis'
properties: {
value: allOperationsPolicy
format: 'xml'
}
}
}
And I can create 'api-read' API with some policy using syntax like this:
resource apiRead 'Microsoft.ApiManagement/service/apis@2021-01-01-preview' = {
parent: apiManagement
name: 'api-read'
properties: {
displayName: 'API Read'
subscriptionRequired: true
path: 'read'
protocols: [
'https'
]
isCurrent: true
authenticationSettings: {
oAuth2: {
authorizationServerId: authServer.name
}
}
}
resource policyAllOperationsRead 'policies@2021-01-01-preview' = {
name: 'policy'
properties: {
value: myPolicyHere
format: 'xml'
}
}
}
But how can I add policy to All API's (global policy) using Bicep, to have it here?
I have tried like this:
resource apiManagement 'Microsoft.ApiManagement/service@2019-12-01' = {
name: appName
location: location
sku: {
name: 'Developer'
capacity: 1
}
identity: {
type: 'SystemAssigned'
}
properties: {
publisherEmail: publisherEmail
publisherName: publisherName
}
}
resource policy 'Microsoft.ApiManagement/service/apis/policies@2021-01-01-preview' = {
parent: apiManagement
name: 'allApis'
properties: {
value: allOperationsPolicy
format: 'xml'
}
}
But I got an error: "The property 'parent' expected a value of type 'Microsoft.ApiManagement/service/apis' but the provided value is of type 'Microsoft.ApiManagement/service@2019-12-01'."
英文:
I configured APIM in Bicep like this:
resource apiManagement 'Microsoft.ApiManagement/service@2019-12-01' = {
name: appName
location: location
sku: {
name: 'Developer'
capacity: 1
}
identity: {
type: 'SystemAssigned'
}
properties: {
publisherEmail: publisherEmail
publisherName: publisherName
}
resource policy 'policies@2021-01-01-preview' = {
name: 'allApis'
properties: {
value: allOperationsPolicy
format: 'xml'
}
}
}
And I can create 'api-read' API with some policy using syntax like this:
resource apiRead 'Microsoft.ApiManagement/service/apis@2021-01-01-preview' = {
parent: apiManagement
name: 'api-read'
properties: {
displayName: 'API Read'
subscriptionRequired: true
path: 'read'
protocols: [
'https'
]
isCurrent: true
authenticationSettings: {
oAuth2: {
authorizationServerId: authServer.name
}
}
}
resource policyAllOperationsRead 'policies@2021-01-01-preview' = {
name: 'policy'
properties: {
value: myPolicyHere
format: 'xml'
}
}
}
But how can I add policy to All API's (global policy) using Bicep, to have it here?
I have tried like this:
resource apiManagement 'Microsoft.ApiManagement/service@2019-12-01' = {
name: appName
location: location
sku: {
name: 'Developer'
capacity: 1
}
identity: {
type: 'SystemAssigned'
}
properties: {
publisherEmail: publisherEmail
publisherName: publisherName
}
}
resource policy 'Microsoft.ApiManagement/service/apis/policies@2021-01-01-preview' = {
parent: apiManagement
name: 'allApis'
properties: {
value: allOperationsPolicy
format: 'xml'
}
}
But I got error:
> The property "parent" expected a value of type "Microsoft.ApiManagement/service/apis" but the provided value is of type "Microsoft.ApiManagement/service@2019-12-01"
答案1
得分: 1
以下是翻译好的部分:
在我尝试之后,我能够这样做:
resource apiManagement 'Microsoft.ApiManagement/service@2019-12-01' = {
name: appName
location: location
sku: {
name: 'Developer'
capacity: 1
}
identity: {
type: 'SystemAssigned'
}
properties: {
publisherEmail: publisherEmail
publisherName: publisherName
}
resource policy 'policies@2021-01-01-preview' = {
name: 'policy'
properties: {
value: allOperationsPolicy
format: 'xml'
}
}
}
请注意,name 只能是 "policy"
英文:
After all I was able to do it like that:
resource apiManagement 'Microsoft.ApiManagement/service@2019-12-01' = {
name: appName
location: location
sku: {
name: 'Developer'
capacity: 1
}
identity: {
type: 'SystemAssigned'
}
properties: {
publisherEmail: publisherEmail
publisherName: publisherName
}
resource policy 'policies@2021-01-01-preview' = {
name: 'policy'
properties: {
value: allOperationsPolicy
format: 'xml'
}
}
}
Note that name can only be "policy"
答案2
得分: 0
查看文档,可以像这样为所有 API 添加策略:
resource policy 'Microsoft.ApiManagement/service/policies@2021-01-01-preview' = {
parent: apiManagement
name: 'allApis'
properties: {
value: allOperationsPolicy
format: 'xml'
}
}
英文:
Looking at the documentation, policies can be added for all apis like that:
resource policy 'Microsoft.ApiManagement/service/policies@2021-01-01-preview' = {
parent: apiManagement
name: 'allApis'
properties: {
value: allOperationsPolicy
format: 'xml'
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论