Introduction
Problem
A user may run into the following error when attempting to import an Azure Subscription into state:
$ terraform import azurerm_subscription.test /providers/Microsoft.Subscriptions/<REDACTED>
azurerm_subscription.test: Importing from ID "/providers/Microsoft.Subscriptions/<REDACTED>
Error: cannot parse resource id: "/providers/Microsoft.Subscriptions/<REDACTED>"
Cause
Terraform requires an alias to correctly manage Subscription resources due to Azure Subscription API limitations. This error occurs when attempting to import an Azure Subscription that was created without an alias (i.e., subscriptions made through the Portal).
Overview of possible solutions
Solution:
-
Add an alias to existing subscription via Terraform configuration [1], then do a terraform apply.
resource "azurerm_subscription" "test" {
alias = "test-sub"
subscription_name = "My Test Subscription"
subscription_id = "<subscription-id>"
}
2. Add an alias to an existing subscription via Azure API [2], then retry the import using the subscription alias.
Outcome:
After using one of the above solutions, Terraform will have management over the subscription.