Deploying Azure VM's using terraform

View My GitHub Profile

Infrastructure as code

In this tutorial I will try to explain how to deploy virtual infrastucture as code using the Azure resource manager. Since manual labour of clicking resources on the azure portal is time consuming and repetitive work, I like to have network config stored as code.

In order to quickly deploy VM's on your azure subscription, you can use JSON templates. These templates are parsed against microsofts API. However, creating seperate JSON's for all your customers might be time consuming.

Therefore, a tutorial how to get VM's deployed against your azure subscription using Terraform.
P.S. If some steps are not working, or you need some detailed infomation, please contact me :+1:

Preparation: Configuring Azure active directory objects

1. Install terraform.
2. Login to the azure management portal
3. Click active directory --> your subscription --> applications, and click add:

4. Give it a name, click next and give it a random url, since we're not using a url for it yet.
5. Complete the creation of the object. My object is called devopskeyfault:

6. Click on your created object, and click configure. You can see the details here you need in your terraform configuration:
  • client_id:

  • client_secret:

  • The secret wil become visible after creating the key.
  • subscription_id:
  • Can be found via settings --> subscriptions
  • tenant_id(customer endpoint):
  • This is the trickiest one:
    - Go to the new management portal(you can see it popping up at top of your screen when visiting the "old azure portal"
    - Go to subscriptions --> Click subscription --> Click all settings --> Click Users --> Click add:

    You need to select a contributor role, and select the application you created. In my case it's the devopskeyfault role:

    Now your role is mapped to the application, you can retrieve the tenant_id:

    Next, Step2: Creating terrfaform cookbooks using the Azure RM provider