Skip to content

Commit 8bed53a

Browse files
CopilotEMaher
authored andcommitted
Use named values in round-trip logger overrides
1 parent c256116 commit 8bed53a

3 files changed

Lines changed: 88 additions & 14 deletions

File tree

tests/integration/all-resource-types/bicep/source-apim.bicep

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,38 @@ resource nvKeyVault 'Microsoft.ApiManagement/service/namedValues@2025-09-01-prev
437437
}
438438
}
439439

440+
resource nvAppInsightsKey 'Microsoft.ApiManagement/service/namedValues@2025-09-01-preview' = {
441+
parent: apim
442+
name: 'src-nv-appinsights-key'
443+
properties: {
444+
displayName: 'src-nv-appinsights-key'
445+
value: appInsights.properties.InstrumentationKey
446+
secret: true
447+
tags: ['all-resources', 'logger', 'appinsights']
448+
}
449+
}
450+
451+
resource nvEventHubName 'Microsoft.ApiManagement/service/namedValues@2025-09-01-preview' = {
452+
parent: apim
453+
name: 'src-nv-eventhub-name'
454+
properties: {
455+
displayName: 'src-nv-eventhub-name'
456+
value: eventHub.name
457+
tags: ['all-resources', 'logger', 'eventhub']
458+
}
459+
}
460+
461+
resource nvEventHubConnectionString 'Microsoft.ApiManagement/service/namedValues@2025-09-01-preview' = {
462+
parent: apim
463+
name: 'src-nv-eventhub-connection-string'
464+
properties: {
465+
displayName: 'src-nv-eventhub-connection-string'
466+
value: eventHubAuthRule.listKeys().primaryConnectionString
467+
secret: true
468+
tags: ['all-resources', 'logger', 'eventhub']
469+
}
470+
}
471+
440472
// --- Tags ---
441473
resource tagEnv 'Microsoft.ApiManagement/service/tags@2025-09-01-preview' = {
442474
parent: apim
@@ -562,25 +594,30 @@ resource backendPool 'Microsoft.ApiManagement/service/backends@2025-09-01-previe
562594
resource loggerAppInsights 'Microsoft.ApiManagement/service/loggers@2025-09-01-preview' = {
563595
parent: apim
564596
name: 'src-logger-appinsights'
597+
dependsOn: [nvAppInsightsKey]
565598
properties: {
566599
loggerType: 'applicationInsights'
567600
description: 'Application Insights logger for BVT'
568601
resourceId: appInsights.id
569602
credentials: {
570-
instrumentationKey: appInsights.properties.InstrumentationKey
603+
instrumentationKey: '{{src-nv-appinsights-key}}'
571604
}
572605
}
573606
}
574607

575608
resource loggerEventHub 'Microsoft.ApiManagement/service/loggers@2025-09-01-preview' = {
576609
parent: apim
577610
name: 'src-logger-eventhub'
611+
dependsOn: [
612+
nvEventHubName
613+
nvEventHubConnectionString
614+
]
578615
properties: {
579616
loggerType: 'azureEventHub'
580617
description: 'Event Hub logger for BVT'
581618
credentials: {
582-
name: eventHub.name
583-
connectionString: eventHubAuthRule.listKeys().primaryConnectionString
619+
name: '{{src-nv-eventhub-name}}'
620+
connectionString: '{{src-nv-eventhub-connection-string}}'
584621
}
585622
}
586623
}

tests/integration/all-resource-types/expected-structure.json

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"directories": {
2020
"namedValues": {
21-
"minCount": 3,
21+
"minCount": 6,
2222
"expected": [
2323
{
2424
"name": "src-nv-plain",
@@ -56,6 +56,42 @@
5656
}
5757
},
5858
"notes": "KeyVault reference type"
59+
},
60+
{
61+
"name": "src-nv-appinsights-key",
62+
"files": ["namedValueInformation.json"],
63+
"spotChecks": {
64+
"namedValueInformation.json": {
65+
"properties.displayName": "src-nv-appinsights-key",
66+
"properties.secret": true,
67+
"properties.tags": ["all-resources", "logger", "appinsights"]
68+
}
69+
},
70+
"notes": "Logger Application Insights instrumentation key stored as a secret named value"
71+
},
72+
{
73+
"name": "src-nv-eventhub-name",
74+
"files": ["namedValueInformation.json"],
75+
"spotChecks": {
76+
"namedValueInformation.json": {
77+
"properties.displayName": "src-nv-eventhub-name",
78+
"properties.value": "src-apim-logs",
79+
"properties.secret": false,
80+
"properties.tags": ["all-resources", "logger", "eventhub"]
81+
}
82+
}
83+
},
84+
{
85+
"name": "src-nv-eventhub-connection-string",
86+
"files": ["namedValueInformation.json"],
87+
"spotChecks": {
88+
"namedValueInformation.json": {
89+
"properties.displayName": "src-nv-eventhub-connection-string",
90+
"properties.secret": true,
91+
"properties.tags": ["all-resources", "logger", "eventhub"]
92+
}
93+
},
94+
"notes": "Logger Event Hub connection string stored as a secret named value"
5995
}
6096
]
6197
},
@@ -184,21 +220,22 @@
184220
"spotChecks": {
185221
"loggerInformation.json": {
186222
"properties.loggerType": "applicationInsights",
187-
"properties.credentials.instrumentationKey": "exists"
223+
"properties.credentials.instrumentationKey": "{{src-nv-appinsights-key}}"
188224
}
189225
},
190-
"notes": "Instrumentationkey should be redacted"
226+
"notes": "Instrumentation key should be referenced via NamedValue"
191227
},
192228
{
193229
"name": "src-logger-eventhub",
194230
"files": ["loggerInformation.json"],
195231
"spotChecks": {
196232
"loggerInformation.json": {
197233
"properties.loggerType": "azureEventHub",
198-
"properties.credentials.name": "src-apim-logs"
234+
"properties.credentials.name": "{{src-nv-eventhub-name}}",
235+
"properties.credentials.connectionString": "{{src-nv-eventhub-connection-string}}"
199236
}
200237
},
201-
"notes": "Connection string should be redacted"
238+
"notes": "Event Hub logger credentials should be referenced via NamedValues"
202239
}
203240
]
204241
},

tests/integration/all-resource-types/phases/run-phase4-create-overrides.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,16 @@ namedValues:
104104
src-nv-keyvault:
105105
keyVault:
106106
secretIdentifier: "${targetKvUri}secrets/tgt-secret-value"
107+
src-nv-appinsights-key:
108+
value: "$targetAiKey"
109+
src-nv-eventhub-name:
110+
value: "tgt-eh-logs"
111+
src-nv-eventhub-connection-string:
112+
value: "$targetEhConnStr"
107113
108114
loggers:
109115
src-logger-appinsights:
110116
resourceId: "$targetAiResourceId"
111-
credentials:
112-
instrumentationKey: "$targetAiKey"
113-
src-logger-eventhub:
114-
credentials:
115-
name: "tgt-eh-logs"
116-
connectionString: "$targetEhConnStr"
117117
"@
118118

119119
$overrideYaml | Set-Content -Path $overrideFile -Encoding utf8

0 commit comments

Comments
 (0)