DevOps Infrastructure as Code 1 — Questions and Answers
Question 1: What is Infrastructure as Code (IaC)?
- Managing and provisioning infrastructure through machine-readable configuration files (Correct answer)
- Writing application code that runs on cloud infrastructure
- Using scripts to manually configure servers after provisioning
- Documenting infrastructure architecture in code comments
Correct answer: Managing and provisioning infrastructure through machine-readable configuration files
IaC manages infrastructure (networks, VMs, load balancers) through declarative or imperative configuration files that can be version-controlled and automated.
Question 2: Which IaC tool uses a declarative language called HCL (HashiCorp Configuration Language)?
- Terraform (Correct answer)
- Ansible
- Chef
- Puppet
Correct answer: Terraform
Terraform uses HCL to describe the desired state of infrastructure; it then creates, updates, or destroys resources to match that declared state.
Question 3: What does `terraform init` do?
- Initializes a Terraform working directory and downloads provider plugins (Correct answer)
- Creates an execution plan showing infrastructure changes
- Applies the Terraform configuration to provision resources
- Destroys all infrastructure managed by the configuration
Correct answer: Initializes a Terraform working directory and downloads provider plugins
`terraform init` initializes the working directory by downloading the required provider plugins and setting up the backend for state storage.
Question 4: What is Terraform 'state'?
- A file that tracks the current real-world resources managed by Terraform (Correct answer)
- The desired configuration declared in .tf files
- A log of all previous Terraform operations
- The current running status of provisioned VMs
Correct answer: A file that tracks the current real-world resources managed by Terraform
Terraform state (terraform.tfstate) maps the configuration to real infrastructure resources so Terraform can calculate changes and detect drift.
Question 5: What is the purpose of `terraform plan`?
- Shows what changes Terraform will make without actually applying them (Correct answer)
- Validates the syntax of Terraform configuration files
- Initializes the Terraform backend and providers
- Locks the state file to prevent concurrent modifications
Correct answer: Shows what changes Terraform will make without actually applying them
`terraform plan` creates an execution plan showing which resources will be created, modified, or destroyed based on current state vs. desired configuration.
Question 6: What is Ansible primarily used for in a DevOps workflow?
- Configuration management and application deployment using agentless SSH (Correct answer)
- Provisioning cloud infrastructure through declarative state files
- Orchestrating container workloads across a Kubernetes cluster
- Monitoring infrastructure health and sending alerts
Correct answer: Configuration management and application deployment using agentless SSH
Ansible automates configuration management, application deployment, and orchestration using SSH without requiring agents on managed nodes.
What is Infrastructure as Code (IaC)?