Courseiva
Understand IaC conceptshardMultiple ChoiceObjective-mapped

TF-004 Understand IaC concepts Practice Question

A team manages a multi-tier application consisting of web servers, application servers, and databases deployed across AWS and Azure. Historically, they have provisioned infrastructure manually using cloud consoles and ad-hoc scripts. To improve consistency and reduce errors, they decide to adopt Terraform for Infrastructure as Code. After initial rollout, they encounter problems: some team members still make direct changes via the cloud console to quickly fix issues, causing configuration drift between the Terraform state and actual resources. They also need to manage three distinct environments (development, staging, production) with different configurations (e.g., instance sizes, database settings). The team consists of five people with a limited budget for additional tools. Which course of action best addresses these challenges while adhering to IaC principles?

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

Implement a CI/CD pipeline that runs terraform plan and apply automatically on merges to the main branch, and use Terraform Cloud's Sentinel policies to prevent drift.

Best addresses both challenges. Implementing a CI/CD pipeline that runs terraform plan and apply automatically on merges to the main branch ensures all infrastructure changes are made through version-controlled Terraform configurations, preventing configuration drift from manual console changes. Using Terraform Cloud's Sentinel policies adds an additional layer of governance to enforce compliance and prevent unauthorized changes. This approach also naturally supports environment management because different branches or configurations can represent the three environments (development, staging, production), and the pipeline can target different remote backends or workspaces. Option A (shared S3 with DynamoDB locking) improves state management and collaboration but does not prevent drift from direct console changes. Option B (workspaces and IAM policies) can help with environment separation and restrict console changes, but local applies still risk drift and the IAM approach may be overly restrictive. Option C (provider aliases) is not designed for environment management and manual planning does not prevent drift.

Answer analysis

Option-by-option breakdown

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

  • Store Terraform state in a shared S3 bucket with DynamoDB locking, and have each team member apply their own changes locally after review.

    Why it's wrong here

    Storing Terraform state in an S3 bucket with DynamoDB locking effectively manages concurrent access to the state file, but allowing team members to apply changes locally after review still introduces significant risk of configuration drift. This approach lacks centralized enforcement, meaning unreviewed or incorrect changes can still be applied, and it does not prevent manual out-of-band modifications to resources, making drift detection and prevention difficult.

  • Use Terraform workspaces to manage environments and enforce that all changes go through version-controlled Terraform configs, disabling direct console changes via IAM policies.

    Why it's wrong here

    While Terraform workspaces are excellent for isolating state files across different environments (e.g., dev, staging, prod) within a single configuration, they do not inherently prevent configuration drift. Workspaces manage distinct state files, but they do not enforce *how* changes are applied to those states. Disabling direct console changes via IAM policies is a crucial security measure, but it's an external control and doesn't prevent an authorized user from applying an unreviewed or incorrect Terraform configuration, nor does it detect drift caused by other automated processes.

  • Assign each environment to a different Terraform provider alias and use manual planning to ensure correctness.

    Why it's wrong here

    Terraform provider aliases are designed to manage multiple configurations for the *same* provider within a single Terraform configuration, such as deploying resources into different AWS accounts from one codebase. They are not a mechanism for isolating distinct environments or preventing configuration drift. Relying on manual planning is insufficient as it is prone to human error, lacks automated enforcement, and cannot proactively detect or prevent out-of-band changes that lead to drift, making it an unreliable strategy for maintaining infrastructure consistency.

  • Implement a CI/CD pipeline that runs terraform plan and apply automatically on merges to the main branch, and use Terraform Cloud's Sentinel policies to prevent drift.

    Why this is correct

    Implementing a CI/CD pipeline ensures that all infrastructure changes are applied through an automated, version-controlled process, eliminating local applies and unreviewed modifications that commonly cause drift. This pipeline can run `terraform plan` for review and `terraform apply` automatically upon merge to the main branch, enforcing a single source of truth. Furthermore, integrating Terraform Cloud's Sentinel policies provides policy-as-code enforcement, actively preventing deployments that would introduce drift or violate organizational compliance rules by blocking non-compliant plans before application.

Quick reference

AWS S3 Storage Class Comparison

Storage ClassMin DurationRetrievalUse Case
S3 StandardNoneImmediateFrequently accessed data
S3 Standard-IA30 daysImmediateInfrequent access, rapid retrieval
S3 One Zone-IA30 daysImmediateNon-critical infrequent data
S3 Intelligent-TieringNoneImmediate–hoursUnknown or changing access patterns
S3 Glacier Instant90 daysMillisecondsArchive with instant retrieval
S3 Glacier Flexible90 daysMinutes–hoursArchive, flexible retrieval
S3 Glacier Deep Archive180 daysHoursLong-term compliance archive

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.