Skip to content

Commit

Permalink
adding resource provider features and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
sebassem committed Sep 10, 2023
1 parent e29d269 commit 36faa2b
Show file tree
Hide file tree
Showing 6 changed files with 490 additions and 100 deletions.
89 changes: 89 additions & 0 deletions .github/scripts/Register-SubResourceProviders.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
param(
[string]$subscriptionId,
[string]$resourceProviders,
[string]$resourceProvidersFeatures
)

$ErrorActionPreference = "SilentlyContinue"
# Selecting the right subscription
Select-AzSubscription -SubscriptionId $subscriptionId

# Defining variables
$providers = $resourceProviders | ConvertFrom-Json
$features = $resourceProvidersFeatures | ConvertFrom-Json
$failedProviders = ""
$failedFeatures = ""
$DeploymentScriptOutputs = @{}

#########################################
## Registering the resource providers
#########################################

foreach ($provider in $providers ) {
try {
$providerStatus = (Get-AzResourceProvider -ListAvailable | Where-Object ProviderNamespace -eq $provider).registrationState
# Check if the providered is registered
if ($providerStatus -ne 'Registered') {
Write-Output "`n Registering the '$provider' provider"
if (Register-AzResourceProvider -ProviderNamespace $provider) {
Write-Output "`n The '$provider' has been registered successfully"
}
else {
Write-Output "`n The '$provider' provider has not been registered successfully"
$failedProviders += ",$provider"
}
}
if ($failedProviders.length -gt 0) {
$output = $failedProviders.substring(1)
}
else {
$output = "N/A"
}
$DeploymentScriptOutputs["failedProviderRegistrations"] = $output
}
catch {
Write-Output "`n There was a problem registering the '$provider' provider. Please make sure this provider namespace is valid"
}
}

##################################################
## Registering the resource providers features
##################################################

