![Forrest logo](/images/logo.png)
terraform:tldr:d3bb4
The terraform apply
command is used to apply the changes specified in a Terraform configuration file (usually named main.tf
) to the defined infrastructure.
When you run terraform apply
, Terraform reads the current state of the infrastructure and the configuration file, then determines the changes that need to be made to reach the desired state specified in the configuration file.
The command will prompt you to confirm the planned changes. If you choose to proceed, Terraform will create, modify, or destroy resources as necessary to match the desired infrastructure specified in the configuration file. It will also update the state file with the new state of the infrastructure.
Here's a high-level overview of the process that occurs when you run terraform apply
:
- Terraform compares the current state of the infrastructure to the desired state specified in the configuration file.
- It determines what actions need to be taken to reach the desired state (e.g., creating new resources, modifying existing ones, or destroying unnecessary resources).
- Terraform presents a summary of the planned changes and prompts you to confirm.
- If you confirm, Terraform executes the planned changes, communicating with the corresponding APIs of the cloud providers or infrastructure services.
- Resources are created, modified, or destroyed, and Terraform tracks the changes made.
- Terraform updates the state file to reflect the new state of the infrastructure.
terraform apply
is a critical command while working with Terraform, as it applies the actual changes to the infrastructure. It should be used with caution, especially in production environments, as it can lead to unintended consequences if not used carefully.