Infrastructure as Code and your first apply
Terraform · 13 questions
Short notes
Key idea
Infrastructure as Code (IaC) describes cloud resources in files that live in Git. Terraform reads them, compares them with what exists, and makes the changes. The same files give the same infrastructure every time.
Syntax
provider "google" {
project = "my-project"
region = "asia-south1"
}
resource "google_storage_bucket" "raw" {
name = "my-project-raw"
location = "ASIA-SOUTH1"
}
terraform init # download providers
terraform plan # show what will change
terraform apply # make the changes
terraform destroy # remove everything in this config
Example
Write the bucket above, run plan: "1 to add". apply creates it. Change location and plan says the bucket must be replaced. You see that before anything happens.
Traps
- Always read the plan. A "-/+ replace" on a database or bucket can mean data loss.
- Clicking changes in the console makes the code and reality disagree (drift).
- Bucket names are global; add the project ID to make them unique.
destroyreally deletes. Useprevent_destroyon anything precious.
Want the full lesson with step-by-step examples, a project and a certificate? Terraform course, ₹120 →
- Question 1easy
Your team built the test project by clicking in the console. Production now behaves differently and nobody knows why. What does Infrastructure as Code fix here?
- Question 2easy
You run
terraform applytwice in a row without changing any code. What happens on the second run? - Question 3medium
Which statement describes a declarative tool?
- Question 4easy
What is a Terraform provider?
- Question 5hard
Why must
terraform.tfstatenever be committed to a public repository?
Infrastructure as Code and your first apply
Infrastructure as Code and your first apply
Infrastructure as Code and your first apply
Infrastructure as Code and your first apply
Infrastructure as Code and your first apply
8 more questions on this topic, with hints, and tests
Sign up free for 21 days of every question and test.