Importing an existing Azure Subscription

Hello, I am running into issues trying to import an existing azure subscription into a local tfstate file.

On the resource page there is a notice on the bottom of the page that says the following (emphasis mine):

“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 terraform import .
In this scenario, the subscription_id property can be completed and Terraform will assume control of the existing subscription by creating an Alias. See the adding an Alias to an existing Subscription above. Terrafom requires an alias to correctly manage Subscription resources due to Azure Subscription API design.”

My interpretation of this is that an alias is required and by following the steps in the adding an Alias to an existing Subscription, Terraform will add the alias to the resource and import it. The user here had the same interpretation and ran into the same issue I am seeing now that the import command errors out saying the Alias cannot be found.

In the github issue linked above, it is stated that the subscription must have an existing Alias before the import can be done, which contradicts what is said on the terraform resource page about Terraform creating the Alias. What is the correct process here? If the Alias needs to be manually applied through other means to a subscription before it can be imported, can the documentation please be updated to reflect this?

I have the same problem to understand how existing Subscriptions can be imported properly into the Terraform state. This must be a very common case because Subscriptions cant be created/removed in the same way as other Azure resources. Why has no one commented this before?

Hi @JanIsaksson @spjavid!

The subscription is used in general as the building block which is expected to exist. Most users don’t create subscriptions automatically, as most accounts don’t allow this anyway.

When using an EA, it is possible to create subscriptions automatically, but it is certainly not required. When using the Azure Provider, using an existing subscription as scope for your Terraform resource works like a charm!

When using multiple subscriptions, aliases come into play as you can currently use one subscription within the Azure Provider scope for resource creation. To use multiple, you need multiple Azure Provider scopes, which can be created using provider aliases.

Thanks for your clarification!

Now I also see the Alias keyword in the Provider declaration.