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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .azuredevops/modulePipelines/ms.resources.tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ trigger:
include:
- '/.azuredevops/modulePipelines/ms.resources.tags.yml'
- '/.azuredevops/pipelineTemplates/*.yml'
- '/modules/resources/tag/*'
- '/modules/resources/tags/*'
- '/utilities/pipelines/*'
exclude:
- '/utilities/pipelines/deploymentRemoval/*'
Expand All @@ -39,7 +39,7 @@ variables:
- template: '../../settings.yml'
- group: 'PLATFORM_VARIABLES'
- name: modulePath
value: '/modules/resources/tag'
value: '/modules/resources/tags'

stages:
- template: /.azuredevops/pipelineTemplates/stages.module.yml
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ms.resources.tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ on:
- '.github/actions/templates/**'
- '.github/workflows/template.module.yml'
- '.github/workflows/ms.resources.tags.yml'
- 'modules/resources/tag/**'
- 'modules/resources/tags/**'
- 'utilities/pipelines/**'
- '!utilities/pipelines/deploymentRemoval/**'
- '!*/**/README.md'

env:
modulePath: 'modules/resources/tag'
modulePath: 'modules/resources/tags'
workflowPath: '.github/workflows/ms.resources.tags.yml'

concurrency:
Expand Down
158 changes: 158 additions & 0 deletions Set-CARMLFoldersForPBRSingular.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<#
.SYNOPSIS
Re-format the name of every CARML module to match the requirements of the Public Bicep Registry

.DESCRIPTION
The names are formatted as per the following rules:
- Add a '-' prefix to every upper-case character
- Make the entire name lower case

For example, it re-formats
- 'AppConfiguration\configurationStores\keyValues\deploy.bicep'
to
- app-configuration\configuration-stores\key-values\deploy.bicep

.PARAMETER ModulesFolderPath
Mandatory. The path to the modules who's folder names should be converted.

.EXAMPLE
Set-CARMLFoldersForPBRSingular -ModulesFolderPath 'C:\dev\ip\Azure-ResourceModules\ResourceModules\modules'

Convert all folders in path 'C:\dev\ip\Azure-ResourceModules\ResourceModules\modules'

.EXAMPLE
Set-CARMLFoldersForPBRSingular -ModulesFolderPath 'C:\dev\ip\GitHub\Azure\ResourceModules\modules' -WorkflowsPath 'C:\dev\ip\GitHub\Azure\ResourceModules\.github\workflows' -PipelinesPath 'C:\dev\ip\GitHub\Azure\ResourceModules\.azuredevops\modulePipelines' -UtilitiesPath 'C:\dev\ip\GitHub\Azure\ResourceModules\utilities' -Verbose

Convert all folders in path 'C:\dev\ip\Azure-ResourceModules\ResourceModules\modules' and replaces all pipeline, workflows and utility references

.EXAMPLE
Set-CARMLFoldersForPBRSingular -ResourceProviderPath 'C:\dev\ip\Azure-ResourceModules\ResourceModules\modules\KeyVault'

Convert all folders in path 'C:\dev\ip\Azure-ResourceModules\ResourceModules\modules\KeyVault' included

