Obtaining details for creating an Azure subscription using Rest API and Terraform

Mehul Movadiya 0 Reputation points
2024-05-10T11:44:15.6966667+00:00

Hello!

I have been trying to create an Azure subscription using Rest API and Terraform but I am not sure what the following parameters mean: billingAccountName, billingProfileName, invoiceSectionName. Could someone point me in the right direction on how to find this information?

Here is the Rest API I am using: POST https://management.azure.com/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}/invoiceSections/{invoiceSectionName}/providers/Microsoft.Subscription/createSubscription?api-version=2020-01-01

I have also looked at these APIs:

GET https://management.azure.com/providers/Microsoft.Billing/billingaccounts/?api-version=2020-05-01

PUT https://management.azure.com/providers/Microsoft.Subscription/aliases/sampleAlias?api-version=2021-10-01

This is the documentation I am following:

https://learn.microsoft.com/en-us/azure/cost-management-billing/manage/programmatically-create-subscription-microsoft-partner-agreement?tabs=rest

Azure Cost Management
Azure Cost Management
A Microsoft offering that enables tracking of cloud usage and expenditures for Azure and other cloud providers.
2,127 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,834 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sina Salam 4,216 Reputation points
    2024-05-10T23:49:28.3266667+00:00

    Hello Mehul Movadiya,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    Problem

    Sequel to your questions, I understand that you are seeking assistance in creating an Azure subscription using REST API and Terraform. You are encountering confusion regarding the parameters billingAccountName, billingProfileName, and invoiceSectionName, which are necessary for the subscription creation API call, and you need clarification on what these parameters signify and how to obtain their values programmatically.

    Scenario

    You were asked with automating the creation of Azure subscriptions for his organization's projects using REST API and Terraform. To achieve this automation, he's referring to Microsoft's documentation on programmatically creating subscriptions. However, he's encountering confusion regarding specific parameters required for the API call.

    Solution

    This prescribed solution was based on the scenario given and your questions, while focusing on the problem statement. The parameters you mentioned billingAccountName, billingProfileName, and invoiceSectionName - are related to billing and invoicing configurations within Azure.

    Meaning:

    billingAccountName: This is the name of the billing account under which you want to create the subscription. A billing account is essentially the billing entity within Azure, representing a billing agreement or a payment method.

    billingProfileName: Billing profiles are used to organize and manage charges for a specific set of Azure subscriptions. The billing profile name refers to the profile within the billing account that you want to associate the new subscription with.

    invoiceSectionName: Invoice sections are subdivisions within a billing profile, typically used for organizational or departmental billing purposes. The invoice section name refers to the specific section within the billing profile where you want to create the subscription.

    To obtain the correct values for these parameters, you'll need to access your Azure account's billing settings. You can retrieve this information programmatically using the Azure Billing API or by accessing the Azure portal as you have listed.

    For Terraform, you'll likely use the azurerm_subscription resource to create a subscription, but you'll need to provide the appropriate values for these parameters.

    Finally

    Once you have identified the names of the billing account, billing profile, and invoice section, you can use these names as values for the corresponding parameters (billingAccountName, billingProfileName, and invoiceSectionName) in your REST API calls or Terraform configurations. You should be able to find the necessary information to populate the parameters required for creating an Azure subscription using the REST API or Terraform.

    References

    Source: Review subscription billing using REST APIs. Accessed, 5/10/2024.

    Accept Answer

    I hope this is helpful! Do not hesitate to let me know if you have any other questions.

    ** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful ** so that others in the community facing similar issues can easily find the solution.

    Best Regards,

    Sina SalamRecovered.