Deploying the infrastructure with Terraform

With the Terraform code written, we now need to run Terraform to deploy our infrastructure.

However, before any execution, it is necessary to first provide authentication with the Azure SP to ensure that Terraform can manage Azure resources.

For this, we can either set the environment variables specific to Terraform to contain the information of the SP created earlier in the Configuring Terraform for Azure section or use the az cli script. 

The following script exports the four Terraform environment variables in the Linux OS:

export ARM_SUBSCRIPTION_ID=xxxxx-xxxxx-xxxx-xxxx
export ARM_CLIENT_ID=xxxxx-xxxxx-xxxx-xxxx
export ARM_CLIENT_SECRET=xxxxxxxxxxxxxxxxxx
export ARM_TENANT_ID=xxxxx-xxxxx-xxxx-xxxx

We can also use the az cli script with the login command:

az login

Once authenticated, we can run Terraform.

In our scenario, for example, we start with an empty Azure subscription without any group resources, but in the real world, our subscription may already contain group resources. 

Before running Terraform, in the Azure portal, check that we do not have a resource group in our subscription:

To run Terraform, we must open a command-line Terminal such as CMD, PowerShell, or Bash and go to the directory where the Terraform code files we wrote are located.

The Terraform code is executed in several steps such as initialization, the preview of changes, and the application of those changes.

Let's look in detail at the execution of these steps next, starting with the initialization step.

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

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