You have a `variable "env"` with no default value. When running `terraform plan` in a CI/CD pipeline (non-interactive), how should you supply the value without prompting?

Direct Answer (Verified)Reviewed by Sunny (Senior Cloud Engineer)

Correct Answer: Both B and C are valid approaches

Both `TF_VAR_env` (environment variable) and `-var="env=prod"` (CLI flag) supply variable values in non-interactive mode — ideal for CI/CD. Committing `terraform.tfvars` with sensi...

Real Exam Scenario

You have a `variable "env"` with no default value. When running `terraform plan` in a CI/CD pipeline (non-interactive), how should you supply the value without prompting?

✓ Correct Answer & Explanation

Correct Answer

Both B and C are valid approaches

Why This Answer Is Correct

Both `TF_VAR_env` (environment variable) and `-var="env=prod"` (CLI flag) supply variable values in non-interactive mode — ideal for CI/CD. Committing `terraform.tfvars` with sensitive/environment-specific values to source control is a security anti-pattern. Terraform's variable precedence order (lowest to highest): environment variables → tfvars files → CLI flags.