Once you have successfully initialized a Terraform project, you can create the infrastructure using two alternatives:
Run the terraform plan
command first, which creates an execution plan for the infrastructure. This command alone will not modify/create the infrastructure. To apply the changes, run the terraform apply
command upon confirming the proposed changes.
Run the terraform apply
command directly. This command automatically runs the terraform plan
command, which creates an execution plan for the infrastructure. Upon confirmation of the proposed changes, the terraform apply
command starts building the infrastructure.
The following illustration shows the steps mentioned above:
The terraform plan
command creates the execution plan by doing the following:
Accessing the currently existing state to make sure that Terraform is up to date.
Making a note of the differences between the proposed configuration and the previous state.
Propose a set of changes required to attain the infrastructure desired by the developer.
Once the execution plan is complete, the terraform plan
will not start making the changes. Once the user has confirmed the changes, the terraform apply
command is needed.
Once you run the terraform apply
command in the terminal, various options will appear, such as planning options, planning modes, and other options. The apply command pauses until the user gives their confirmation. Once done, the application will start, and the proposed plan will begin executing. After the terraform apply command
finishes, Terraform will display a message indicating the successful application to the user.
To read more about the options in
terraform apply
andterraform plan,
click here.
Free Resources