Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upped aliases API version to non-preview #198

Merged
merged 13 commits into from
Apr 2, 2022
10 changes: 8 additions & 2 deletions infra-as-code/bicep/CRML/subscriptionAlias/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ The module requires the following inputs:
| ----------- | ---- | ----------- | ------------ | ------- | -------- |
parSubscriptionName | string | Name of the subscription to be created. Will also be used as the alias name. Whilst you can use any name you like we recommend it to be: all lowercase, no spaces, alphanumeric and hyphens only. | Yes | `sub-example-001` | None, must be provided. |
parSubscriptionBillingScope | string | The full resource ID of billing scope associated to the EA, MCA or MPA account you wish to create the subscription in. | Yes | EA - `/providers/Microsoft.Billing/BillingAccounts/1234567/enrollmentAccounts/7654321` <br> MCA - `/providers/Microsoft.Billing/billingAccounts/5e98e158-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx_xxxx-xx-xx/billingProfiles/AW4F-xxxx-xxx-xxx/invoiceSections/SH3V-xxxx-xxx-xxx` <br> MPA - `/providers/Microsoft.Billing/billingAccounts/99a13315-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx_xxxx-xx-xx/customers/2281f543-xxxx-xxxx-xxxx-xxxxxxxxxxxx` | None, must be provided. |
parTags | object | Tags you would like to be applied. | No | `{"key": "value"}` | Empty object `{}` |
parManagementGroupId | string | The ID of the existing management group where the subscription will be placed. Also known as it's parent management group. | No | `mg-root` | Empty string |
parSubscriptionOwnerId | string | The object ID of a responsible user, AAD group or service principal. | No | `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx` | Empty string |
parSubscriptionOfferType | string | The offer type of the EA, MCA or MPA subscription to be created. | No | `DevTest` | `Production` |
parTenantId | string | The ID of the tenant. | No | `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx` | `tenant().tenantId` |

## Outputs

Expand All @@ -31,11 +35,13 @@ In this example, the Subscription is created upon an EA Account through a tenant

> For the below examples we assume you have downloaded or cloned the Git repo as-is and are in the root of the repository as your selected directory in your terminal of choice.

> **Important Note:** There are 2 parameter files examples provided in the `/parameters` folder of this module. One that contains examples of all possible parameters and another that only contains the minimum required parameters. The minimum version is used in the below examples.

### Azure CLI
```bash
az deployment tenant create \
--template-file infra-as-code/bicep/CRML/subscriptionAlias/subscriptionAlias.bicep \
--parameters @infra-as-code/bicep/CRML/subscriptionAlias/subscriptionAlias.parameters.example.json \
--parameters @infra-as-code/bicep/CRML/subscriptionAlias/parameters/subscriptionAlias.parameters.minimum.example.json \
--location eastus
```

Expand All @@ -44,7 +50,7 @@ az deployment tenant create \
```powershell
New-AzTenantDeployment `
-TemplateFile infra-as-code/bicep/CRML/subscriptionAlias/subscriptionAlias.bicep `
-TemplateParameterFile infra-as-code/bicep/CRML/subscriptionAlias/subscriptionAlias.parameters.example.json `
-TemplateParameterFile infra-as-code/bicep/CRML/subscriptionAlias/parameters/subscriptionAlias.parameters.minimum.example.json `
-Location eastus
```

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"parSubscriptionName": {
"value": "sub-example-001"
},
"parSubscriptionBillingScope": {
"value": "/providers/Microsoft.Billing/billingAccounts/XXXXXXX/enrollmentAccounts/XXXXXX"
},
"parTags": {
"value": {
"Environment": "POC"
}
},
"parManagementGroupId": {
"value": "mg-example-001"
},
"parSubscriptionOwnerId": {
"value": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx"
},
"parSubscriptionOfferType": {
"value": "Production"
},
"parTenantId": {
"value": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
},
"parSubscriptionBillingScope": {
"value": "/providers/Microsoft.Billing/billingAccounts/XXXXXXX/enrollmentAccounts/XXXXXX"
},
"parSubscriptionOfferType": {
"value": "Production"
}
}
}
26 changes: 23 additions & 3 deletions infra-as-code/bicep/CRML/subscriptionAlias/subscriptionAlias.bicep
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/*
SUMMARY: The Subscription Alias module deploys an EA, MCA or MPA Subscription into the tenants default Management Group
DESCRIPTION: The Subscription Alias module deploys an EA, MCA or MPA Subscription into the tenants default Management Group as per the docs here: https://docs.microsoft.com/azure/cost-management-billing/manage/programmatically-create-subscription
AUTHOR/S: jtracey93
VERSION: 1.0.0
AUTHOR/S: jtracey93, johnlokerse
VERSION: 1.1.0
- Updated version of the API
- Added additional properties: parTags, parManagementGroupId, parSubscriptionOwnerId and subscriptionTenantId
*/

