Day 61 - Terraform Basic Commands🔥
Task 1: Understanding Basic Terraform Commands
Terraform init
This command collects all resources needed to set up a working directory with Terraform configuration files. It's safe to use this command multiple times, as it never deletes your existing configuration. It initializes Terraform in the current directory with a hidden
.terraform
folder and downloads plugins from providers.
Terraform init -upgrade
Ensures your working directory uses the latest version of provider plugins by upgrading them if needed.
Terraform Plan
This command creates an execution plan, showing what actions Terraform will take to achieve the desired state defined in your configuration files. It is used to create a rough outline before execution.
Terraform Apply
The
terraform apply
command is used to make the changes needed to achieve the desired state of the configuration file. It applies the execution plan, creating or updating infrastructure resources to match your configuration.Terraform Validate
Validates the syntax and consistency of your Terraform configuration files. It's an excellent way to catch errors early.
Terraform fmt
Automatically formats your Terraform configuration files to improve readability and ensure consistency.
Terraform Destroy
Used to delete the infrastructure managed by Terraform. You can also specify what to delete.
Bonus Insight: Terraform's Main Competitors
Terraform is a rockstar, but knowing its alternatives gives you a broader perspective:
Ansible: A go-to tool for configuration management and provisioning.
Packer: Specializes in creating machine images for various platforms.
Cloud Foundry: Focuses on deploying and managing applications.
Kubernetes: Orchestrates containerized applications but doesn’t provision infrastructure like Terraform does.