diff --git a/modules/authorization/locks/resource-group/README.md b/modules/authorization/locks/resource-group/README.md index 9403abe16f..146e48ed25 100644 --- a/modules/authorization/locks/resource-group/README.md +++ b/modules/authorization/locks/resource-group/README.md @@ -1,4 +1,4 @@ -# Authorization Locks (Resource Group scope) `[Microsoft.Authorization/locks/resourceGroup]` +# Authorization Locks (Resource Group scope) `[Microsoft.Authorization/locks]` This module deploys an Authorization Lock at a Resource Group scope. diff --git a/modules/authorization/locks/subscription/README.md b/modules/authorization/locks/subscription/README.md index 3358d5abb2..35fe0fd8ca 100644 --- a/modules/authorization/locks/subscription/README.md +++ b/modules/authorization/locks/subscription/README.md @@ -1,4 +1,4 @@ -# Authorization Locks (Subscription scope) `[Microsoft.Authorization/locks/subscription]` +# Authorization Locks (Subscription scope) `[Microsoft.Authorization/locks]` This module deploys an Authorization Lock at a Subscription scope. diff --git a/modules/authorization/policy-assignments/management-group/README.md b/modules/authorization/policy-assignments/management-group/README.md index 4605093988..086b1d38ea 100644 --- a/modules/authorization/policy-assignments/management-group/README.md +++ b/modules/authorization/policy-assignments/management-group/README.md @@ -1,4 +1,4 @@ -# Policy Assignments (Management Group scope) `[Microsoft.Authorization/policyAssignments/managementGroup]` +# Policy Assignments (Management Group scope) `[Microsoft.Authorization/policyAssignments]` This module deploys a Policy Assignment at a Management Group scope. diff --git a/modules/authorization/policy-assignments/resource-group/README.md b/modules/authorization/policy-assignments/resource-group/README.md index ae3023add4..6ed90b07ac 100644 --- a/modules/authorization/policy-assignments/resource-group/README.md +++ b/modules/authorization/policy-assignments/resource-group/README.md @@ -1,4 +1,4 @@ -# Policy Assignments (Resource Group scope) `[Microsoft.Authorization/policyAssignments/resourceGroup]` +# Policy Assignments (Resource Group scope) `[Microsoft.Authorization/policyAssignments]` This module deploys a Policy Assignment at a Resource Group scope. diff --git a/modules/authorization/policy-assignments/subscription/README.md b/modules/authorization/policy-assignments/subscription/README.md index b2fbe1c249..26810db431 100644 --- a/modules/authorization/policy-assignments/subscription/README.md +++ b/modules/authorization/policy-assignments/subscription/README.md @@ -1,4 +1,4 @@ -# Policy Assignments (Subscription scope) `[Microsoft.Authorization/policyAssignments/subscription]` +# Policy Assignments (Subscription scope) `[Microsoft.Authorization/policyAssignments]` This module deploys a Policy Assignment at a Subscription scope. diff --git a/modules/authorization/policy-definitions/management-group/README.md b/modules/authorization/policy-definitions/management-group/README.md index 028d713044..01780427c6 100644 --- a/modules/authorization/policy-definitions/management-group/README.md +++ b/modules/authorization/policy-definitions/management-group/README.md @@ -1,4 +1,4 @@ -# Policy Definitions (Management Group scope) `[Microsoft.Authorization/policyDefinitions/managementGroup]` +# Policy Definitions (Management Group scope) `[Microsoft.Authorization/policyDefinitions]` This module deploys a Policy Definition at a Management Group scope. diff --git a/modules/authorization/policy-definitions/subscription/README.md b/modules/authorization/policy-definitions/subscription/README.md index 69b94bbaae..2557236387 100644 --- a/modules/authorization/policy-definitions/subscription/README.md +++ b/modules/authorization/policy-definitions/subscription/README.md @@ -1,4 +1,4 @@ -# Policy Definitions (Subscription scope) `[Microsoft.Authorization/policyDefinitions/subscription]` +# Policy Definitions (Subscription scope) `[Microsoft.Authorization/policyDefinitions]` This module deploys a Policy Definition at a Subscription scope. diff --git a/modules/authorization/policy-exemptions/management-group/README.md b/modules/authorization/policy-exemptions/management-group/README.md index fc9c7002ef..1bfb787eab 100644 --- a/modules/authorization/policy-exemptions/management-group/README.md +++ b/modules/authorization/policy-exemptions/management-group/README.md @@ -1,4 +1,4 @@ -# Policy Exemptions (Management Group scope) `[Microsoft.Authorization/policyExemptions/managementGroup]` +# Policy Exemptions (Management Group scope) `[Microsoft.Authorization/policyExemptions]` This module deploys a Policy Exemption at a Management Group scope. diff --git a/modules/authorization/policy-exemptions/resource-group/README.md b/modules/authorization/policy-exemptions/resource-group/README.md index fc5480482b..7fd6faa68a 100644 --- a/modules/authorization/policy-exemptions/resource-group/README.md +++ b/modules/authorization/policy-exemptions/resource-group/README.md @@ -1,4 +1,4 @@ -# Policy Exemptions (Resource Group scope) `[Microsoft.Authorization/policyExemptions/resourceGroup]` +# Policy Exemptions (Resource Group scope) `[Microsoft.Authorization/policyExemptions]` This module deploys a Policy Exemption at a Resource Group scope. diff --git a/modules/authorization/policy-exemptions/subscription/README.md b/modules/authorization/policy-exemptions/subscription/README.md index ff5d45ee74..82e45d2349 100644 --- a/modules/authorization/policy-exemptions/subscription/README.md +++ b/modules/authorization/policy-exemptions/subscription/README.md @@ -1,4 +1,4 @@ -# Policy Exemptions (Subscription scope) `[Microsoft.Authorization/policyExemptions/subscription]` +# Policy Exemptions (Subscription scope) `[Microsoft.Authorization/policyExemptions]` This module deploys a Policy Exemption at a Subscription scope. diff --git a/modules/authorization/policy-set-definitions/management-group/README.md b/modules/authorization/policy-set-definitions/management-group/README.md index 8d0b575925..40de7bcd60 100644 --- a/modules/authorization/policy-set-definitions/management-group/README.md +++ b/modules/authorization/policy-set-definitions/management-group/README.md @@ -1,4 +1,4 @@ -# Policy Set Definitions (Initiatives) (Management Group scope) `[Microsoft.Authorization/policySetDefinitions/managementGroup]` +# Policy Set Definitions (Initiatives) (Management Group scope) `[Microsoft.Authorization/policySetDefinitions]` This module deploys a Policy Set Definition (Initiative) at a Management Group scope. diff --git a/modules/authorization/policy-set-definitions/subscription/README.md b/modules/authorization/policy-set-definitions/subscription/README.md index 801df21abe..64b2597fe0 100644 --- a/modules/authorization/policy-set-definitions/subscription/README.md +++ b/modules/authorization/policy-set-definitions/subscription/README.md @@ -1,4 +1,4 @@ -# Policy Set Definitions (Initiatives) (Subscription scope) `[Microsoft.Authorization/policySetDefinitions/subscription]` +# Policy Set Definitions (Initiatives) (Subscription scope) `[Microsoft.Authorization/policySetDefinitions]` This module deploys a Policy Set Definition (Initiative) at a Subscription scope. diff --git a/modules/authorization/role-assignments/management-group/README.md b/modules/authorization/role-assignments/management-group/README.md index 1f7344c5cc..911ac2c8e6 100644 --- a/modules/authorization/role-assignments/management-group/README.md +++ b/modules/authorization/role-assignments/management-group/README.md @@ -1,4 +1,4 @@ -# Role Assignments (Management Group scope) `[Microsoft.Authorization/roleAssignments/managementGroup]` +# Role Assignments (Management Group scope) `[Microsoft.Authorization/roleAssignments]` This module deploys a Role Assignment at a Management Group scope. diff --git a/modules/authorization/role-assignments/resource-group/README.md b/modules/authorization/role-assignments/resource-group/README.md index 5dbf130f99..a2cd0959a5 100644 --- a/modules/authorization/role-assignments/resource-group/README.md +++ b/modules/authorization/role-assignments/resource-group/README.md @@ -1,4 +1,4 @@ -# Role Assignments (Resource Group scope) `[Microsoft.Authorization/roleAssignments/resourceGroup]` +# Role Assignments (Resource Group scope) `[Microsoft.Authorization/roleAssignments]` This module deploys a Role Assignment at a Resource Group scope. diff --git a/modules/authorization/role-assignments/subscription/README.md b/modules/authorization/role-assignments/subscription/README.md index dc31e1c223..58b5d059a4 100644 --- a/modules/authorization/role-assignments/subscription/README.md +++ b/modules/authorization/role-assignments/subscription/README.md @@ -1,4 +1,4 @@ -# Role Assignments (Subscription scope) `[Microsoft.Authorization/roleAssignments/subscription]` +# Role Assignments (Subscription scope) `[Microsoft.Authorization/roleAssignments]` This module deploys a Role Assignment at a Subscription scope. diff --git a/modules/authorization/role-definitions/management-group/README.md b/modules/authorization/role-definitions/management-group/README.md index 0d04a82ce6..02a11b45bc 100644 --- a/modules/authorization/role-definitions/management-group/README.md +++ b/modules/authorization/role-definitions/management-group/README.md @@ -1,4 +1,4 @@ -# Role Definitions (Management Group scope) `[Microsoft.Authorization/roleDefinitions/managementGroup]` +# Role Definitions (Management Group scope) `[Microsoft.Authorization/roleDefinitions]` This module deploys a Role Definition at a Management Group scope. diff --git a/modules/authorization/role-definitions/resource-group/README.md b/modules/authorization/role-definitions/resource-group/README.md index 0202e15bd4..924c4eb112 100644 --- a/modules/authorization/role-definitions/resource-group/README.md +++ b/modules/authorization/role-definitions/resource-group/README.md @@ -1,4 +1,4 @@ -# Role Definitions (Resource Group scope) `[Microsoft.Authorization/roleDefinitions/resourceGroup]` +# Role Definitions (Resource Group scope) `[Microsoft.Authorization/roleDefinitions]` This module deploys a Role Definition at a Resource Group scope. diff --git a/modules/authorization/role-definitions/subscription/README.md b/modules/authorization/role-definitions/subscription/README.md index daa72da52d..3bbd9894b0 100644 --- a/modules/authorization/role-definitions/subscription/README.md +++ b/modules/authorization/role-definitions/subscription/README.md @@ -1,4 +1,4 @@ -# Role Definitions (Subscription scope) `[Microsoft.Authorization/roleDefinitions/subscription]` +# Role Definitions (Subscription scope) `[Microsoft.Authorization/roleDefinitions]` This module deploys a Role Definition at a Subscription scope. diff --git a/modules/cache/redis/README.md b/modules/cache/redis/README.md index fed7da134b..1d43d64d3c 100644 --- a/modules/cache/redis/README.md +++ b/modules/cache/redis/README.md @@ -1,4 +1,4 @@ -# Redis Cache `[Microsoft.Cache/redis]` +# Redis Cache `[Microsoft.Cache/Redis]` This module deploys a Redis Cache. diff --git a/modules/db-for-postgre-sql/flexible-servers/README.md b/modules/db-for-postgre-sql/flexible-servers/README.md index fbb46909d1..a015e34910 100644 --- a/modules/db-for-postgre-sql/flexible-servers/README.md +++ b/modules/db-for-postgre-sql/flexible-servers/README.md @@ -1,4 +1,4 @@ -# DBforPostgreSQL Flexible Servers `[Microsoft.DBforPostgreSQL/flexibleServers]` +# DBforPostgreSQL Flexible Servers `[Microsoft.DBForPostgreSql/flexibleServers]` This module deploys a DBforPostgreSQL Flexible Server. diff --git a/modules/db-for-postgre-sql/flexible-servers/configurations/README.md b/modules/db-for-postgre-sql/flexible-servers/configurations/README.md index 5a98fdc548..3cb7920198 100644 --- a/modules/db-for-postgre-sql/flexible-servers/configurations/README.md +++ b/modules/db-for-postgre-sql/flexible-servers/configurations/README.md @@ -1,4 +1,4 @@ -# DBforPostgreSQL Flexible Server Configurations `[Microsoft.DBforPostgreSQL/flexibleServers/configurations]` +# DBforPostgreSQL Flexible Server Configurations `[Microsoft.DBForPostgreSql/flexibleServers/configurations]` This module deploys a DBforPostgreSQL Flexible Server Configuration. diff --git a/modules/db-for-postgre-sql/flexible-servers/databases/README.md b/modules/db-for-postgre-sql/flexible-servers/databases/README.md index 700caebc88..130f01f648 100644 --- a/modules/db-for-postgre-sql/flexible-servers/databases/README.md +++ b/modules/db-for-postgre-sql/flexible-servers/databases/README.md @@ -1,4 +1,4 @@ -# DBforPostgreSQL Flexible Server Databases `[Microsoft.DBforPostgreSQL/flexibleServers/databases]` +# DBforPostgreSQL Flexible Server Databases `[Microsoft.DBForPostgreSql/flexibleServers/databases]` This module deploys a DBforPostgreSQL Flexible Server Database. diff --git a/modules/db-for-postgre-sql/flexible-servers/firewall-rules/README.md b/modules/db-for-postgre-sql/flexible-servers/firewall-rules/README.md index d4f092e9f6..ef855d0f03 100644 --- a/modules/db-for-postgre-sql/flexible-servers/firewall-rules/README.md +++ b/modules/db-for-postgre-sql/flexible-servers/firewall-rules/README.md @@ -1,4 +1,4 @@ -# DBforPostgreSQL Flexible Server Firewall Rules `[Microsoft.DBforPostgreSQL/flexibleServers/firewallRules]` +# DBforPostgreSQL Flexible Server Firewall Rules `[Microsoft.DBForPostgreSql/flexibleServers/firewallRules]` This module deploys a DBforPostgreSQL Flexible Server Firewall Rule. diff --git a/modules/insights/private-link-scopes/README.md b/modules/insights/private-link-scopes/README.md index e935e8ef41..118453a44e 100644 --- a/modules/insights/private-link-scopes/README.md +++ b/modules/insights/private-link-scopes/README.md @@ -1,4 +1,4 @@ -# Azure Monitor Private Link Scopes `[microsoft.insights/privateLinkScopes]` +# Azure Monitor Private Link Scopes `[Microsoft.Insights/privateLinkScopes]` This module deploys an Azure Monitor Private Link Scope. diff --git a/modules/network/express-route-gateway/README.md b/modules/network/express-route-gateway/README.md index 24c65dd7b2..a545f8a6a2 100644 --- a/modules/network/express-route-gateway/README.md +++ b/modules/network/express-route-gateway/README.md @@ -1,4 +1,4 @@ -# Express Route Gateways `[Microsoft.Network/expressRouteGateway]` +# Express Route Gateways `[Microsoft.Network/expressRouteGateways]` This module deploys an Express Route Gateway. diff --git a/modules/policy-insights/remediations/management-group/README.md b/modules/policy-insights/remediations/management-group/README.md index 4062ada6fd..7a747eb168 100644 --- a/modules/policy-insights/remediations/management-group/README.md +++ b/modules/policy-insights/remediations/management-group/README.md @@ -1,4 +1,4 @@ -# Policy Insights Remediations (Management Group scope) `[Microsoft.PolicyInsights/remediations/managementGroup]` +# Policy Insights Remediations (Management Group scope) `[Microsoft.PolicyInsights/remediations]` This module deploys a Policy Insights Remediation on a Management Group scope. diff --git a/modules/policy-insights/remediations/resource-group/README.md b/modules/policy-insights/remediations/resource-group/README.md index b43098b6fb..88c4aa8f58 100644 --- a/modules/policy-insights/remediations/resource-group/README.md +++ b/modules/policy-insights/remediations/resource-group/README.md @@ -1,4 +1,4 @@ -# Policy Insights Remediations (Resource Group scope) `[Microsoft.PolicyInsights/remediations/resourceGroup]` +# Policy Insights Remediations (Resource Group scope) `[Microsoft.PolicyInsights/remediations]` This module deploys a Policy Insights Remediation on a Resource Group scope. diff --git a/modules/policy-insights/remediations/subscription/README.md b/modules/policy-insights/remediations/subscription/README.md index 9e8e882bca..82a91bb72b 100644 --- a/modules/policy-insights/remediations/subscription/README.md +++ b/modules/policy-insights/remediations/subscription/README.md @@ -1,4 +1,4 @@ -# Policy Insights Remediations (Subscription scope) `[Microsoft.PolicyInsights/remediations/subscription]` +# Policy Insights Remediations (Subscription scope) `[Microsoft.PolicyInsights/remediations]` This module deploys a Policy Insights Remediation on a Subscription scope. diff --git a/modules/resources/tags/resource-groups/README.md b/modules/resources/tags/resource-groups/README.md index 20dd11ea03..3deb2a74cf 100644 --- a/modules/resources/tags/resource-groups/README.md +++ b/modules/resources/tags/resource-groups/README.md @@ -1,4 +1,4 @@ -# Resources Tags Resource Group `[Microsoft.Resources/tags/resourceGroups]` +# Resources Tags Resource Group `[Microsoft.Resources/tags]` This module deploys a Resource Tag on a Resource Group scope. diff --git a/modules/resources/tags/subscriptions/README.md b/modules/resources/tags/subscriptions/README.md index 6e65f77d45..ab74b2d81c 100644 --- a/modules/resources/tags/subscriptions/README.md +++ b/modules/resources/tags/subscriptions/README.md @@ -1,4 +1,4 @@ -# Resources Tags Subscription Scope `[Microsoft.Resources/tags/subscriptions]` +# Resources Tags Subscription Scope `[Microsoft.Resources/tags]` This module deploys a Resource Tag on a Subscription scope. diff --git a/modules/security/azure-security-center/README.md b/modules/security/azure-security-center/README.md index 97575003c3..d132f0662b 100644 --- a/modules/security/azure-security-center/README.md +++ b/modules/security/azure-security-center/README.md @@ -1,4 +1,4 @@ -# Azure Security Center (Defender for Cloud) `[Microsoft.Security/azureSecurityCenter]` +# Azure Security Center (Defender for Cloud) `[Microsoft.Security/azuresecuritycenter]` This module deploys an Azure Security Center (Defender for Cloud) Configuration. diff --git a/utilities/tools/Set-ModuleReadMe.ps1 b/utilities/tools/Set-ModuleReadMe.ps1 index d042751c41..38820b8e75 100644 --- a/utilities/tools/Set-ModuleReadMe.ps1 +++ b/utilities/tools/Set-ModuleReadMe.ps1 @@ -1417,22 +1417,11 @@ function Initialize-ReadMe { [hashtable] $TemplateFileContent ) + . (Join-Path $PSScriptRoot 'helper' 'ConvertTo-ModuleResourceType.ps1') + $moduleName = $TemplateFileContent.metadata.name $moduleDescription = $TemplateFileContent.metadata.description - - $splitHyphens = $FullModuleIdentifier.split('-') - $splitHyphens = $splitHyphens | ForEach-Object { $_.substring(0, 1).toupper() + $_.substring(1) } - $splitHyphens = $splitHyphens -join '' - $fullResourceType = 'Microsoft.{0}' -f $splitHyphens.Replace('-', '') - - # Resolve resource type as per used API name to use matching casing - $relevantResourceTypeObjects = (Get-NestedResourceList $TemplateFileContent).type | Select-Object -Unique - $formattedResourceType = $relevantResourceTypeObjects | Where-Object { $_ -eq $fullResourceType } - - if (-not $formattedResourceType) { - Write-Warning "Did not find module [$FullModuleIdentifier] formatted as [$fullResourceType] in the module template's resource types." - $formattedResourceType = $fullResourceType - } + $formattedResourceType = ConvertTo-ModuleResourceType -ResourceIdentifier $FullModuleIdentifier if (-not (Test-Path $ReadMeFilePath) -or ([String]::IsNullOrEmpty((Get-Content $ReadMeFilePath -Raw)))) { diff --git a/utilities/tools/helper/ConvertTo-ModuleResourceType.ps1 b/utilities/tools/helper/ConvertTo-ModuleResourceType.ps1 new file mode 100644 index 0000000000..e18892fc21 --- /dev/null +++ b/utilities/tools/helper/ConvertTo-ModuleResourceType.ps1 @@ -0,0 +1,57 @@ +<# +.SYNOPSIS +Converts a parent or child module folder path to the corresponding resource type. + +.DESCRIPTION +Converts a parent or child module folder path to the corresponding resource type. + +.PARAMETER ResourceIdentifier +Mandatory. The resource identifier to search for, i.e. the relative module file path starting from the resource provider folder. + +.EXAMPLE +ConvertTo-ModuleResourceType -ResourceIdentifier 'storage/storage-account'. + +Returns 'Microsoft.Storage/storageAccounts'. + +.EXAMPLE +ConvertTo-ModuleResourceType -ResourceIdentifier 'storage/storage-account/blob-service/container/immutability-policy'. + +Returns 'Microsoft.Storage/storageAccounts/blobServices/containers/immutabilityPolicies'. +#> +function ConvertTo-ModuleResourceType { + + [CmdletBinding()] + param ( + [Parameter(Mandatory = $true)] + [string] $ResourceIdentifier + ) + + . (Join-Path $PSScriptRoot 'Get-SpecsAlignedResourceName.ps1') + + $provider, $parentType, $childTypeString = $ResourceIdentifier -Split '[\/|\\]', 3 + $parentResourceIdentifier = $provider, $parentType -join '/' + + $fullParentResourceType = Get-SpecsAlignedResourceName -ResourceIdentifier $parentResourceIdentifier + + if (-not $childTypeString) { + $fullResourceType = $fullParentResourceType + } else { + $childTypeArray = $childTypeString -split '\/' + + $innerResourceType = $fullParentResourceType + foreach ($childType in $childTypeArray) { + # Additional check for child types non existing on their own (e.g. sites/hybridConnectionNamespaces does not exist, sites/hybridConnectionNamespaces/relays does) + $innerResourceTypeLeafReduced = Get-ReducedWordString -StringToReduce ($innerResourceType -Split '[\/|\\]')[-1] + $childTypeReduced = Get-ReducedWordString -StringToReduce $childType + if ($innerResourceTypeLeafReduced -eq $childTypeReduced) { + break + } + + $innerResourceType = $innerResourceType.Replace('Microsoft.', '', 'OrdinalIgnoreCase'), $childType -join '/' + $fullResourceType = Get-SpecsAlignedResourceName -ResourceIdentifier $innerResourceType + $innerResourceType = $fullResourceType + } + } + + return $fullResourceType +} diff --git a/utilities/tools/helper/Get-SpecsAlignedResourceName.ps1 b/utilities/tools/helper/Get-SpecsAlignedResourceName.ps1 index ecd6cf72f3..14ce9c7c7f 100644 --- a/utilities/tools/helper/Get-SpecsAlignedResourceName.ps1 +++ b/utilities/tools/helper/Get-SpecsAlignedResourceName.ps1 @@ -67,25 +67,54 @@ function Get-SpecsAlignedResourceName { $reducedResourceIdentifier = $ResourceIdentifier -replace '-' - $rawProviderNamespace = $reducedResourceIdentifier.Split('/')[0] + $rawProviderNamespace, $rawResourceType = $reducedResourceIdentifier -Split '[\/|\\]', 2 # e.g. 'keyvault' & 'vaults/keys' + $foundProviderNamespaceMatches = ($specs.Keys | Sort-Object) | Where-Object { $_ -like "Microsoft.$rawProviderNamespace*" } if (-not $foundProviderNamespaceMatches) { $providerNamespace = "Microsoft.$rawProviderNamespace" - Write-Warning "Failed to identifier provider namespace [$rawProviderNamespace]. Falling back to [$providerNamespace]." + Write-Warning "Failed to identify provider namespace [$rawProviderNamespace]. Falling back to [$providerNamespace]." } else { $providerNamespace = ($foundProviderNamespaceMatches.Count -eq 1) ? $foundProviderNamespaceMatches : $foundProviderNamespaceMatches[0] } $innerResourceTypes = $specs[$providerNamespace].Keys | Sort-Object - $rawResourceType = Get-ReducedWordString -StringToReduce ($reducedResourceIdentifier -replace ('{0}/' -f ($reducedResourceIdentifier.Split('/')[0])), '') - $foundResourceTypeMatches = $innerResourceTypes | Where-Object { $_ -like "$rawResourceType*" } + $rawResourceTypeReduced = Get-ReducedWordString -StringToReduce $rawResourceType + $foundResourceTypeMatches = $innerResourceTypes | Where-Object { $_ -like "$rawResourceTypeReduced*" } if (-not $foundResourceTypeMatches) { - $resourceType = $reducedResourceIdentifier.Split('/')[0] + $resourceType = $reducedResourceIdentifier.Split('/')[1] Write-Warning "Failed to identify resource type [$rawResourceType] in provider namespace [$providerNamespace]. Fallback to [$resourceType]." + } elseif ($foundResourceTypeMatches.Count -eq 1) { + $resourceType = $foundResourceTypeMatches } else { - $resourceType = ($foundResourceTypeMatches.Count -eq 1) ? $foundResourceTypeMatches : $foundResourceTypeMatches[0] + # If more than one specs resource type matches the input resource type core string, get all specs core strings and check exact match + # This is to avoid that e.g. web/connection falls to Microsoft.Web/connectionGateways instead of Microsoft.Web/connections + foreach ($foundResourceTypeMatch in $foundResourceTypeMatches) { + $foundResourceTypeMatchReduced = Get-ReducedWordString -StringToReduce $foundResourceTypeMatch + if ($rawResourceTypeReduced -eq $foundResourceTypeMatchReduced) { + $resourceType = $foundResourceTypeMatch + break + } + } + + if (-not $resourceType) { + # Try removing last split of each match, then reduce to core and compare + # This is needed to deal cases such as Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers where backupFabrics does not exist on its own + foreach ($foundResourceTypeMatch in $foundResourceTypeMatches) { + $foundResourceTypeMatch = $foundResourceTypeMatch.SubString(0, $foundResourceTypeMatch.LastIndexOf('/')) + $foundResourceTypeMatchReduced = Get-ReducedWordString -StringToReduce $foundResourceTypeMatch + if ($rawResourceTypeReduced -eq $foundResourceTypeMatchReduced) { + $resourceType = $foundResourceTypeMatch + break + } + } + # Finally fallback to first match in the list + if (-not $resourceType) { + $resourceType = $foundResourceTypeMatches[0] + Write-Warning "Failed to find exact match between core matched resource types and [$rawResourceTypeReduced]. Fallback to first ResourceType in the match list [$resourceType]." + } + } } return "$providerNamespace/$resourceType"