Azure Base Subscription
This page shows how to write Terraform and Azure Resource Manager for Base Subscription and write them securely.
azurerm_subscription (Terraform)
The Subscription in Base can be configured in Terraform with the resource name azurerm_subscription
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_subscription" "eshop" {
alias = "eshop"
subscription_name = "demo-E-shop"
subscription_id = "4fd63c38-a6be-4fb1-ac9e-ab1781af69ad"
}
resource "azurerm_subscription" "example" {
subscription_name = "Landing Zone A2"
billing_scope_id = data.azurerm_billing_enrollment_account_scope.example.id
}
# output "billing_account_name" {
resource "azurerm_subscription" "create_subscription" {
subscription_name = var.subscription_name
billing_scope_id = data.azurerm_billing_mca_account_scope.get_billing_scope.id
}
resource "azurerm_management_group_subscription_association" "add_subscription_to_mg" {
resource "azurerm_subscription" "amapolis_root_subscription" {
subscription_name = var.subscription_name
subscription_id = var.subscription_id
}
resource "azurerm_resource_group" "amapolis_dot_dev_resource_group" {
resource "azurerm_subscription" "changeme_enterprise_enrollment_subscription" {
subscription_name = "changeme-subscription-name"
billing_scope_id = data.azurerm_billing_enrollment_account_scope.changeme_enrollment_account_scope.id
}
resource "azurerm_subscription" "changeme_customer_account_subscription" {
subscription_name = "changeme-new-subscription-name"
billing_scope_id = data.azurerm_billing_mca_account_scope.changeme_mca_account_scope.id
}
resource "azurerm_subscription" "sub" {
count = var.subscription_key != "logged_in_subscription" ? 1 : 0
alias = try(var.settings.alias, null) == null ? var.subscription_key : var.settings.alias
subscription_name = var.settings.name
subscription_id = try(var.settings.subscription_id, null) != null ? var.settings.subscription_id : null
resource "azurerm_subscription" "sub" {
count = try(var.settings.subscription_id, null) == null && var.subscription_key != "logged_in_subscription" ? 1 : 0
alias = var.subscription_key
subscription_name = var.settings.name
billing_scope_id = data.azurerm_billing_enrollment_account_scope.sub.0.id
resource "azurerm_subscription" "sub" {
count = try(var.settings.subscription_id, null) == null && var.subscription_key != "logged_in_subscription" ? 1 : 0
alias = var.subscription_key
subscription_name = var.settings.name
billing_scope_id = data.azurerm_billing_enrollment_account_scope.sub.0.id
resource "azurerm_subscription" "boubou" {
provider = azurerm.root
alias = "boubou"
subscription_name = "boubou"
billing_scope_id = "/providers/Microsoft.Billing/billingAccounts/REPLACE_ME/billingProfiles/REPLACE_ME/invoiceSections/REPLACE_ME"
}
Parameters
-
alias
optional computed - string
The Alias Name of the subscription. If omitted a new UUID will be generated for this property.
-
billing_scope_id
optional - string -
id
optional computed - string -
subscription_id
optional computed - string
The GUID of the Subscription.
-
subscription_name
required - string
The Display Name for the Subscription.
The Tenant ID to which the subscription belongs
-
workload
optional - string
The workload type for the Subscription. Possible values are
Production
(default) andDevTest
.
-
timeouts
single block
Explanation in Terraform Registry
Manages an Alias for a Subscription - which adds an Alias to an existing Subscription, allowing it to be managed in Terraform - or create a new Subscription with a new Alias.
NOTE: Destroying a Subscription controlled by this resource will place the Subscription into a cancelled state. It is possible to re-activate a subscription within 90-days of cancellation, after which time the Subscription is irrevocably deleted, and the Subscription ID cannot be re-used. For further information see here. Users can optionally delete a Subscription once 72 hours have passed, however, this functionality is not suitable for Terraform. A
Deleted
subscription cannot be reactivated.NOTE: It is not possible to destroy (cancel) a subscription if it contains resources. If resources are present that are not managed by Terraform then these will need to be removed before the Subscription can be destroyed.
NOTE: Azure supports Multiple Aliases per Subscription, however, to reliably manage this resource in Terraform only a single Alias is supported.
Microsoft.Subscription/aliases (Azure Resource Manager)
The aliases in Microsoft.Subscription can be configured in Azure Resource Manager with the resource name Microsoft.Subscription/aliases
. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
"type": "Microsoft.Subscription/aliases",
"properties": {
"subscriptionId": "subscriptions/291bba3f-e0a5-47bc-a099-3bdcb2a50a05"
}
}
},
"type": "Microsoft.Subscription/aliases",
"properties": {
"subscriptionId": "subscriptions/291bba3f-e0a5-47bc-a099-3bdcb2a50a05"
}
}
},
"type": "Microsoft.Subscription/aliases",
"properties": {
"subscriptionId": "subscriptions/291bba3f-e0a5-47bc-a099-3bdcb2a50a05"
}
}
},
"type": "Microsoft.Subscription/aliases",
"properties": {
"subscriptionId": "subscriptions/291bba3f-e0a5-47bc-a099-3bdcb2a50a05"
}
}
},
"type": "Microsoft.Subscription/aliases",
"properties": {
"subscriptionId": "subscriptions/291bba3f-e0a5-47bc-a099-3bdcb2a50a05"
}
}
},
"type": "Microsoft.Subscription/aliases",
"properties": {
"subscriptionId": "subscriptions/291bba3f-e0a5-47bc-a099-3bdcb2a50a05"
}
}
},
"type": "Microsoft.Subscription/aliases",
"apiVersion": "2020-09-01",
"copy": {
"name": "eslzSubCopy",
"count": "[length(parameters('subscriptions'))]"
},
"type": "Microsoft.Subscription/aliases",
"apiVersion": "2020-09-01",
"properties": {
"displayName": "string",
"workload": "Production",
"billingScope": "string",
"type": "Microsoft.Subscription/aliases",
"apiVersion": "2020-09-01",
"copy": {
"name": "eslzSubCopy",
"count": "[length(parameters('subscriptions'))]"
},
"type": "Microsoft.Subscription/aliases",
"apiVersion": "2020-09-01",
"copy": {
"name": "eslzSubCopy",
"count": "[length(parameters('subscriptions'))]"
},
Frequently asked questions
What is Azure Base Subscription?
Azure Base Subscription is a resource for Base of Microsoft Azure. Settings can be wrote in Terraform.
Where can I find the example code for the Azure Base Subscription?
For Terraform, the tkubica12/governance-automation, grtn316/ESLZTFPipelining and chaitanyagm/terraform_code source code examples are useful. See the Terraform Example section for further details.
For Azure Resource Manager, the jashsing-mic/azure-rest-api-specs, jashsing-mic/azure-rest-api-specs and EugenML/msapi01 source code examples are useful. See the Azure Resource Manager Example section for further details.