Explain the lifecycle of a Terraform configuration and what happens during the planning and application phases.