Skip to content

azurermSubscription

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.

Example Usage - creating a new Alias and Subscription for an Enrollment Account

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
const dataAzurermBillingEnrollmentAccountScopeExample =
  new azurerm.dataAzurermBillingEnrollmentAccountScope.DataAzurermBillingEnrollmentAccountScope(
    this,
    "example",
    {
      billing_account_name: "1234567890",
      enrollment_account_name: "0123456",
    }
  );
const azurermSubscriptionExample = new azurerm.subscription.Subscription(
  this,
  "example_1",
  {
    billing_scope_id: dataAzurermBillingEnrollmentAccountScopeExample.id,
    subscription_name: "My Example EA Subscription",
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermSubscriptionExample.overrideLogicalId("example");

Example Usage - creating a new Alias and Subscription for a Microsoft Customer Account

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
const dataAzurermBillingMcaAccountScopeExample =
  new azurerm.dataAzurermBillingMcaAccountScope.DataAzurermBillingMcaAccountScope(
    this,
    "example",
    {
      billing_account_name:
        "e879cf0f-2b4d-5431-109a-f72fc9868693:024cabf4-7321-4cf9-be59-df0c77ca51de_2019-05-31",
      billing_profile_name: "PE2Q-NOIT-BG7-TGB",
      invoice_section_name: "MTT4-OBS7-PJA-TGB",
    }
  );
const azurermSubscriptionExample = new azurerm.subscription.Subscription(
  this,
  "example_1",
  {
    billing_scope_id: dataAzurermBillingMcaAccountScopeExample.id,
    subscription_name: "My Example MCA Subscription",
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermSubscriptionExample.overrideLogicalId("example");

Example Usage - creating a new Alias and Subscription for a Microsoft Partner Account

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
const dataAzurermBillingMpaAccountScopeExample =
  new azurerm.dataAzurermBillingMpaAccountScope.DataAzurermBillingMpaAccountScope(
    this,
    "example",
    {
      billing_account_name:
        "e879cf0f-2b4d-5431-109a-f72fc9868693:024cabf4-7321-4cf9-be59-df0c77ca51de_2019-05-31",
      customer_name: "2281f543-7321-4cf9-1e23-edb4Oc31a31c",
    }
  );
const azurermSubscriptionExample = new azurerm.subscription.Subscription(
  this,
  "example_1",
  {
    billing_scope_id: dataAzurermBillingMpaAccountScopeExample.id,
    subscription_name: "My Example MPA Subscription",
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermSubscriptionExample.overrideLogicalId("example");

Example Usage - adding an Alias to an existing Subscription

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
new azurerm.subscription.Subscription(this, "example", {
  alias: "examplesub",
  subscription_id: "12345678-12234-5678-9012-123456789012",
  subscription_name: "My Example Subscription",
});

Arguments Reference

The following arguments are supported:

  • subscriptionName - (Required) The Name of the Subscription. This is the Display Name in the portal.

  • alias - (Optional) The Alias name for the subscription. Terraform will generate a new GUID if this is not supplied. Changing this forces a new Subscription to be created.

  • billingScopeId - (Optional) The Azure Billing Scope ID. Can be a Microsoft Customer Account Billing Scope ID, a Microsoft Partner Account Billing Scope ID or an Enrollment Billing Scope ID.

  • subscriptionId - (Optional) The ID of the Subscription. Changing this forces a new Subscription to be created.

\~> NOTE: This value can be specified only for adopting control of an existing Subscription, it cannot be used to provide a custom Subscription ID.

\~> NOTE: Either billingScopeId or subscriptionId has to be specified.

  • workload - (Optional) The workload type of the Subscription. Possible values are production (default) and devTest. Changing this forces a new Subscription to be created.

  • tags - (Optional) A mapping of tags to assign to the Subscription.

Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:

  • id - The Resource ID of the Alias.

  • tenantId - The ID of the Tenant to which the subscription belongs.

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

  • create - (Defaults to 30 minutes) Used when creating the Subscription.
  • read - (Defaults to 5 minutes) Used when retrieving the Subscription.
  • update - (Defaults to 30 minutes) Used when updating the Subscription.
  • delete - (Defaults to 30 minutes) Used when deleting the Subscription.

Import

Subscriptions can be imported using the resourceId, e.g.

terraform import azurerm_subscription.example "/providers/Microsoft.Subscription/aliases/subscription1"

!> NOTE: When importing a Subscription that was not created programmatically, either by this Terraform resource or using the Alias API, it will have no Alias ID to import via terraformImport. In this scenario, the subscriptionId property can be completed and Terraform will assume control of the existing subscription by creating an Alias. See the addingAnAliasToAnExistingSubscription above. Terrafom requires an alias to correctly manage Subscription resources due to Azure Subscription API design.