Skip to content

Commit 92c32c2

Browse files
Sample and Documentation Refinements (#5)
1 parent 40b761c commit 92c32c2

File tree

14 files changed

+85
-48
lines changed

14 files changed

+85
-48
lines changed

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ _Try it out, learn from it, apply it in your setups._
3535

3636
We provide several common architectural approaches to integrating APIM into your Azure ecosystem. While these are high-fidelity setups, they are not production-ready. Please refer to the [Azure API Management landing zone accelerator](https://learn.microsoft.com/azure/cloud-adoption-framework/scenarios/app-platform/api-management/landing-zone-accelerator) for up-to-date production setups.
3737

38-
- [Simple API Management](./infrastructure/simple-apim)
39-
- Just the basics with a publicly accessible API Management intance fronting your APIs. This is the innermost way to experience and experiment with the APIM policies.
40-
- [API Management & Container Apps](./infrastructure/apim-aca)
38+
- [Simple API Management](./infrastructure/simple-apim) (simple-apim)
39+
- Just the basics with a publicly accessible API Management intance fronting your APIs. This is the innermost way to experience and experiment with the APIM policies.
40+
41+
- [API Management & Container Apps](./infrastructure/apim-aca) (apim-aca)
4142
- APIs are often times implemented in containers that are running in Azure Container Apps. This architecture accesses the container apps publicly. It's beneficial to test both APIM and container app URLs here to contrast and compare experiences of API calls through and bypassing APIM. It is not intended to be a security baseline.
42-
- [Secure Front Door & API Management & Container Apps](./infrastructure/afd-apim)
43+
44+
- [Secure Front Door & API Management & Container Apps](./infrastructure/afd-apim) (afd-apim)
4345
- A higher-fidelity implementation of a secured setup in which Azure Front Door connects to APIM via the new private link integration. This traffic, once it traverses through Front Door, rides entirely on Microsoft-owned and operated networks. Similarly, the connection from APIM to Container Apps is secured but through a VNet configuration (it is also entirely possible to do this via private link). It's noteworthy that we are using APIM Standard V2 here as we need the ability to accept a private link from Front Door.
4446

4547
---
@@ -71,6 +73,13 @@ Run through the following steps to create a Python virtual environment before do
7173

7274
The first time you run a Jupyter notebook, you'll be asked to install the Jupyter kernel package (ipykernel).
7375

76+
### List of Samples
77+
78+
| Sample Name | Description | Supported Infrastructure(s) |
79+
|------------------|-----------------------------------------------------------------------------|--------------------------------------------|
80+
| [General](./samples/general) | Basic demonstration of APIM sample setup and policy usage. | All infrastructures |
81+
| [Load Balancing](./samples/load-balancing) | Example of APIM policy-based load balancing across backends. | apim-aca, afd-apim (with ACA) |
82+
7483
### Running a Sample
7584

7685
1. Locate the specific sample's `create.ipynb` file and adjust the parameters under the `User-defined Parameters` header as you see fit.

infrastructure/afd-apim/create.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@
5757
"if use_ACA:\n",
5858
" utils.print_info('ACA APIs will be created.')\n",
5959
"\n",
60-
" aca_backend_1_policy_xml = utils.policy_xml_replacement(ACA_BACKEND_1_XML_POLICY_PATH)\n",
61-
" aca_backend_2_policy_xml = utils.policy_xml_replacement(ACA_BACKEND_2_XML_POLICY_PATH)\n",
62-
" aca_backend_pool_policy_xml = utils.policy_xml_replacement(ACA_BACKEND_POOL_XML_POLICY_PATH)\n",
60+
" aca_backend_1_policy_xml = utils.read_policy_xml(ACA_BACKEND_1_XML_POLICY_PATH)\n",
61+
" aca_backend_2_policy_xml = utils.read_policy_xml(ACA_BACKEND_2_XML_POLICY_PATH)\n",
62+
" aca_backend_pool_policy_xml = utils.read_policy_xml(ACA_BACKEND_POOL_XML_POLICY_PATH)\n",
6363
"\n",
6464
" # Hello World (ACA Backend 1)\n",
6565
" api_hwaca_1_get = GET_APIOperation('This is a GET for Hello World on ACA Backend 1')\n",

infrastructure/afd-apim/main.bicep

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ module acaEnvModule '../../shared/bicep/modules/aca/v1/environment.bicep' = if (
136136
name: 'acaEnvModule'
137137
params: {
138138
name: 'cae-${resourceSuffix}'
139-
location: location
140139
logAnalyticsWorkspaceCustomerId: lawModule.outputs.customerId
141140
logAnalyticsWorkspaceSharedKey: lawModule.outputs.clientSecret
142141
subnetResourceId: acaSubnetResourceId
@@ -148,24 +147,16 @@ module acaModule1 '../../shared/bicep/modules/aca/v1/containerapp.bicep' = if (u
148147
name: 'acaModule-1'
149148
params: {
150149
name: 'ca-${resourceSuffix}-mockwebapi-1'
151-
location: location
152150
containerImage: IMG_MOCK_WEB_API
153151
environmentId: acaEnvModule.outputs.environmentId
154-
cpu: '0.5'
155-
memory: '1.0Gi'
156-
ingressPort: 8080
157152
}
158153
}
159154
module acaModule2 '../../shared/bicep/modules/aca/v1/containerapp.bicep' = if (useACA) {
160155
name: 'acaModule-2'
161156
params: {
162157
name: 'ca-${resourceSuffix}-mockwebapi-2'
163-
location: location
164158
containerImage: IMG_MOCK_WEB_API
165159
environmentId: acaEnvModule.outputs.environmentId
166-
cpu: '0.5'
167-
memory: '1.0Gi'
168-
ingressPort: 8080
169160
}
170161
}
171162

@@ -267,7 +258,6 @@ module apimDnsPrivateLinkModule '../../shared/bicep/modules/dns/v1/dns-private-l
267258
module acaDnsPrivateZoneModule '../../shared/bicep/modules/dns/v1/aca-dns-private-zone.bicep' = if (useACA && !empty(acaSubnetResourceId)) {
268259
name: 'acaDnsPrivateZoneModule'
269260
params: {
270-
location: location
271261
acaEnvironmentRandomSubdomain: acaEnvModule.outputs.environmentRandomSubdomain
272262
acaEnvironmentStaticIp: acaEnvModule.outputs.environmentStaticIp
273263
vnetId: vnetModule.outputs.vnetId
@@ -278,7 +268,6 @@ module acaDnsPrivateZoneModule '../../shared/bicep/modules/dns/v1/aca-dns-privat
278268
module afdModule '../../shared/bicep/modules/afd/v1/afd.bicep' = {
279269
name: 'afdModule'
280270
params: {
281-
location: 'global'
282271
resourceSuffix: resourceSuffix
283272
afdName: afdEndpointName
284273
fdeName: afdEndpointName

infrastructure/apim-aca/create.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@
4545
"# 3) Define the APIs and their operations and policies\n",
4646
"\n",
4747
"# Policies\n",
48-
"hello_world_policy_xml = utils.policy_xml_replacement(HELLO_WORLD_XML_POLICY_PATH)\n",
49-
"aca_backend_1_policy_xml = utils.policy_xml_replacement(ACA_BACKEND_1_XML_POLICY_PATH)\n",
50-
"aca_backend_2_policy_xml = utils.policy_xml_replacement(ACA_BACKEND_2_XML_POLICY_PATH)\n",
51-
"aca_backend_pool_policy_xml = utils.policy_xml_replacement(ACA_BACKEND_POOL_XML_POLICY_PATH)\n",
48+
"hello_world_policy_xml = utils.read_policy_xml(HELLO_WORLD_XML_POLICY_PATH)\n",
49+
"aca_backend_1_policy_xml = utils.read_policy_xml(ACA_BACKEND_1_XML_POLICY_PATH)\n",
50+
"aca_backend_2_policy_xml = utils.read_policy_xml(ACA_BACKEND_2_XML_POLICY_PATH)\n",
51+
"aca_backend_pool_policy_xml = utils.read_policy_xml(ACA_BACKEND_POOL_XML_POLICY_PATH)\n",
5252
"\n",
5353
"# Hello World (Root)\n",
5454
"api_hwroot_get = GET_APIOperation('This is a GET for Hello World in the root', hello_world_policy_xml)\n",

infrastructure/apim-aca/main.bicep

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ param location string = resourceGroup().location
99
param resourceSuffix string = uniqueString(subscription().id, resourceGroup().id)
1010

1111
param apimName string = 'apim-${resourceSuffix}'
12-
1312
param apimSku string
1413
param apis array = []
1514

@@ -59,26 +58,17 @@ module acaModule1 '../../shared/bicep/modules/aca/v1/containerapp.bicep' = {
5958
name: 'acaModule-1'
6059
params: {
6160
name: 'ca-${resourceSuffix}-mockwebapi-1'
62-
location: location
6361
containerImage: IMG_MOCK_WEB_API
6462
environmentId: acaEnvModule.outputs.environmentId
65-
cpu: '0.5'
66-
memory: '1.0Gi'
67-
ingressPort: 8080
68-
ingressExternal: true
6963
}
7064
}
65+
7166
module acaModule2 '../../shared/bicep/modules/aca/v1/containerapp.bicep' = {
7267
name: 'acaModule-2'
7368
params: {
7469
name: 'ca-${resourceSuffix}-mockwebapi-2'
75-
location: location
7670
containerImage: IMG_MOCK_WEB_API
7771
environmentId: acaEnvModule.outputs.environmentId
78-
cpu: '0.5'
79-
memory: '1.0Gi'
80-
ingressPort: 8080
81-
ingressExternal: true
8272
}
8373
}
8474

infrastructure/simple-apim/create.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"# 3) Define the APIs and their operations and policies\n",
4444
"\n",
4545
"# Policies\n",
46-
"hello_world_policy_xml = utils.policy_xml_replacement(HELLO_WORLD_XML_POLICY_PATH)\n",
46+
"hello_world_policy_xml = utils.read_policy_xml(HELLO_WORLD_XML_POLICY_PATH)\n",
4747
"\n",
4848
"# Hello World (Root)\n",
4949
"api_hwroot_get = GET_APIOperation('This is a GET for API 1', hello_world_policy_xml)\n",

samples/_TEMPLATE/create.ipynb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
"1. [LEARNING / EXPERIMENTATION OBJECTIVE 2]\n",
1919
"1. ...\n",
2020
"\n",
21+
"## Lab Components\n",
22+
"\n",
23+
"[DESCRIBE IN MORE DETAIL WHAT THIS LAB SETS UP AND HOW THIS BENEFITS THE LEARNER/USER.]\n",
24+
"\n",
2125
"## Configuration\n",
2226
"\n",
2327
"1. Decide which of the [Infrastructure Architectures](../../README.md#infrastructure-architectures) you wish to use.\n",
@@ -51,7 +55,8 @@
5155
"rg_location = 'eastus2'\n",
5256
"index = 1\n",
5357
"deployment = INFRASTRUCTURE.AFD_APIM_PE\n",
54-
"tags = ['TAG1', 'TAG2', '...'] // [ENTER DESCRIPTIVE TAG(S)]\n",
58+
"tags = ['tag1', 'tag2', '...'] # ENTER DESCRIPTIVE TAG(S)\n",
59+
"api_prefix = '' # OPTIONAL: ENTER A PREFIX FOR THE APIS TO REDUCE COLLISION POTENTIAL WITH OTHER SAMPLES\n",
5560
"\n",
5661
"# 2) Service-defined parameters (please do not change these)\n",
5762
"rg_name = utils.get_infra_rg_name(deployment, index)\n",
@@ -68,6 +73,7 @@
6873
"\n",
6974
"# APIs Array\n",
7075
"# apis: List[API] = [api1, apin]\n",
76+
"apis: List[API] = []\n",
7177
"\n",
7278
"utils.print_ok('Notebook initialized')"
7379
]
@@ -132,7 +138,7 @@
132138
"import utils\n",
133139
"from apimrequests import ApimRequests\n",
134140
"\n",
135-
"[ADD RELEVANT TESTS HERE]\n",
141+
"# [ADD RELEVANT TESTS HERE]\n",
136142
"\n",
137143
"# 1) Issue a direct request to API Management\n",
138144
"# reqsApim = ApimRequests(apim_gateway_url)\n",

samples/_TEMPLATE/main.bicep

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,27 @@ param apimName string = 'apim-${resourceSuffix}'
1212
param appInsightsName string = 'appi-${resourceSuffix}'
1313
param apis array = []
1414

15+
// [ADD RELEVANT PARAMETERS HERE]
1516

1617
// ------------------
1718
// RESOURCES
1819
// ------------------
1920

2021
// https://learn.microsoft.com/azure/templates/microsoft.insights/components
21-
resource appInsightsModule 'Microsoft.Insights/components@2020-02-02' existing = {
22+
resource appInsights 'Microsoft.Insights/components@2020-02-02' existing = {
2223
name: appInsightsName
2324
}
2425

25-
var appInsightsId = appInsightsModule.id
26-
var appInsightsInstrumentationKey = appInsightsModule.properties.InstrumentationKey
26+
var appInsightsId = appInsights.id
27+
var appInsightsInstrumentationKey = appInsights.properties.InstrumentationKey
2728

2829
// https://learn.microsoft.com/azure/templates/microsoft.apimanagement/service
2930
resource apimService 'Microsoft.ApiManagement/service@2024-06-01-preview' existing = {
3031
name: apimName
3132
}
3233

34+
// [ADD RELEVANT BICEP MODULES HERE]
35+
3336
// APIM APIs
3437
module apisModule '../../shared/bicep/modules/apim/v1/api.bicep' = [for api in apis: if(length(apis) > 0) {
3538
name: '${api.name}-${resourceSuffix}'
@@ -50,3 +53,4 @@ module apisModule '../../shared/bicep/modules/apim/v1/api.bicep' = [for api in a
5053
output apimServiceId string = apimService.id
5154
output apimServiceName string = apimService.name
5255
output apimResourceGatewayURL string = apimService.properties.gatewayUrl
56+
// [ADD RELEVANT OUTPUTS HERE]

shared/bicep/modules/afd/v1/afd.bicep

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
// PARAMETERS
1010
// ------------------------------
1111

12-
@description('Location to be used for resources. Defaults to the resource group location')
13-
param location string = resourceGroup().location
14-
1512
@description('The unique suffix to append. Defaults to a unique string based on subscription and resource group IDs.')
1613
param resourceSuffix string = uniqueString(subscription().id, resourceGroup().id)
1714

shared/bicep/modules/apim/v1/api.bicep

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
// PARAMETERS
1010
// ------------------------------
1111

12-
@description('Location to be used for resources. Defaults to the resource group location')
13-
param location string = resourceGroup().location
14-
1512
@description('The unique suffix to append. Defaults to a unique string based on subscription and resource group IDs.')
1613
param resourceSuffix string = uniqueString(subscription().id, resourceGroup().id)
1714

0 commit comments

Comments
 (0)