Applying the changes
After having validated that the result of the plan command corresponds to our expectations, the last step is the application of the Terraform code in real time to provision and apply the changes to our infrastructure.
For this, we execute the apply command:
terraform apply
This command does the same operation as the plan command and interactively asks the user for confirmation that we want to implement the changes.
The following is a screenshot of the terraform apply confirmation:
The confirmation is given by inputting yes (or no to cancel), then Terraform applies the changes to the infrastructure.
The following is a screenshot of the terraform apply execution:
The output of the apply command displays all actions executed by Terraform, with all changes and the impacted resources. It ends with a summary line that displays the sum of all added, changed, or destroyed resources.
Since the Terraform apply command has been executed correctly, we can check in the Azure portal that the resources described in the Terraform code are present.
The following is a screenshot of Azure resources by Terraform:
We can see from the portal that the resources specified in the Terraform code have been provisioned successfully.
We have just seen how Terraform is useful for provisioning infrastructure with three main commands:
- The init command that initializes the context
- The plan command to preview the changes
- The apply command to apply the changes
In the next section, we will explore other Terraform commands and the Terraform's life cycle.