CDM Infrastructure Automation & Configuration Management 5 — Questions and Answers
Question 1: Which tool is purpose-built for testing infrastructure code by provisioning real resources and verifying their behavior?
- Terratest (Correct answer)
- JUnit
- Selenium
- SonarQube
Correct answer: Terratest
Terratest is a Go-based framework that provisions actual cloud resources using Terraform, validates their properties, and then tears them down as part of automated testing.
Question 2: In Terraform, what is the effect of setting `prevent_destroy = true` in a resource's `lifecycle` block?
- Prevents the resource from being modified by any `terraform apply`
- Causes Terraform to error if a plan would destroy the resource (Correct answer)
- Locks the resource state file so other users cannot modify it
- Excludes the resource from `terraform plan` output
Correct answer: Causes Terraform to error if a plan would destroy the resource
`prevent_destroy = true` is a safeguard that makes Terraform abort with an error if a plan would delete the resource, protecting stateful resources like databases.
Question 3: What is the primary purpose of Packer in an infrastructure automation pipeline?
- Provisioning cloud network topology using declarative HCL
- Building consistent machine images (AMIs, VM templates) across multiple platforms from a single configuration (Correct answer)
- Orchestrating container deployments across a Kubernetes cluster
- Managing secrets and credentials for automated deployments
Correct answer: Building consistent machine images (AMIs, VM templates) across multiple platforms from a single configuration
Packer automates the creation of identical machine images for multiple platforms (AWS AMI, GCP image, Docker) from a single JSON or HCL2 template.
Question 4: Which Ansible feature enables conditional task execution based on the value of a variable or fact?
- handlers
- notify
- when (Correct answer)
- register
Correct answer: when
The `when` directive evaluates a Jinja2 expression and skips the task if the condition is false, enabling branching logic in playbooks.
Question 5: In a DevOps pipeline, what does 'shifting left' security testing for IaC mean?
- Deploying infrastructure to lower-cost regions during off-peak hours
- Running security scans on IaC code during development and CI rather than only after deployment (Correct answer)
- Reducing the number of manual approval gates in the deployment pipeline
- Moving infrastructure management responsibility from Ops to Dev teams
Correct answer: Running security scans on IaC code during development and CI rather than only after deployment
Shifting left means integrating security scanning tools (Checkov, tfsec, Trivy) into the developer workflow and CI pipeline so vulnerabilities are caught before deployment.
Question 6: What is the function of `terraform workspace` in Terraform?
- Defines the directory structure for a Terraform project
- Creates isolated state environments within the same backend configuration for managing multiple environments (Correct answer)
- Configures which cloud provider region resources will be deployed to
- Manages team access permissions for Terraform Cloud organizations
Correct answer: Creates isolated state environments within the same backend configuration for managing multiple environments
Terraform workspaces allow the same configuration to maintain separate state files for different environments (dev, staging, prod) on a single backend.
Question 7: Which principle does 'cattle, not pets' describe in modern infrastructure management?
- Servers should be individually named, maintained, and kept running as long as possible
- Infrastructure resources should be interchangeable, disposable, and replaced rather than individually maintained (Correct answer)
- Cloud costs should be minimized by sharing resources across multiple tenants
- Configuration changes should be applied incrementally to avoid service disruptions
Correct answer: Infrastructure resources should be interchangeable, disposable, and replaced rather than individually maintained
The 'cattle, not pets' philosophy treats servers as interchangeable and ephemeral — when one fails it is replaced with a fresh instance rather than being nursed back to health.
Which tool is purpose-built for testing infrastructure code by provisioning real resources and verifying their behavior?