At this point, you need to log in to Azure using the command line, which will redirect
you to the browser to authenticate yourself. After successful authentication, you will
be able to log in:
$ ~ az login
You have logged in. Now let us find all the subscriptions to which you have access...
[
{
"cloudName": "AzureCloud",
"id": "b1234567-89017-6135-v94s-3v16ifk86912",
"isDefault": true,
"name": "Visual Studio Enterprise",
"state": "Enabled",
"tenantId": "ba0198-d28a-41ck-a2od-d8419714a098",
"user": {
"name": "
[email protected]",
"type": "user"
}
}
]
Now that you have successfully logged in and authenticated with Azure, you can
check the ~/.azure directory, which contains the authentication and authorization
information:
$ ls -al
total 44
drwxr-xr-x 1 nsingh nsingh 270 Apr 13 21:13 .
drwxr-xr-x 1 nsingh nsingh 624 Apr 13 21:13 ..
-rw------- 1 nsingh nsingh 7842 Apr 13 21:13 accessTokens.json
-rw-r--r-- 1 nsingh nsingh 5 Apr 13 21:13 az.json
-rw-r--r-- 1 nsingh nsingh 5 Apr 13 21:13 az.sess
-rw-r--r-- 1 nsingh nsingh 420 Apr 13 21:21 azureProfile.json
-rw-r--r-- 1 nsingh nsingh 66 Apr 13 21:21 clouds.config
-rw-r--r-- 1 nsingh nsingh 5053 Apr 13 21:13 commandIndex.json
drwxr-xr-x 1 nsingh nsingh 318 Apr 13 21:21 commands
-rw------- 1 nsingh nsingh 51 Apr 13 21:13 config
drwxr-xr-x 1 nsingh nsingh 26 Apr 13 21:13 logs
drwxr-xr-x 1 nsingh nsingh 10 Apr 13 21:13 telemetry
-rw-r--r-- 1 nsingh nsingh 16 Apr 13 21:13 telemetry.txt
-rw-r--r-- 1 nsingh nsingh 211 Apr 13 21:13 versionCheck.json
Basic usage and infrastructure setup with Terraform
Now that you have successfully set up Terraform to communicate with Azure, you
can build some basic infrastructure. As you work your way through these steps, you
will be able to connect the dots and use Terraform effectively.
All the Terraform code related to this chapter is available in the book’s GitHub
repository, which you can clone onto your local machine.
Go to the Test directory, and you will find a file named test.tf. Example 2-1 shows the
contents of this file. In this example, we are using a local state file to store the current
state of the infrastructure.
20 | Chapter 2: Infrastructure as Code: Setting Up the Gateway