Execute the write, plan, and apply workflow including initialization, validation, and destruction.
This domain covers the core Terraform workflow of write, plan, and apply. It includes describing the overall workflow, initializing a Terraform working directory with terraform init, validating configurations with terraform validate, generating and reviewing execution plans with terraform plan, applying changes with terraform apply, destroying infrastructure with terraform destroy, and applying formatting with terraform fmt.
5 minutes
5 Questions
The Core Terraform Workflow consists of three main stages: Write, Plan, and Apply. This workflow represents the fundamental process that practitioners follow when using Terraform to manage infrastructure as code.
**Write Stage:**
In this initial phase, you author your Terraform configuration files using HashiCorp Configuration Language (HCL). These files define the desired state of your infrastructure, including resources, providers, variables, and outputs. Configuration files typically have a .tf extension and describe what infrastructure components you need, such as virtual machines, networks, storage, and security groups. This stage involves creating or modifying your infrastructure definitions based on requirements.
**Plan Stage:**
The plan stage is executed using the 'terraform plan' command. Terraform compares your written configuration against the current state of your infrastructure stored in the state file. It then generates an execution plan showing what actions Terraform will take to achieve the desired state. This includes resources to be created, modified, or destroyed. The plan serves as a preview and validation step, allowing teams to review proposed changes before implementation. This stage is crucial for catching potential issues and understanding the impact of changes.
**Apply Stage:**
The final stage involves executing 'terraform apply' to implement the planned changes. Terraform provisions, modifies, or removes infrastructure resources according to the execution plan. During this process, Terraform communicates with cloud provider APIs to make the necessary changes. Once complete, Terraform updates the state file to reflect the new infrastructure state.
This workflow supports collaboration through version control integration, enabling teams to review configuration changes through pull requests. The workflow can be executed locally for individual development or through automation platforms like Terraform Cloud for team environments. Following this core workflow ensures consistent, repeatable, and auditable infrastructure deployments across environments.The Core Terraform Workflow consists of three main stages: Write, Plan, and Apply. This workflow represents the fundamental process that practitioners follow when using Terraform to manage infrastructure as code.
**Write Stage:**
In this initial phase, you author your Terraform configuration files…