Courseiva
Understand Terraform's purposemediumMultiple ChoiceObjective-mapped

TF-004 Understand Terraform's purpose Practice Question

A DevOps engineer needs to integrate Terraform with a CI/CD pipeline. What is a common practice?

⚠ Common exam trap

A common trap is to assume that `-auto-approve` is safe for automation, but it bypasses the human review step and can lead to unintended changes. The best practice is to use `terraform plan` in pull requests to review changes before applying.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Run terraform plan in a pull request

Running `terraform plan` in a pull request is a common practice because it allows the team to review the proposed infrastructure changes before they are applied. This integrates Terraform's safety mechanism into the CI/CD pipeline, ensuring that any destructive or unexpected modifications are caught during code review, not during deployment. It aligns with the principle of infrastructure as code (IaC) where changes are validated and approved through the same workflow as application code.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Run terraform plan in a pull request

    Why this is correct

    Running `terraform plan` within a pull request (PR) is a best practice for CI/CD integration, as it provides a transparent preview of the infrastructure changes before they are applied. This allows team members to review the exact resources that will be created, updated, or destroyed, facilitating early detection of unintended modifications and ensuring adherence to infrastructure as code (IaC) principles prior to any actual state modification.

  • Avoid using variables

    Why it's wrong here

    Avoiding variables in Terraform configurations is counterproductive for CI/CD integration and best practices. Variables are fundamental for creating reusable, flexible, and environment-agnostic modules, allowing configurations to be parameterized with different values for various environments (e.g., dev, staging, prod) or specific resource attributes without altering the core HCL code. This promotes DRY (Don't Repeat Yourself) principles and simplifies management across diverse deployments.

  • Use -auto-approve always

    Why it's wrong here

    Using `terraform apply -auto-approve` always in a CI/CD pipeline is a significant anti-pattern and introduces substantial risk. While it automates the application process, it completely bypasses the critical human review step of the `terraform plan` output, which is essential for verifying intended changes and preventing accidental infrastructure modifications or deletions. This practice can lead to unreviewed, potentially destructive changes being deployed directly to production environments, violating change management and security protocols.

  • Store state in a local file

    Why it's wrong here

    Storing Terraform state in a local file (`terraform.tfstate`) is highly unsuitable for CI/CD environments and team collaboration. Local state files lack concurrency controls, making them prone to corruption and conflicts when multiple engineers or automated pipelines attempt to modify infrastructure simultaneously. Furthermore, local state is not accessible to other team members or CI/CD agents, preventing consistent and shared understanding of the infrastructure's current configuration, thereby necessitating the use of remote state backends for reliability and collaboration.

About these practice questions

One of 428 original TF-004 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This TF-004 practice question is part of Courseiva's free HashiCorp certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the TF-004 exam.