targetScope = 'tenant'
Expand All @@ -13,16 +15,34 @@ param parSubscriptionName string
@description('The full resource ID of billing scope associated to the EA, MCA or MPA account you wish to create the subscription in.')
param parSubscriptionBillingScope string

@description('Tags you would like to be applied.')
param parTags object = {}

@description('The ID of the existing management group where the subscription will be placed. Also known as its parent management group. (Optional)')
param parManagementGroupId string = ''

@description('The object ID of a responsible user, AAD group or service principal. (Optional)')
param parSubscriptionOwnerId string = ''

@allowed([
'DevTest'
'Production'
])
@description('The offer type of the EA, MCA or MPA subscription to be created. Defaults to = Production')
param parSubscriptionOfferType string = 'Production'

resource resSubscription 'Microsoft.Subscription/aliases@2019-10-01-preview' = {
@description('The ID of the tenant. Defaults to = tenant().tenantId')
param parTenantId string = tenant().tenantId

resource resSubscription 'Microsoft.Subscription/aliases@2021-10-01' = {
name: parSubscriptionName
properties: {
additionalProperties: {
tags: parTags
managementGroupId: empty(parManagementGroupId) ? json('null') : managementGroup(parManagementGroupId)
subscriptionOwnerId: empty(parSubscriptionOwnerId) ? json('null') : parSubscriptionOwnerId
subscriptionTenantId: parTenantId
}
displayName: parSubscriptionName
billingScope: parSubscriptionBillingScope
workload: parSubscriptionOfferType
Expand Down
2 changes: 1 addition & 1 deletion tests/pipelines/bicep-build-to-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
inputs:
targetType: 'inline'
script: |
subid=$(az deployment tenant create --name "deploy-$(SubscriptionName)" --location $(Location) --template-file infra-as-code/bicep/CRML/subscriptionAlias/subscriptionAlias.bicep --parameters @infra-as-code/bicep/CRML/subscriptionAlias/subscriptionAlias.parameters.example.json --parameters parSubscriptionBillingScope=$(ALZ-AZURE-SECRET-EA-BILLING-ACCOUNT) parSubscriptionName=$(SubscriptionName) | jq .properties.outputs.outSubscriptionId.value | tr -d '"')
subid=$(az deployment tenant create --name "deploy-$(SubscriptionName)" --location $(Location) --template-file infra-as-code/bicep/CRML/subscriptionAlias/subscriptionAlias.bicep --parameters @infra-as-code/bicep/CRML/subscriptionAlias/parameters/subscriptionAlias.parameters.minimum.example.json --parameters parSubscriptionBillingScope=$(ALZ-AZURE-SECRET-EA-BILLING-ACCOUNT) parSubscriptionName=$(SubscriptionName) | jq .properties.outputs.outSubscriptionId.value | tr -d '"')
echo $subId
echo "##vso[task.setvariable variable=subscriptionId]$subid"
echo "##vso[task.setvariable variable=IsDeployed;isoutput=true]$subid"
Expand Down