0
0
Terraformcloud~5 mins

Why IaC over manual provisioning in Terraform - Why It Works

Choose your learning style9 modes available
Introduction
Manually setting up servers and networks takes a lot of time and can lead to mistakes. Infrastructure as Code (IaC) lets you write down your setup in files, so you can create the same setup again and again without errors.
When you want to create the same server setup multiple times without forgetting steps
When you need to fix or update your infrastructure quickly and safely
When you want to share your infrastructure setup with your team easily
When you want to keep a history of changes to your infrastructure
When you want to avoid human errors in setting up cloud resources
Commands
This command sets up Terraform in your folder so it can talk to your cloud provider and prepare to create resources.
Terminal
terraform init
Expected OutputExpected
Initializing the backend... Initializing provider plugins... - Finding latest version of hashicorp/aws... - Installing hashicorp/aws v4.0.0... - Installed hashicorp/aws v4.0.0 (signed by HashiCorp) Terraform has been successfully initialized!
This command shows what Terraform will do before it makes any changes. It helps you check your setup for mistakes.
Terminal
terraform plan
Expected OutputExpected
An execution plan has been generated and is shown below. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # aws_instance.example will be created + resource "aws_instance" "example" { + ami = "ami-0c55b159cbfafe1f0" + instance_type = "t2.micro" } Plan: 1 to add, 0 to change, 0 to destroy.
This command tells Terraform to create the resources you described in your files without asking for confirmation.
Terminal
terraform apply -auto-approve
Expected OutputExpected
aws_instance.example: Creating... aws_instance.example: Still creating... [10s elapsed] aws_instance.example: Creation complete after 20s [id=i-0abcd1234efgh5678] Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
-auto-approve - Skip manual approval to apply changes immediately
This command removes all the resources Terraform created, cleaning up your cloud environment.
Terminal
terraform destroy -auto-approve
Expected OutputExpected
aws_instance.example: Destroying... aws_instance.example: Destruction complete after 10s Destroy complete! Resources: 1 destroyed.
-auto-approve - Skip manual approval to destroy resources immediately
Key Concept

If you remember nothing else, remember: IaC lets you create, change, and delete infrastructure safely and repeatedly using code instead of manual steps.

Common Mistakes
Running terraform apply without checking terraform plan first
You might create or change resources you did not intend, causing errors or extra costs.
Always run terraform plan first to review what changes will happen.
Manually changing cloud resources after Terraform created them
Terraform will not know about manual changes and can overwrite or lose them on next apply.
Make all changes through Terraform files and commands to keep state consistent.
Not running terraform destroy to clean up resources after testing
Unused resources keep running and cost money.
Run terraform destroy when you no longer need the resources.
Summary
terraform init prepares your folder to work with Terraform and cloud providers.
terraform plan shows what changes Terraform will make before applying them.
terraform apply creates or updates your cloud resources based on your code.
terraform destroy removes the resources Terraform created to avoid extra costs.