Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 41 additions & 24 deletions src/lib/azure/services/api-management/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,30 +272,47 @@ export class AzureApiManagementManager {
)
createAzureTfOutput(`${id}-${operation.displayName}-${operation.method}-apimOperationId`, scope, apimOperation.id)

if (props.policyXmlContent) {
const apimOperationPolicy = new ApiManagementApiOperationPolicy(
scope,
`${id}-apim-api-operation-policy-${operation.displayName}-${operation.method}`,
{
apiManagementName: apiManagementApi.apiManagementName,
resourceGroupName: apiManagementApi.resourceGroupName,
apiName: apiManagementApi.name,
operationId: apimOperation.operationId,
xmlContent: props.policyXmlContent,
}
)

createAzureTfOutput(
`${id}-${operation.displayName}-${operation.method}-apimOperationPolicyFriendlyUniqueId`,
scope,
apimOperationPolicy.friendlyUniqueId
)
createAzureTfOutput(
`${id}-${operation.displayName}-${operation.method}-apimOperationPolicyId`,
scope,
apimOperationPolicy.id
)
}
const policyXmlContent = `<policies>
<inbound>
<base />
${operation.cacheInboundPolicy ?? ''}
${props.commonInboundPolicyXml ?? ''}
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
${operation.cacheOutboundPolicy ?? ''}
${props.commonOutboundPolicyXml ?? ''}
</outbound>
<on-error>
<base />
</on-error>
</policies>`

const apimOperationPolicy = new ApiManagementApiOperationPolicy(
scope,
`${id}-apim-api-operation-policy-${operation.displayName}-${operation.method}`,
{
apiManagementName: apiManagementApi.apiManagementName,
resourceGroupName: apiManagementApi.resourceGroupName,
apiName: apiManagementApi.name,
operationId: apimOperation.operationId,
xmlContent: policyXmlContent,
}
)

createAzureTfOutput(
`${id}-${operation.displayName}-${operation.method}-apimOperationPolicyFriendlyUniqueId`,
scope,
apimOperationPolicy.friendlyUniqueId
)
createAzureTfOutput(
`${id}-${operation.displayName}-${operation.method}-apimOperationPolicyId`,
scope,
apimOperationPolicy.id
)
})

return apiManagementApi
Expand Down
11 changes: 8 additions & 3 deletions src/lib/azure/services/api-management/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ApiManagementBackendConfig } from '@cdktf/provider-azurerm/lib/api-mana
import { ApiManagementCustomDomainConfig } from '@cdktf/provider-azurerm/lib/api-management-custom-domain'
import { ApiManagementApiConfig } from '@cdktf/provider-azurerm/lib/api-management-api'
import { ApiManagementApiOperationConfig } from '@cdktf/provider-azurerm/lib/api-management-api-operation'
import { ApiManagementApiOperationPolicyConfig } from '@cdktf/provider-azurerm/lib/api-management-api-operation-policy'

export interface ApiManagementProps extends ApiManagementConfig {}

Expand All @@ -14,10 +13,16 @@ export interface ApiManagementBackendProps extends ApiManagementBackendConfig {
export interface ApiManagementCustomDomainProps extends ApiManagementCustomDomainConfig {}

export interface ApiManagementApiProps extends ApiManagementApiConfig {
operations: ApiManagementApiOperationConfig[]
policyXmlContent?: ApiManagementApiOperationPolicyConfig['xmlContent']
operations: ApiManagementApiOperationProps[]
commonInboundPolicyXml: string
commonOutboundPolicyXml: string
}

export interface ApiManagementV2Props extends ApiManagementConfig {
body: any
}

export interface ApiManagementApiOperationProps extends ApiManagementApiOperationConfig {
cacheInboundPolicy: string
cacheOutboundPolicy: string
}
20 changes: 2 additions & 18 deletions src/test/azure/services/api-management-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,11 @@ class TestCommonConstruct extends CommonAzureConstruct {
}
)

const policyXmlContent = `<policies>
<inbound>
<base />
<set-backend-service id="apim-generated-policy" backend-id="${this.apiManagementBackend.name}" />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>`

this.apiManagementManager.createApiManagementApi(`test-api-management-${this.props.stage}`, this, {
...this.props.testApiManagementApi,
apiManagementName: this.apiManagement.name,
resourceGroupName: this.apiManagement.resourceGroupName,
policyXmlContent,
commonInboundPolicyXml: `<set-backend-service id="apim-generated-policy" backend-id="${this.apiManagementBackend.name}" />`,
})

this.apiManagementManager.createApiManagementCustomDomain(`test-api-management-${this.props.stage}`, this, {
Expand Down Expand Up @@ -269,7 +253,7 @@ describe('TestAzureApiManagementConstruct', () => {
'${azurerm_api_management_api_operation.test-api-management-dev-apim-api-operation-test-get.operation_id}',
resource_group_name: '${azurerm_api_management_api.test-api-management-dev-am-api.resource_group_name}',
xml_content:
'<policies>\n <inbound>\n <base />\n <set-backend-service id="apim-generated-policy" backend-id="${azurerm_api_management_backend.test-api-management-dev-am-be.name}" />\n </inbound>\n <backend>\n <base />\n </backend>\n <outbound>\n <base />\n </outbound>\n <on-error>\n <base />\n </on-error>\n </policies>',
'<policies>\n <inbound>\n <base />\n \n <set-backend-service id="apim-generated-policy" backend-id="${azurerm_api_management_backend.test-api-management-dev-am-be.name}" />\n </inbound>\n <backend>\n <base />\n </backend>\n <outbound>\n <base />\n \n \n </outbound>\n <on-error>\n <base />\n </on-error>\n </policies>',
})
})
})
Expand Down