.NOTES
This script should only be run AFTER the 'Microsoft.' provider namespace prefix was removed.
Identifiers such as 'DBforPostgreSQL' becomes 'd-bfor-postgre-s-q-l' which should probably be manually reverted to 'db-for-postgre-sql'.
#>
function Set-CARMLFoldersForPBRSingular {

[CmdletBinding(SupportsShouldProcess = $true)]
param (
[Parameter(Mandatory = $true)]
[string] $ModulesFolderPath,

[Parameter(Mandatory = $false)]
[string] $ResourceProviderPath = '',

[Parameter(Mandatory = $false)]
[string] $WorkflowsPath = '',

[Parameter(Mandatory = $false)]
[string] $PipelinesPath = '',

[Parameter(Mandatory = $false)]
[string] $UtilitiesPath = '',

[Parameter(Mandatory = $false)]
[string] $ConversionFilePath = (Join-Path $PSScriptRoot '\rtMapping.jsonc')
)

$specialConversionHash = Get-Content -Raw $ConversionFilePath | ConvertFrom-Json -AsHashtable

$relevantFolderPaths = @()
# Get all module folder names
if ($ResourceProviderPath -ne '') {
$relevantFolderPaths += (Get-ChildItem -Path $ResourceProviderPath -Recurse -Directory).FullName | Where-Object {
$_ -notlike '*.bicep*' -and
$_ -notlike '*.shared*' -and
$_ -notlike '*.test*'
}
Write-Verbose ("relevantFolderPaths $relevantFolderPaths") -Verbose
Write-Verbose ("ResourceProviderPath $ResourceProviderPath") -Verbose
$relevantFolderPaths += $ResourceProviderPath
Write-Verbose ("relevantFolderPaths $relevantFolderPaths") -Verbose

} else {
$relevantFolderPaths = (Get-ChildItem -Path $ModulesFolderPath -Recurse -Directory).FullName | Where-Object {
$_ -notlike '*.bicep*' -and
$_ -notlike '*.shared*' -and
$_ -notlike '*.test*'
}
}
$relevantFolderPaths | Sort-Object -Descending

# Iterate on all folder names
foreach ($folderPath in $relevantFolderPaths) {

# Convert each folder name to its kebab-case
$folderName = Split-Path $folderPath -Leaf

if ($specialConversionHash.ContainsKey($folderName)) {
$newName = $specialConversionHash[$folderName]
} else {
# (?<!^): This is a negative lookbehind assertion that ensures the match is not at the beginning of the string. This is used to exclude the first character from being replaced.
# ([A-Z]): This captures any uppercase letter from A to Z using parentheses.
$newName = $folderName
#$newName = $newName.substring(0, 1).tolower() + $newName.substring(1)
}
Write-Verbose ("$folderName $newName") -Verbose

# Replace the name if the new name is not the same as the old
if ($newName -ine $folderName) {
if ($PSCmdlet.ShouldProcess(('Folder [{0}] to [{1}]' -f ((Split-Path $folderPath -Leaf)), $newName), 'Update')) {
$null = Rename-Item -Path $folderPath -NewName $newName -Force
}
}

# Replace local module references in files across the whole library

# Get file paths
$filePaths = (Get-ChildItem -Path $ModulesFolderPath -Recurse | Select-String "$folderName.*main.bicep" -List | Select-Object Path).Path

# Iterate on all files
foreach ($filePath in $filePaths) {
# Replace content
Write-Verbose (" $filePath") -Verbose
(Get-Content $filePath) -creplace "(/|')($folderName)/(.*main.bicep)", "`$1$newName/`$3" | Set-Content $filePath
}

# Replace local module references in workflows
if ($WorkflowsPath -ne '') {
# Get file paths
$workflowsfilePaths = (Get-ChildItem -Path $WorkflowsPath -Recurse | Select-String "modules.*$folderName" -List | Select-Object Path).Path

# Iterate on all files
foreach ($workflowsfilePath in $workflowsfilePaths) {
# Replace content
Write-Verbose (" $workflowsfilePath") -Verbose
(Get-Content $workflowsfilePath) -creplace "(modules.*)/($folderName)", "`$1/$newName" | Set-Content $workflowsfilePath
}
}

# Replace local module references in ado pipelines
if ($PipelinesPath -ne '') {
# Get file paths
$pipelinesfilePaths = (Get-ChildItem -Path $PipelinesPath -Recurse | Select-String "modules.*$folderName" -List | Select-Object Path).Path

# Iterate on all files
foreach ($pipelinesfilePath in $pipelinesfilePaths) {
# Replace content
Write-Verbose (" $pipelinesfilePath") -Verbose
(Get-Content $pipelinesfilePath) -creplace "(modules.*)/($folderName)", "`$1/$newName" | Set-Content $pipelinesfilePath
}
}

# Replace local module references in utilities
if ($UtilitiesPath -ne '') {
# Get file paths
$utilitiesFilePaths = (Get-ChildItem -Path $UtilitiesPath -Recurse | Select-String "modules.*$folderName" -List | Select-Object Path).Path

# Iterate on all files
foreach ($utilitiesFilePath in $utilitiesFilePaths) {
# Replace content
Write-Verbose (" $utilitiesFilePath") -Verbose
(Get-Content $utilitiesFilePath) -creplace "(modules.*)/($folderName)", "`$1/$newName" | Set-Content $utilitiesFilePath
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ The following module usage examples are retrieved from the content of the files
<summary>via Bicep module</summary>

```bicep
module domainServices './aad/domain-services/main.bicep' = {
module domainServices './aad/domain-service/main.bicep' = {
name: '${uniqueString(deployment().name, location)}-test-aaddscom'
params: {
// Required parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ The following module usage examples are retrieved from the content of the files
<summary>via Bicep module</summary>

```bicep
module servers './analysis-services/servers/main.bicep' = {
module servers './analysis-services/server/main.bicep' = {
name: '${uniqueString(deployment().name, location)}-test-asscom'
params: {
// Required parameters
Expand Down Expand Up @@ -279,7 +279,7 @@ module servers './analysis-services/servers/main.bicep' = {
<summary>via Bicep module</summary>

```bicep
module servers './analysis-services/servers/main.bicep' = {
module servers './analysis-services/server/main.bicep' = {
name: '${uniqueString(deployment().name)}-test-assmax'
params: {
// Required parameters
Expand Down Expand Up @@ -416,7 +416,7 @@ module servers './analysis-services/servers/main.bicep' = {
<summary>via Bicep module</summary>

```bicep
module servers './analysis-services/servers/main.bicep' = {
module servers './analysis-services/server/main.bicep' = {
name: '${uniqueString(deployment().name, location)}-test-assmin'
params: {
// Required parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ resource api 'Microsoft.ApiManagement/service/apis@2021-08-01' = {
}
}

module policy 'policies/main.bicep' = [for (policy, index) in policies: {
module policy 'policy/main.bicep' = [for (policy, index) in policies: {
name: '${deployment().name}-Policy-${index}'
params: {
apiManagementServiceName: apiManagementServiceName
Expand Down
22 changes: 11 additions & 11 deletions modules/api-management/service/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ resource service 'Microsoft.ApiManagement/service@2021-08-01' = {
}
}

module service_apis 'apis/main.bicep' = [for (api, index) in apis: {
module service_apis 'api/main.bicep' = [for (api, index) in apis: {
name: '${uniqueString(deployment().name, location)}-Apim-Api-${index}'
params: {
apiManagementServiceName: service.name
Expand Down Expand Up @@ -289,7 +289,7 @@ module service_apis 'apis/main.bicep' = [for (api, index) in apis: {
]
}]

module service_apiVersionSets 'api-version-sets/main.bicep' = [for (apiVersionSet, index) in apiVersionSets: {
module service_apiVersionSets 'api-version-set/main.bicep' = [for (apiVersionSet, index) in apiVersionSets: {
name: '${uniqueString(deployment().name, location)}-Apim-ApiVersionSet-${index}'
params: {
apiManagementServiceName: service.name
Expand All @@ -299,7 +299,7 @@ module service_apiVersionSets 'api-version-sets/main.bicep' = [for (apiVersionSe
}
}]

module service_authorizationServers 'authorization-servers/main.bicep' = [for (authorizationServer, index) in authorizationServerList: {
module service_authorizationServers 'authorization-server/main.bicep' = [for (authorizationServer, index) in authorizationServerList: {
name: '${uniqueString(deployment().name, location)}-Apim-AuthorizationServer-${index}'
params: {
apiManagementServiceName: service.name
Expand Down Expand Up @@ -329,7 +329,7 @@ module service_authorizationServers 'authorization-servers/main.bicep' = [for (a
}
}]

module service_backends 'backends/main.bicep' = [for (backend, index) in backends: {
module service_backends 'backend/main.bicep' = [for (backend, index) in backends: {
name: '${uniqueString(deployment().name, location)}-Apim-Backend-${index}'
params: {
apiManagementServiceName: service.name
Expand All @@ -350,7 +350,7 @@ module service_backends 'backends/main.bicep' = [for (backend, index) in backend
}
}]

module service_caches 'caches/main.bicep' = [for (cache, index) in caches: {
module service_caches 'cache/main.bicep' = [for (cache, index) in caches: {
name: '${uniqueString(deployment().name, location)}-Apim-Cache-${index}'
params: {
apiManagementServiceName: service.name
Expand All @@ -363,7 +363,7 @@ module service_caches 'caches/main.bicep' = [for (cache, index) in caches: {
}
}]

module service_identityProviders 'identity-providers/main.bicep' = [for (identityProvider, index) in identityProviders: {
module service_identityProviders 'identity-provider/main.bicep' = [for (identityProvider, index) in identityProviders: {
name: '${uniqueString(deployment().name, location)}-Apim-IdentityProvider-${index}'
params: {
apiManagementServiceName: service.name
Expand All @@ -383,7 +383,7 @@ module service_identityProviders 'identity-providers/main.bicep' = [for (identit
}
}]

module service_namedValues 'named-values/main.bicep' = [for (namedValue, index) in namedValues: {
module service_namedValues 'named-value/main.bicep' = [for (namedValue, index) in namedValues: {
name: '${uniqueString(deployment().name, location)}-Apim-NamedValue-${index}'
params: {
apiManagementServiceName: service.name
Expand All @@ -397,7 +397,7 @@ module service_namedValues 'named-values/main.bicep' = [for (namedValue, index)
}
}]

module service_portalsettings 'portalsettings/main.bicep' = [for (portalsetting, index) in portalsettings: {
module service_portalsettings 'portalsetting/main.bicep' = [for (portalsetting, index) in portalsettings: {
name: '${uniqueString(deployment().name, location)}-Apim-PortalSetting-${index}'
params: {
apiManagementServiceName: service.name
Expand All @@ -407,7 +407,7 @@ module service_portalsettings 'portalsettings/main.bicep' = [for (portalsetting,
}
}]

module service_policies 'policies/main.bicep' = [for (policy, index) in policies: {
module service_policies 'policy/main.bicep' = [for (policy, index) in policies: {
name: '${uniqueString(deployment().name, location)}-Apim-Policy-${index}'
params: {
apiManagementServiceName: service.name
Expand All @@ -417,7 +417,7 @@ module service_policies 'policies/main.bicep' = [for (policy, index) in policies
}
}]

module service_products 'products/main.bicep' = [for (product, index) in products: {
module service_products 'product/main.bicep' = [for (product, index) in products: {
name: '${uniqueString(deployment().name, location)}-Apim-Product-${index}'
params: {
apiManagementServiceName: service.name
Expand All @@ -437,7 +437,7 @@ module service_products 'products/main.bicep' = [for (product, index) in product
]
}]

module service_subscriptions 'subscriptions/main.bicep' = [for (subscription, index) in subscriptions: {
module service_subscriptions 'subscription/main.bicep' = [for (subscription, index) in subscriptions: {
name: '${uniqueString(deployment().name, location)}-Apim-Subscription-${index}'
params: {
apiManagementServiceName: service.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ resource product 'Microsoft.ApiManagement/service/products@2021-08-01' = {
}
}

module product_apis 'apis/main.bicep' = [for (api, index) in apis: {
module product_apis 'api/main.bicep' = [for (api, index) in apis: {
name: '${deployment().name}-Api-${index}'
params: {
apiManagementServiceName: apiManagementServiceName
Expand All @@ -77,7 +77,7 @@ module product_apis 'apis/main.bicep' = [for (api, index) in apis: {
}
}]

module product_groups 'groups/main.bicep' = [for (group, index) in groups: {
module product_groups 'group/main.bicep' = [for (group, index) in groups: {
name: '${deployment().name}-Group-${index}'
params: {
apiManagementServiceName: apiManagementServiceName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ The following module usage examples are retrieved from the content of the files
<summary>via Bicep module</summary>

```bicep
module configurationStores './app-configuration/configuration-stores/main.bicep' = {
module configurationStores './app-configuration/configuration-store/main.bicep' = {
name: '${uniqueString(deployment().name, location)}-test-acccom'
params: {
// Required parameters
Expand Down Expand Up @@ -477,7 +477,7 @@ module configurationStores './app-configuration/configuration-stores/main.bicep'
<summary>via Bicep module</summary>

```bicep
module configurationStores './app-configuration/configuration-stores/main.bicep' = {
module configurationStores './app-configuration/configuration-store/main.bicep' = {
name: '${uniqueString(deployment().name, location)}-test-accmin'
params: {
// Required parameters
Expand Down Expand Up @@ -522,7 +522,7 @@ module configurationStores './app-configuration/configuration-stores/main.bicep'
<summary>via Bicep module</summary>

```bicep
module configurationStores './app-configuration/configuration-stores/main.bicep' = {
module configurationStores './app-configuration/configuration-store/main.bicep' = {
name: '${uniqueString(deployment().name, location)}-test-accpe'
params: {
// Required parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ resource configurationStore 'Microsoft.AppConfiguration/configurationStores@2021
}
}

module configurationStore_keyValues 'key-values/main.bicep' = [for (keyValue, index) in keyValues: {
module configurationStore_keyValues 'key-value/main.bicep' = [for (keyValue, index) in keyValues: {
name: '${uniqueString(deployment().name, location)}-AppConfig-KeyValues-${index}'
params: {
appConfigurationName: configurationStore.name
Expand Down Expand Up @@ -224,7 +224,7 @@ module configurationStore_roleAssignments '.bicep/nested_roleAssignments.bicep'
}
}]

module configurationStore_privateEndpoints '../../network/private-endpoints/main.bicep' = [for (privateEndpoint, index) in privateEndpoints: {
module configurationStore_privateEndpoints '../../network/private-endpoint/main.bicep' = [for (privateEndpoint, index) in privateEndpoints: {
name: '${uniqueString(deployment().name, location)}-AppConfig-PrivateEndpoint-${index}'
params: {
groupIds: [
Expand Down
Loading