if ($features.length -gt 0) {
foreach ($feature in $features) {
# Define variables
try {
$feature = (Get-AzProviderFeature -ListAvailable | Where-Object FeatureName -eq $feature)
$featureName = $feature.FeatureName
$featureStatus = $feature.RegistrationState
$featureProvider = $feature.ProviderName
# Check if the feature is registered
if ($featureStatus -eq 'NotRegistered') {
Write-Output "`n Registering the '$featureName' feature"
# Check if the feature's resource provider is registered, if not then register first
$providerStatus = (Get-AzResourceProvider -ListAvailable | Where-Object ProviderNamespace -eq $featureProvider).RegistrationState
if ($providerStatus -ne 'Registered') {
if (Register-AzResourceProvider -ProviderNamespace $featureProvider) {
Write-Output "`n The '$featureProvider' has been registered successfully"
Register-AzProviderFeature -FeatureName $featureName -ProviderNamespace $featureProvider
}
else {
Write-Output "`n The '$featureName' feature has not been registered successfully"
$failedFeatures += ",$featureName"
}
}
}
if ($failedFeatures.length -gt 0) {
$output = $failedFeatures.substring(1)
}
else {
$output = "N/A"
}
$DeploymentScriptOutputs["failedFeaturesRegistrations"] = $output
}
catch {
Write-Output "`n There was a problem registering the '$featureName' feature. Please make sure this feature name is valid"
}
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This is currently split logically into the following capabilities:
- Specify Custom DNS Servers
- Role assignments
- Tags
- Resource providers and resource providers features registration

> When creating Virtual Network peerings, be aware of the [limit of peerings per Virtual Network.](https://learn.microsoft.com/azure/azure-resource-manager/management/azure-subscription-service-limits?toc=%2Fazure%2Fvirtual-network%2Ftoc.json#azure-resource-manager-virtual-networking-limits)
Expand Down
190 changes: 190 additions & 0 deletions docs/wiki/Example-5-Hub-and-Spoke-With-RP-registration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
<!-- markdownlint-disable MD041 -->
## Example 5 - Landing Zone (Subscription) with a spoke Virtual Network peered to a Hub Virtual Network and resource providers registration

### Bicep Module Registry

Here is a simple example Bicep file for deploying a landing zone (Subscription) with a spoke Virtual Network peered to a Hub Virtual Network, resource providers and features registration using the [Bicep Module Registry](https://github.com/Azure/bicep-registry-modules):

```bicep
targetScope = 'managementGroup'
@description('Specifies the location for resources.')
param location string = 'uksouth'
module sub003 'br/public:lz/sub-vending:1.4.1' = {
name: 'sub-bicep-lz-vending-example-001'
params: {
subscriptionAliasEnabled: true
subscriptionBillingScope: '/providers/Microsoft.Billing/billingAccounts/1234567/enrollmentAccounts/123456'
subscriptionAliasName: 'sub-bicep-lz-vending-example-001'
subscriptionDisplayName: 'sub-bicep-lz-vending-example-001'
subscriptionTags: {
test: 'true'
}
subscriptionWorkload: 'Production'
subscriptionManagementGroupAssociationEnabled: true
subscriptionManagementGroupId: 'alz-landingzones-corp'
virtualNetworkEnabled: true
virtualNetworkLocation: location
virtualNetworkResourceGroupName: 'rsg-${location}-net-001'
virtualNetworkName: 'vnet-${location}-001'
virtualNetworkAddressSpace: [
'10.0.0.0/16'
]
virtualNetworkResourceGroupLockEnabled: false
virtualNetworkPeeringEnabled: true
hubNetworkResourceId: '/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/rsg-uks-net-hub-001/providers/Microsoft.Network/virtualNetworks/vnet-uks-hub-001'
resourceProviders : [
'Microsoft.Compute'
'Microsoft.AVS'
]
resourceProvidersFeatures: [
'AzureServicesVm'
'InGuestHotPatchVMPreview'
]
}
}
```

### ARM JSON Parameter File

Here is a simple example parameter file for deploying a landing zone (Subscription) with a spoke Virtual Network peered to a Hub Virtual Network, resource providers and features registration:

```json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"subscriptionAliasEnabled": {
"value": true
},
"subscriptionDisplayName": {
"value": "sub-bicep-lz-vending-example-001"
},
"subscriptionAliasName": {
"value": "sub-bicep-lz-vending-example-001"
},
"subscriptionBillingScope": {
"value": "providers/Microsoft.Billing/billingAccounts/1234567/enrollmentAccounts/123456"
},
"subscriptionWorkload": {
"value": "Production"
},
"existingSubscriptionId": {
"value": ""
},
"subscriptionManagementGroupAssociationEnabled": {
"value": true
},
"subscriptionManagementGroupId": {
"value": "alz-landingzones-corp"
},
"subscriptionTags": {
"value": {
"Cost-Center": "ABC123",
"Usage": "Example"
}
},
"virtualNetworkEnabled": {
"value": true
},
"virtualNetworkResourceGroupName": {
"value": "rg-networking-001"
},
"virtualNetworkResourceGroupTags": {
"value": {
"Cost-Center": "ABC123",
"Usage": "Example",
"Managed-By": "Platform Team"
}
},
"virtualNetworkResourceGroupLockEnabled": {
"value": true
},
"virtualNetworkLocation": {
"value": "uksouth"
},
"virtualNetworkName": {
"value": "vnet-example-001"
},
"virtualNetworkTags": {
"value": {
"Cost-Center": "ABC123",
"Usage": "Example",
"Managed-By": "Platform Team"
}
},
"virtualNetworkAddressSpace": {
"value": [
"10.0.0.0/16"
]
},
"virtualNetworkDnsServers": {
"value": [
"10.4.1.4",
"10.2.1.5"
]
},
"virtualNetworkDdosPlanId": {
"value": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/rg-hub-network-001/providers/Microsoft.Network/ddosProtectionPlans/ddos-001"
},
"virtualNetworkPeeringEnabled": {
"value": true
},
"hubNetworkResourceId": {
"value": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/rg-hub-network-001/providers/Microsoft.Network/virtualNetworks/vnet-hub-001"
},
"virtualNetworkUseRemoteGateways": {
"value": true
},
"virtualNetworkVwanAssociatedRouteTableResourceId": {
"value": ""
},
"virtualNetworkVwanPropagatedRouteTablesResourceIds": {
"value": []
},
"virtualNetworkVwanPropagatedLabels": {
"value": []
},
"roleAssignmentEnabled": {
"value": true
},
"roleAssignments": {
"value": [
{
"principalId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"definition": "Contributor",
"relativeScope": ""
},
{
"principalId": "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy",
"definition": "/providers/Microsoft.Authorization/roleDefinitions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"relativeScope": ""
},
{
"principalId": "zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz",
"definition": "Reader",
"relativeScope": "/resourceGroups/rg-networking-001"
}
]
},
"resourceProviders":{
"value":[
"Microsoft.Compute",
"Microsoft.AVS"
]
},
"resourceProvidersFeatures":{
"value":[
"AzureServicesVm",
"InGuestHotPatchVMPreview"
]
},
"disableTelemetry": {
"value": false
}
}
}
```

Back to [Examples](Examples)
Loading

0 comments on commit 36faa2b

Please sign in to comment.