From a9de499dfc089ad6694f6f4f17006ed0f6f39e9c Mon Sep 17 00:00:00 2001 From: Alexander Sehr Date: Fri, 28 Jul 2023 19:17:33 +0200 Subject: [PATCH] [Modules] Simplified DNS Forwarding Rule Input Parameter (#3413) * Refactored parameter * Added output * Update to latest * Update to latest * Update to latest * Temp disabled prefix & suffix settings * Tried to escape value * Update to latest * Enhanced output * Fallback * Update to latest --- .../jobs.validateModulePester.yml | 2 +- .../templates/validateModulePester/action.yml | 2 +- .../.test/common/main.test.bicep | 6 +-- .../.test/min/main.test.bicep | 6 +-- .../network/dns-forwarding-rulesets/README.md | 26 ++++-------- .../dns-forwarding-rulesets/main.bicep | 6 ++- .../network/dns-forwarding-rulesets/main.json | 42 +++++++++++++++++-- .../sharedScripts/Add-YamlListToFile.ps1 | 2 +- 8 files changed, 59 insertions(+), 33 deletions(-) diff --git a/.azuredevops/pipelineTemplates/jobs.validateModulePester.yml b/.azuredevops/pipelineTemplates/jobs.validateModulePester.yml index 5c5564d51a..477c8a2204 100644 --- a/.azuredevops/pipelineTemplates/jobs.validateModulePester.yml +++ b/.azuredevops/pipelineTemplates/jobs.validateModulePester.yml @@ -154,7 +154,7 @@ jobs: } Write-Verbose 'Invoke test with' -Verbose - Write-Verbose ($testContainerData | ConvertTo-Json | Out-String) -Verbose + Write-Verbose ($testContainerData | ConvertTo-Json -Depth 5 | Out-String) -Verbose Invoke-Pester -Configuration @{ Run = @{ diff --git a/.github/actions/templates/validateModulePester/action.yml b/.github/actions/templates/validateModulePester/action.yml index b793f23396..cb1849e828 100644 --- a/.github/actions/templates/validateModulePester/action.yml +++ b/.github/actions/templates/validateModulePester/action.yml @@ -98,7 +98,7 @@ runs: } Write-Verbose 'Invoke test with' -Verbose - Write-Verbose ($pesterConfiguration | ConvertTo-Json | Out-String) -Verbose + Write-Verbose ($pesterConfiguration | ConvertTo-Json -Depth 5 | Out-String) -Verbose $testResults = Invoke-Pester -Configuration $pesterConfiguration diff --git a/modules/network/dns-forwarding-rulesets/.test/common/main.test.bicep b/modules/network/dns-forwarding-rulesets/.test/common/main.test.bicep index b66d8c663a..9c4793baaa 100644 --- a/modules/network/dns-forwarding-rulesets/.test/common/main.test.bicep +++ b/modules/network/dns-forwarding-rulesets/.test/common/main.test.bicep @@ -52,10 +52,8 @@ module testDeployment '../../main.bicep' = { params: { enableDefaultTelemetry: enableDefaultTelemetry name: '${namePrefix}${serviceShort}001' - dnsResolverOutboundEndpointIds: [ - { - id: nestedDependencies.outputs.dnsResolverOutboundEndpointsId - } + dnsResolverOutboundEndpointResourceIds: [ + nestedDependencies.outputs.dnsResolverOutboundEndpointsId ] vNetLinks: [ nestedDependencies.outputs.virtualNetworkResourceId diff --git a/modules/network/dns-forwarding-rulesets/.test/min/main.test.bicep b/modules/network/dns-forwarding-rulesets/.test/min/main.test.bicep index 4a38532a0c..43e250ddf4 100644 --- a/modules/network/dns-forwarding-rulesets/.test/min/main.test.bicep +++ b/modules/network/dns-forwarding-rulesets/.test/min/main.test.bicep @@ -51,10 +51,8 @@ module testDeployment '../../main.bicep' = { params: { enableDefaultTelemetry: enableDefaultTelemetry name: '${namePrefix}${serviceShort}001' - dnsResolverOutboundEndpointIds: [ - { - id: nestedDependencies.outputs.dnsResolverOutboundEndpointsResourceId - } + dnsResolverOutboundEndpointResourceIds: [ + nestedDependencies.outputs.dnsResolverOutboundEndpointsResourceId ] } } diff --git a/modules/network/dns-forwarding-rulesets/README.md b/modules/network/dns-forwarding-rulesets/README.md index 9febdf8164..28ff5533db 100644 --- a/modules/network/dns-forwarding-rulesets/README.md +++ b/modules/network/dns-forwarding-rulesets/README.md @@ -26,7 +26,7 @@ This template deploys an dns forwarding ruleset. | Parameter Name | Type | Description | | :-- | :-- | :-- | -| `dnsResolverOutboundEndpointIds` | array | The reference to the DNS resolver outbound endpoints that are used to route DNS queries matching the forwarding rules in the ruleset to the target DNS servers. | +| `dnsResolverOutboundEndpointResourceIds` | array | The reference to the DNS resolver outbound endpoints that are used to route DNS queries matching the forwarding rules in the ruleset to the target DNS servers. | | `name` | string | Name of the DNS Forwarding Ruleset. | **Optional parameters** @@ -173,10 +173,8 @@ module dnsForwardingRulesets './network/dns-forwarding-rulesets/main.bicep' = { name: '${uniqueString(deployment().name, location)}-test-ndfrscom' params: { // Required parameters - dnsResolverOutboundEndpointIds: [ - { - id: '' - } + dnsResolverOutboundEndpointResourceIds: [ + '' ] name: 'ndfrscom001' // Non-required parameters @@ -228,11 +226,9 @@ module dnsForwardingRulesets './network/dns-forwarding-rulesets/main.bicep' = { "contentVersion": "1.0.0.0", "parameters": { // Required parameters - "dnsResolverOutboundEndpointIds": { + "dnsResolverOutboundEndpointResourceIds": { "value": [ - { - "id": "" - } + "" ] }, "name": { @@ -300,10 +296,8 @@ module dnsForwardingRulesets './network/dns-forwarding-rulesets/main.bicep' = { name: '${uniqueString(deployment().name, location)}-test-ndfrsmin' params: { // Required parameters - dnsResolverOutboundEndpointIds: [ - { - id: '' - } + dnsResolverOutboundEndpointResourceIds: [ + '' ] name: 'ndfrsmin001' // Non-required parameters @@ -325,11 +319,9 @@ module dnsForwardingRulesets './network/dns-forwarding-rulesets/main.bicep' = { "contentVersion": "1.0.0.0", "parameters": { // Required parameters - "dnsResolverOutboundEndpointIds": { + "dnsResolverOutboundEndpointResourceIds": { "value": [ - { - "id": "" - } + "" ] }, "name": { diff --git a/modules/network/dns-forwarding-rulesets/main.bicep b/modules/network/dns-forwarding-rulesets/main.bicep index 019265e9aa..f5003f3141 100644 --- a/modules/network/dns-forwarding-rulesets/main.bicep +++ b/modules/network/dns-forwarding-rulesets/main.bicep @@ -20,7 +20,7 @@ param roleAssignments array = [] param tags object = {} @description('Required. The reference to the DNS resolver outbound endpoints that are used to route DNS queries matching the forwarding rules in the ruleset to the target DNS servers.') -param dnsResolverOutboundEndpointIds array +param dnsResolverOutboundEndpointResourceIds array @description('Optional. Array of forwarding rules.') param forwardingRules array = [] @@ -48,7 +48,9 @@ resource dnsForwardingRuleset 'Microsoft.Network/dnsForwardingRulesets@2022-07-0 location: location tags: tags properties: { - dnsResolverOutboundEndpoints: dnsResolverOutboundEndpointIds + dnsResolverOutboundEndpoints: [for dnsResolverOutboundEndpointResourceId in dnsResolverOutboundEndpointResourceIds: { + id: dnsResolverOutboundEndpointResourceId + }] } } diff --git a/modules/network/dns-forwarding-rulesets/main.json b/modules/network/dns-forwarding-rulesets/main.json index 84b1bb7f67..628015ba92 100644 --- a/modules/network/dns-forwarding-rulesets/main.json +++ b/modules/network/dns-forwarding-rulesets/main.json @@ -1,6 +1,13 @@ { "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", + "metadata": { + "_generator": { + "name": "bicep", + "version": "0.18.4.5664", + "templateHash": "6120226132023367818" + } + }, "parameters": { "name": { "type": "string", @@ -42,7 +49,7 @@ "description": "Optional. Tags of the resource." } }, - "dnsResolverOutboundEndpointIds": { + "dnsResolverOutboundEndpointResourceIds": { "type": "array", "metadata": { "description": "Required. The reference to the DNS resolver outbound endpoints that are used to route DNS queries matching the forwarding rules in the ruleset to the target DNS servers." @@ -92,7 +99,15 @@ "location": "[parameters('location')]", "tags": "[parameters('tags')]", "properties": { - "dnsResolverOutboundEndpoints": "[parameters('dnsResolverOutboundEndpointIds')]" + "copy": [ + { + "name": "dnsResolverOutboundEndpoints", + "count": "[length(parameters('dnsResolverOutboundEndpointResourceIds'))]", + "input": { + "id": "[parameters('dnsResolverOutboundEndpointResourceIds')[copyIndex('dnsResolverOutboundEndpoints')]]" + } + } + ] } }, { @@ -142,6 +157,13 @@ "template": { "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", + "metadata": { + "_generator": { + "name": "bicep", + "version": "0.18.4.5664", + "templateHash": "15974628788273884251" + } + }, "parameters": { "name": { "type": "string", @@ -279,6 +301,13 @@ "template": { "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", + "metadata": { + "_generator": { + "name": "bicep", + "version": "0.18.4.5664", + "templateHash": "15625871831521285672" + } + }, "parameters": { "dnsForwardingRulesetName": { "type": "string", @@ -400,6 +429,13 @@ "template": { "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", + "metadata": { + "_generator": { + "name": "bicep", + "version": "0.18.4.5664", + "templateHash": "5621141103615196068" + } + }, "parameters": { "principalIds": { "type": "array", @@ -570,4 +606,4 @@ "value": "[reference(resourceId('Microsoft.Network/dnsForwardingRulesets', parameters('name')), '2022-07-01', 'full').location]" } } -} +} \ No newline at end of file diff --git a/utilities/pipelines/sharedScripts/Add-YamlListToFile.ps1 b/utilities/pipelines/sharedScripts/Add-YamlListToFile.ps1 index fdb8121bb0..b81cec6cad 100644 --- a/utilities/pipelines/sharedScripts/Add-YamlListToFile.ps1 +++ b/utilities/pipelines/sharedScripts/Add-YamlListToFile.ps1 @@ -71,7 +71,7 @@ function Add-YamlListToFile { # Process key value pairs in the list foreach ($Key in ($KeyValuePair.Keys.split(' ') | Sort-Object)) { Write-Verbose ('Setting environment variable [{0}] with value [{1}]' -f $Key, $KeyValuePair[$Key]) -Verbose - Write-Output "$Key=$($KeyValuePair[$Key])" | Out-File -FilePath $OutputFilePath -Encoding utf-8 -Append + Write-Output "$Key=$($KeyValuePair[$Key])" | Out-File -FilePath $OutputFilePath -Encoding 'utf-8' -Append } }