Skip to content

Commit c70b0e1

Browse files
committed
[VM] Freshness and formatting updates
1 parent 2847e12 commit c70b0e1

File tree

1 file changed

+37
-38
lines changed

1 file changed

+37
-38
lines changed
Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
title: Install and configure Terraform to provision VMs and other infrastructure in Azure | Microsoft Docs
2+
title: Install and configure Terraform for use with Azure | Microsoft Docs
33
description: Learn how to install and configure Terraform to create Azure resources
44
services: virtual-machines-linux
55
documentationcenter: virtual-machines
66
author: echuvyrov
7-
manager: jtalkar
7+
manager: jeconnoc
88
editor: na
99
tags: azure-resource-manager
1010

@@ -14,22 +14,25 @@ ms.devlang: na
1414
ms.topic: article
1515
ms.tgt_pltfrm: vm-linux
1616
ms.workload: infrastructure
17-
ms.date: 10/23/2017
17+
ms.date: 06/19/2018
1818
ms.author: echuvyrov
1919
---
2020

2121
# Install and configure Terraform to provision VMs and other infrastructure into Azure
2222

23-
Terraform provides an easy way to define, preview, and deploy cloud infrastructure by using a [simple templating language](https://www.terraform.io/docs/configuration/syntax.html). This article describes the necessary steps to use Terraform to provision resources in Azure.
23+
Terraform provides an easy way to define, preview, and deploy cloud infrastructure by using a [simple templating language](https://www.terraform.io/docs/configuration/syntax.html). This article describes the necessary steps to use Terraform to provision resources in Azure.
2424

25-
> [!TIP]
26-
To learn more about how to use Terraform with Azure, visit the [Terraform Hub](/azure/terraform). Terraform is installed by default in the [Cloud Shell](/azure/terraform/terraform-cloud-shell). By using Cloud Shell, you can skip the install/setup portions of this document.
25+
To learn more about how to use Terraform with Azure, visit the [Terraform Hub](/azure/terraform).
26+
27+
[!INCLUDE [cloud-shell-try-it.md](../../../includes/cloud-shell-try-it.md)]
28+
29+
Terraform is installed by default in the [Cloud Shell](/azure/terraform/terraform-cloud-shell). If you choose to install Terraform locally, complete the next step, otherwise continue to [Set up Terraform access to Azure](#set-up-terraform-access-to-azure).
2730

2831
## Install Terraform
2932

30-
To install Terraform, [download](https://www.terraform.io/downloads.html) the package appropriate for your operating system into a separate install directory. The download contains a single executable file, for which you should also define a global path. For instructions on how to set the path on Linux and Mac, go to [this webpage](https://stackoverflow.com/questions/14637979/how-to-permanently-set-path-on-linux). For instructions on how to set the path on Windows, go to [this webpage](https://stackoverflow.com/questions/1618280/where-can-i-set-path-to-make-exe-on-windows).
33+
To install Terraform, [download](https://www.terraform.io/downloads.html) the appropriate package for your operating system into a separate install directory. The download contains a single executable file, for which you should also define a global path. For instructions on how to set the path on Linux and Mac, go to [this webpage](https://stackoverflow.com/questions/14637979/how-to-permanently-set-path-on-linux). For instructions on how to set the path on Windows, go to [this webpage](https://stackoverflow.com/questions/1618280/where-can-i-set-path-to-make-exe-on-windows).
3134

32-
Verify your path configuration with the `terraform` command. You should see a list of available Terraform options as output:
35+
Verify your path configuration with the `terraform` command. A list of available Terraform options is shown, as in the following example output:
3336

3437
```bash
3538
azureuser@Azure:~$ terraform
@@ -38,54 +41,39 @@ Usage: terraform [--version] [--help] <command> [args]
3841

3942
## Set up Terraform access to Azure
4043

41-
Configure [an Azure AD service principal](/cli/azure/create-an-azure-service-principal-azure-cli) to enable Terraform to provision resources into Azure. The service principal grants your Terraform scripts using credentials to provision resources in your Azure subscription.
42-
43-
There are several ways to create an Azure AD application and an Azure AD service principal. The easiest and fastest way today is to use Azure CLI 2.0, which [you can download and install on Windows, Linux, or a Mac](/cli/azure/install-azure-cli).
44-
45-
Sign in to administer your Azure subscription by issuing the following command:
46-
47-
`az login`
48-
49-
If you have multiple Azure subscriptions, their details are returned by the `az login` command. Set the `SUBSCRIPTION_ID` environment variable to hold the value of the returned `id` field from the subscription you want to use.
44+
To enable Terraform to provision resources into Azure, create an [Azure AD service principal](/cli/azure/create-an-azure-service-principal-azure-cli). The service principal grants your Terraform scripts to provision resources in your Azure subscription.
5045

51-
Set the subscription that you want to use for this session.
46+
If you have multiple Azure subscriptions, first query your account with [az account show](/cli/azure/account#az-account-show) to get a list of subscription ID and tenant ID values:
5247

5348
```azurecli-interactive
54-
az account set --subscription="${SUBSCRIPTION_ID}"
49+
az account show --query "{subscriptionId:id, tenantId:tenantId}"
5550
```
5651

57-
Query the account to get the subscription ID and tenant ID values.
52+
To use a selected subscription, set the subscription for this session with [az account set](/cli/azure/account#az-account-set). Set the `SUBSCRIPTION_ID` environment variable to hold the value of the returned `id` field from the subscription you want to use:
5853

5954
```azurecli-interactive
60-
az account show --query "{subscriptionId:id, tenantId:tenantId}"
55+
az account set --subscription="${SUBSCRIPTION_ID}"
6156
```
6257

63-
Next, create separate credentials for Terraform.
58+
Now you can create a service principal for use with Terraform. Use [az ad sp create-for-rbac]/cli/azure/ad/sp#az-ad-sp-create-for-rbac), and set the *scope* to your subscription as follows:
6459

6560
```azurecli-interactive
6661
az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/${SUBSCRIPTION_ID}"
6762
```
6863

69-
Your appId, password, sp_name, and tenant are returned. Make a note of the appId and password.
70-
71-
To test your credentials, open a new shell and run the following command, using the returned values for sp_name, password, and tenant:
72-
73-
```azurecli-interactive
74-
az login --service-principal -u SP_NAME -p PASSWORD --tenant TENANT
75-
az vm list-sizes --location westus
76-
```
64+
Your *appId*, *password*, *sp_name*, and *tenant* are returned. Make a note of the *appId* and *password*.
7765

7866
## Configure Terraform environment variables
7967

80-
Configure Terraform to use the tenant ID, subscription ID, client ID, and client secret from the service principal when creating Azure resources. You can also set the environment if working with an Azure cloud other than Azure public. Set the following environment variables, which are used automatically by the [Azure Terraform modules](https://registry.terraform.io/modules/Azure).
68+
To configure Terraform to use your Azure AD service principal, set the following environment variables, which are then used by the [Azure Terraform modules](https://registry.terraform.io/modules/Azure). You can also set the environment if working with an Azure cloud other than Azure public.
8169

8270
- ARM_SUBSCRIPTION_ID
8371
- ARM_CLIENT_ID
8472
- ARM_CLIENT_SECRET
8573
- ARM_TENANT_ID
8674
- ARM_ENVIRONMENT
8775

88-
You can use this sample shell script to set those variables:
76+
You can use the following sample shell script to set those variables:
8977

9078
```bash
9179
#!/bin/sh
@@ -101,7 +89,7 @@ export ARM_ENVIRONMENT=public
10189

10290
## Run a sample script
10391

104-
Create a file `test.tf` in an empty directory and paste in the following script.
92+
Create a file `test.tf` in an empty directory and paste in the following script.
10593

10694
```tf
10795
provider "azurerm" {
@@ -112,17 +100,29 @@ resource "azurerm_resource_group" "rg" {
112100
}
113101
```
114102

115-
Save the file and then run `terraform init`. This command downloads the Azure modules required to create an Azure resource group. You see the following output:
103+
Save the file and then initialize the Terraform deployment. This step downloads the Azure modules required to create an Azure resource group.
116104

105+
```bash
106+
terraform init
117107
```
108+
109+
The output is similar to the following example:
110+
111+
```bash
118112
* provider.azurerm: version = "~> 0.3"
119113

120114
Terraform has been successfully initialized!
121115
```
122116

123-
Preview the script with `terraform plan`, and then create the `testResouceGroup` resource group with `terraform apply`:
117+
You can preview the actions to be completed by the Terraform script with `terraform plan`. When ready to create the resource group, apply your Terraform plan as follows:
124118

119+
```bash
120+
terraform apply
125121
```
122+
123+
The output is similar to the following example:
124+
125+
```bash
126126
An execution plan has been generated and is shown below.
127127
Resource actions are indicated with the following symbols:
128128
+ create
@@ -144,8 +144,7 @@ azurerm_resource_group.rg: Creation complete after 1s
144144

145145
## Next steps
146146

147-
You have installed Terraform and configured Azure credentials so that you can start deploying infrastructure into your Azure subscription. You then tested your installation by creating an empty Azure resource group.
147+
In this article, you installed Terraform or used the Cloud Shell to configure Azure credentials and start creating resources in your Azure subscription. To create a more complete Terraform deployment in Azure, see the following article:
148148

149149
> [!div class="nextstepaction"]
150-
> [Create an Azure VM with Terraform](terraform-create-complete-vm.md)
151-
150+
> [Create an Azure VM with Terraform](terraform-create-complete-vm.md)

0 commit comments

Comments
 (0)