appendix B Authenticating to Azure

The Azure provider for Terraform provisions infrastructure to Microsoft Azure using the Azure Resource Manager API. This appendix walks through the steps necessary to obtain credentials for Azure using the CLI method.

B.1 Creating an Azure account

Microsoft offers a free 30-day trial period for all new account holders. Here is how you can create one (see http://mng.bz/EVdo):

  1. In the web browser, go to https://azure.microsoft.com/free and click the Start Free button.

  2. Sign in with a Microsoft or GitHub account.

  3. Fill in all the required personal information.

After you are done, you will be redirected to the Azure portal home page.

B.2 Installing the Azure CLI

The Azure CLI is the easiest way to obtain credentials for Terraform. It is distributed for Windows, Mac, and Linux operating systems. Refer to Azure’s official documentation for instructions on how to install the CLI: http://mng.bz/N8KN.

B.3 Obtaining credentials via the CLI

Once the CLI is installed, you need to run a few commands.

Note The following information comes directly from the Azure provider documentation at http://mng.bz/D12n. I take no credit for it.

First, log in to the Azure CLI:

$ az login

Once logged in, you can display the list of subscriptions associated with the account:

$ az account list

The output (similar to the following) will display one or more subscriptions. Take note of id, which is the subscription ID you will need in the next step:

[
  {
    "cloudName": "AzureCloud",
    "id": "00000000-0000-0000-0000-000000000000",
    "isDefault": true,
    "name": "PAYG Subscription",
    "state": "Enabled",
    "tenantId": "00000000-0000-0000-0000-000000000000",
    "user": {
      "name": "[email protected]",
      "type": "user"
    }
  }
]

If you have more than one subscription, you can specify the subscription to use via the following command with the subscription ID from earlier:

$ az account set—subscription= "<SUBSCRIPTION_ID>"

B.4 Configuring Azure CLI authentication in Terraform

Now that you’ve logged in to the Azure CLI, you can configure Terraform to use these credentials. If you’re using the default subscription (which you will be, if you’re following this guide), it’s as easy as declaring an empty provider block:

provider "azurem" {
 features {}
}

At this point, terraform plan and terraform apply will run, using the CLI to authenticate.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset