Terraform Beginner Quiz
30 questions on Terraform Basics.
Question 1: What is Terraform primarily used for?
- A. Video rendering
- B. Infrastructure provisioning and management as Code (IaC) β (correct answer)
- C. Graphic design
- D. Writing web applications
Explanation: Terraform allows you to define your cloud infrastructure (servers, databases, networks) using configuration files, rather than clicking through a web interface.
Question 2: Which company created and maintains Terraform?
- A. Google
- B. Microsoft
- C. HashiCorp β (correct answer)
- D. Amazon
Explanation: HashiCorp is the creator of Terraform, as well as other DevOps tools like Vault, Consul, and Vagrant.
Question 3: What language are Terraform configuration files written in?
- A. YAML
- B. HCL (HashiCorp Configuration Language) β (correct answer)
- C. Python
- D. XML
Explanation: HCL is designed to be human-readable, declarative, and easy to understand for defining infrastructure.
Question 4: What does it mean that Terraform is a "Declarative" tool?
- A. You write exact step-by-step scripts of how to build the server
- B. You declare the *desired end state* of your infrastructure, and Terraform figures out how to achieve it β (correct answer)
- C. You declare variables loudly
- D. You must manually declare resources in the AWS console first
Explanation: You say "I want 3 servers." If there are currently 0, Terraform creates 3. If there are 5, Terraform destroys 2. You don't write the logic; Terraform handles it.
Question 5: What is a Terraform "Provider"?
- A. The internet service provider
- B. A plugin that allows Terraform to interact with cloud platforms, SaaS providers, and other APIs (e.g., AWS, Azure, GCP) β (correct answer)
- C. The person who writes the code
- D. A server
Explanation: Without the AWS Provider, Terraform has no idea how to talk to the AWS API.
Question 6: Which command initializes a working directory containing Terraform configuration files?
- A.
terraform start
- B.
terraform begin
- C.
terraform init β (correct answer)
- D.
terraform build
Explanation: terraform init is always the first command you run. It downloads the necessary provider plugins required by your code.
Question 7: What does the terraform plan command do?
- A. Creates a flowchart of your code
- B. Creates an execution plan, showing you exactly what actions Terraform *will* take to achieve the desired state, without actually making any changes β (correct answer)
- C. Bills your credit card
- D. Applies the changes to the cloud
Explanation: plan is a safety mechanism. It shows you the additions, changes, and destructions it intends to perform before you approve them.
Question 8: Which command actually creates or updates infrastructure to match the configuration?
- A.
terraform apply β (correct answer)
- B.
terraform create
- C.
terraform go
- D.
terraform push
Explanation: terraform apply will run a plan, prompt you for approval (yes/no), and then execute the API calls to build your infrastructure.
Question 9: Which command is used to completely tear down all resources managed by your Terraform configuration?
- A.
terraform delete
- B.
terraform destroy β (correct answer)
- C.
terraform remove
- D.
terraform kill
Explanation: terraform destroy is extremely powerful and dangerous. It removes everything defined in your state file.
Question 10: What is the Terraform "State" file (terraform.tfstate)?
- A. A backup of your code
- B. A JSON file where Terraform maps your real-world cloud resources to your configuration, tracking metadata to know what it currently manages β (correct answer)
- C. A log of errors
- D. The configuration file you write
Explanation: State is how Terraform knows that a specific AWS instance ID belongs to a specific block of code you wrote.
Question 11: Why is it dangerous to commit the terraform.tfstate file to a public Git repository?
- A. It is too large
- B. It often contains sensitive data, including initial passwords, database connection strings, and private keys in plain text β (correct answer)
- C. Git will reject it
- D. It causes syntax errors
Explanation: State files should be stored securely in a remote backend (like an encrypted AWS S3 bucket) rather than local Git.
Question 12: In Terraform HCL, what does the resource block do?
- A. Connects to the internet
- B. Defines a piece of infrastructure you want to exist (e.g., a virtual network, compute instance, or DNS record) β (correct answer)
- C. Defines variables
- D. Connects to a database
Explanation: Example: resource "aws_instance" "web" { ... } tells Terraform to provision an EC2 instance on AWS.
Question 13: In the block resource "aws_instance" "web_server", what is aws_instance?
- A. The resource type, defined by the provider β (correct answer)
- B. The variable name
- C. The region name
- D. The password
Explanation: The first label is the *type* of resource (which the AWS provider understands). The second label (web_server) is your custom *local name* for it.
Question 14: In the block resource "aws_instance" "web_server", what is web_server?
- A. The resource type
- B. The local identifier (name) you use to reference this specific resource elsewhere in your Terraform code β (correct answer)
- C. The domain name of the website
- D. The username
Explanation: This name is only used inside Terraform. It is not necessarily the name that will appear in the AWS console.
Question 15: What does the data block (Data Source) do in Terraform?
- A. Creates a new database
- B. Allows Terraform to fetch information about resources that are defined *outside* of Terraform, or by another separate Terraform configuration β (correct answer)
- C. Sends data to a webhook
- D. Deletes data
Explanation: If a network was created manually by your IT team years ago, you can use a data block to fetch its ID so you can put your new servers inside it.
Question 16: How do you reference the ID of the web_server resource in another block of code?
- A.
$web_server.id
- B.
aws_instance.web_server.id β (correct answer)
- C.
id=web_server
- D.
resource.id
Explanation: You reference attributes using the syntax resource_type.local_name.attribute.
Question 17: What does the variable block do?
- A. Defines a value that can be passed into the Terraform module from the outside, allowing for dynamic configurations β (correct answer)
- B. Creates a random number
- C. Modifies the state file
- D. Writes to a log file
Explanation: Variables allow you to use the exact same code to deploy to "Dev" and "Prod" by just passing in different values (e.g., instance_size = "t2.micro").
Question 18: How do you access the value of a defined variable named region?
- A.
$region
- B.
var.region β (correct answer)
- C.
${region}
- D.
variable.region
Explanation: The var. prefix is required to access variables in HCL.
Question 19: What is an output block used for?
- A. To print text to the printer
- B. To define values that will be highlighted to the user when Terraform applies, and can be queried using
terraform output β (correct answer)
- C. To export the code to HTML
- D. To delete resources
Explanation: If you create a web server, you can output its public IP address so you don't have to go digging through the AWS console to find it.
Question 20: What happens if you delete a resource block from your .tf file and run terraform apply?
- A. Nothing happens
- B. Terraform gives an error
- C. Terraform will destroy the corresponding real-world resource because it is no longer in the desired state configuration β (correct answer)
- D. Terraform asks you to rewrite it
Explanation: Because Terraform is declarative, removing code equals removing infrastructure.
Question 21: What does the command terraform fmt do?
- A. Formats the hard drive of the server
- B. Rewrites Terraform configuration files to a canonical format and style (auto-indentation) β (correct answer)
- C. Deletes formatting
- D. Downloads providers
Explanation: terraform fmt ensures all developers on a team are using the exact same spacing and indentation in their HCL code.
Question 22: What does the command terraform validate do?
- A. Validates your credit card with AWS
- B. Checks whether the configuration is syntactically valid and internally consistent, regardless of any provided variables or existing state β (correct answer)
- C. Applies the code
- D. Checks the internet connection
Explanation: It catches typos and missing brackets before you even try to run a plan.
Question 23: What is a Terraform "Module"?
- A. A physical component of a server
- B. A container for multiple resources that are used together, allowing you to package and reuse configurations β (correct answer)
- C. A paid feature
- D. A specific provider
Explanation: Instead of writing 50 lines of code every time you need a database, you can write a "database module" once, and then simply call that module with 3 lines of code anywhere else.
Question 24: How can you pass a variable value into Terraform via the command line?
- A.
terraform apply --var="region=us-east-1"
- B.
terraform apply -var="region=us-east-1" β (correct answer)
- C.
terraform apply region=us-east-1
- D.
terraform apply set region us-east-1
Explanation: Using the -var flag allows you to override variable defaults at runtime.
Question 25: What file does Terraform automatically load to populate variable values if it is present in the directory?
- A.
vars.txt
- B.
terraform.tfvars β (correct answer)
- C.
config.env
- D.
values.yml
Explanation: You can put all your variable values in a terraform.tfvars file, and Terraform will automatically pick them up when you run apply.
Question 26: What is the purpose of a "Remote Backend"?
- A. To run Terraform on a slower computer
- B. To store the
terraform.tfstate file remotely (like in an S3 bucket or Terraform Cloud) allowing multiple team members to collaborate and locking the state during runs β (correct answer)
- C. To backup your
.tf files
- D. To host your website
Explanation: If two developers run terraform apply simultaneously using local state, they will overwrite each other. Remote backends provide State Locking.
Question 27: What does the count meta-argument do in a resource block?
- A. Counts the number of lines of code
- B. Creates that many identical, separate instances of the resource β (correct answer)
- C. Sets a budget limit
- D. Counts the errors
Explanation: If you set count = 3 on an aws_instance block, Terraform will provision three identical servers instead of one.
Question 28: What does the depends_on meta-argument do?
- A. Checks if the internet is working
- B. Explicitly forces Terraform to wait for another resource to be created before creating this one, overriding Terraform's automatic dependency graph β (correct answer)
- C. Automatically installs software
- D. Depends on a user clicking "Yes"
Explanation: Usually, Terraform figures out order automatically. But if an app crashes because the database isn't fully ready yet, depends_on forces the app to wait.
Question 29: How do you skip the interactive "yes" approval prompt when running terraform apply in an automated CI/CD pipeline?
- A.
terraform apply --force
- B.
terraform apply -auto-approve β (correct answer)
- C.
terraform apply --yes
- D.
terraform apply -y
Explanation: In Jenkins or GitHub Actions, there is no human to type "yes", so the -auto-approve flag is required.
Question 30: What is terraform taint (or terraform apply -replace) used for?
- A. To inject a virus into the server
- B. To manually mark a resource as degraded or broken, forcing Terraform to destroy and recreate it on the next apply β (correct answer)
- C. To delete variables
- D. To change the color of the output
Explanation: If a server was manually messed up by an admin logging into it, you can taint it to force Terraform to replace it with a fresh, clean server.