Home »
Trending Technologies MCQs
Infrastructure as Code (IaC) MCQs (Multiple-Choice Questions)
Infrastructure as Code (IaC) is a modern approach to managing and provisioning IT infrastructure through machine-readable configuration files. It allows organizations to automate infrastructure creation, configuration, and management instead of relying on manual processes.
Infrastructure as Code (IaC) MCQs
Infrastructure as Code enables developers and operations teams to define infrastructure resources such as virtual machines, networks, databases, and storage systems using code. These configurations can be version-controlled, reviewed, tested, and reused across different environments.
IaC is an important part of DevOps, cloud computing, and Platform Engineering. Popular tools such as Terraform, AWS CloudFormation, Ansible, Pulumi, and Azure Bicep help automate infrastructure management and maintain consistent environments.
List of Infrastructure as Code (IaC) MCQs
The following Infrastructure as Code MCQs cover fundamental concepts, provisioning approaches, configuration management, declarative and imperative models, popular tools, state management, modules, security, testing, and automation practices. Each question includes four options, the correct answer, and an explanation.
1. What is Infrastructure as Code (IaC)?
- A method of manually installing operating systems
- The practice of defining and managing infrastructure through machine-readable configuration files
- A programming language used only for frontend development
- A technique for designing computer hardware
Answer: B) The practice of defining and managing infrastructure through machine-readable configuration files
Explanation:
Infrastructure as Code allows teams to define and manage infrastructure resources using code or configuration files. It automates provisioning and configuration while making infrastructure definitions repeatable and version-controllable.
2. What is the primary objective of Infrastructure as Code?
- To eliminate the use of cloud computing
- To replace application programming languages
- To automate and standardize infrastructure provisioning and management
- To increase manual configuration tasks
Answer: C) To automate and standardize infrastructure provisioning and management
Explanation:
IaC reduces manual infrastructure work by defining resources through reusable configurations. It helps teams create consistent environments and manage infrastructure changes through automated workflows.
3. Which of the following is a popular Infrastructure as Code tool?
- Terraform
- Adobe Photoshop
- Microsoft Word
- VLC Media Player
Answer: A) Terraform
Explanation:
Terraform is an Infrastructure as Code tool that allows users to define and provision infrastructure through declarative configuration files. It supports multiple cloud providers and infrastructure platforms.
4. What does IaC stand for?
- Internet as a Component
- Integration and Configuration
- Infrastructure and Computing
- Infrastructure as Code
Answer: D) Infrastructure as Code
Explanation:
IaC is the abbreviation for Infrastructure as Code. It describes the practice of managing infrastructure through code-based definitions rather than relying entirely on manual configuration.
5. Which approach describes the desired final state of infrastructure?
- Manual provisioning
- Declarative approach
- Imperative approach
- Ad hoc configuration
Answer: B) Declarative approach
Explanation:
A declarative approach specifies what the infrastructure should look like rather than listing every command required to create it. The IaC tool determines the necessary actions to reach the desired state.
6. What is an imperative approach in Infrastructure as Code?
- Defining only the final infrastructure state
- Describing infrastructure without specifying operations
- Specifying the sequence of commands or actions required to configure infrastructure
- Managing infrastructure exclusively through graphical interfaces
Answer: C) Specifying the sequence of commands or actions required to configure infrastructure
Explanation:
An imperative approach defines the steps that must be executed to reach a particular infrastructure configuration. It focuses on how to perform an operation rather than only describing the desired outcome.
7. Which language is commonly used to write Terraform configuration files?
- HCL
- HTML
- CSS
- SQL
Answer: A) HCL
Explanation:
Terraform uses HashiCorp Configuration Language (HCL) as its primary configuration language. HCL provides a readable syntax for defining resources, variables, modules, and other infrastructure components.
8. What is the default file extension for Terraform configuration files?
- .json
- .yaml
- .tfstate
- .tf
Answer: D) .tf
Explanation:
Terraform configuration files generally use the `.tf` extension. These files contain resource definitions, provider configurations, variables, outputs, and other infrastructure settings.
9. What is the purpose of the Terraform init command?
- To delete all managed infrastructure
- To initialize a Terraform working directory and download required providers and modules
- To display application logs
- To automatically approve every infrastructure change
Answer: B) To initialize a Terraform working directory and download required providers and modules
Explanation:
The `terraform init` command prepares a working directory for Terraform operations. It initializes the backend, installs required providers, and retrieves referenced modules.
10. Which Terraform command previews the changes that will be made to infrastructure?
- terraform destroy
- terraform output
- terraform plan
- terraform version
Answer: C) terraform plan
Explanation:
The `terraform plan` command compares the desired configuration with the current infrastructure state and presents the proposed changes. It helps teams review planned modifications before applying them.
11. Which Terraform command applies the planned infrastructure changes?
- terraform apply
- terraform validate
- terraform fmt
- terraform graph
Answer: A) terraform apply
Explanation:
The `terraform apply` command executes the actions required to create, update, or remove infrastructure resources according to the configuration. It can use a previously generated plan file or create a new plan before applying changes.
12. What is the purpose of the Terraform destroy command?
- To format configuration files
- To validate Terraform syntax
- To display output variables
- To remove infrastructure resources managed by the current configuration
Answer: D) To remove infrastructure resources managed by the current configuration
Explanation:
The `terraform destroy` command plans and removes resources managed by the Terraform configuration. It should be used carefully because it can delete infrastructure and associated data.
13. What is Terraform state?
- A configuration file containing only provider credentials
- A record that maps Terraform configuration to managed infrastructure resources
- A document containing application source code
- A log file used only for debugging network requests
Answer: B) A record that maps Terraform configuration to managed infrastructure resources
Explanation:
Terraform state records information about resources managed by Terraform and their attributes. It helps Terraform determine which changes are required to move infrastructure toward the declared configuration.
14. Which file is commonly used by Terraform to store local state?
- main.py
- package.json
- terraform.tfstate
- index.html
Answer: C) terraform.tfstate
Explanation:
Terraform commonly stores local state in a file named `terraform.tfstate`. This file contains infrastructure metadata and resource information. In team environments, remote state storage is often preferred.
15. Why is remote state storage useful in Terraform?
- It allows teams to share state and coordinate infrastructure management
- It eliminates the need for configuration files
- It automatically removes unused resources
- It prevents Terraform from communicating with providers
Answer: A) It allows teams to share state and coordinate infrastructure management
Explanation:
Remote state allows multiple team members and automation systems to access a shared state location. Supported backends may also provide state locking and versioning to reduce conflicts during concurrent operations.
16. What is the purpose of a Terraform provider?
- To compile application source code
- To manage employee authentication
- To replace Terraform state files
- To allow Terraform to interact with infrastructure platforms and services
Answer: D) To allow Terraform to interact with infrastructure platforms and services
Explanation:
Terraform providers are plugins that enable communication with cloud platforms, infrastructure services, and other APIs. A provider supplies resource and data source types that can be used in Terraform configurations.
17. What is a Terraform module?
- A physical network device
- A reusable collection of Terraform configuration files
- A database backup file
- A tool for writing application documentation
Answer: B) A reusable collection of Terraform configuration files
Explanation:
A Terraform module groups related configuration files into a reusable unit. Modules help organize infrastructure code and create consistent resource patterns across projects and environments.
18. What is the main benefit of using reusable IaC modules?
- They eliminate the need for infrastructure testing
- They require every environment to use different configurations
- They reduce duplicated code and promote consistent infrastructure definitions
- They prevent teams from sharing infrastructure patterns
Answer: C) They reduce duplicated code and promote consistent infrastructure definitions
Explanation:
Reusable modules allow teams to define common infrastructure patterns once and use them in multiple projects. This reduces duplication and makes infrastructure configurations easier to maintain.
19. What is the purpose of variables in Terraform?
- To provide configurable values that can be reused in Terraform configurations
- To permanently store all infrastructure state
- To replace resource definitions
- To execute operating system commands automatically
Answer: A) To provide configurable values that can be reused in Terraform configurations
Explanation:
Terraform input variables allow users to customize configurations without changing the underlying resource definitions. They are useful for specifying values such as regions, instance sizes, names, and environment settings.
20. What is the purpose of output values in Terraform?
- To delete resources after deployment
- To define cloud provider authentication only
- To replace input variables
- To expose useful information produced by the configuration
Answer: D) To expose useful information produced by the configuration
Explanation:
Terraform outputs expose selected information after infrastructure operations. Examples include a virtual machine's public IP address, a database endpoint, or a resource identifier.
21. Which AWS service provides Infrastructure as Code through declarative templates?
- AWS CloudTrail
- AWS CloudFormation
- Amazon CloudFront
- Amazon Route 53
Answer: B) AWS CloudFormation
Explanation:
AWS CloudFormation allows users to define AWS resources in templates and provision them as stacks. It supports repeatable infrastructure deployment and management within the AWS ecosystem.
22. Which format is commonly supported for AWS CloudFormation templates?
- MP3 and WAV
- PNG and JPEG
- JSON and YAML
- DOCX and XLSX
Answer: C) JSON and YAML
Explanation:
AWS CloudFormation templates can be written in JSON or YAML. These formats describe resources, parameters, mappings, outputs, and other infrastructure configuration details.
23. Which tool is primarily known for configuration management and automation?
- Ansible
- Photoshop
- PowerPoint
- Microsoft Access
Answer: A) Ansible
Explanation:
Ansible is an automation tool commonly used for configuration management, application deployment, and infrastructure automation. It uses YAML-based playbooks to describe tasks and desired configurations.
24. What is an Ansible playbook?
- A document containing only application screenshots
- A database containing cloud billing records
- A compiled application executable
- A YAML file that defines automation tasks and their execution
Answer: D) A YAML file that defines automation tasks and their execution
Explanation:
An Ansible playbook defines a set of automation tasks that should be executed on specified hosts. It can be used to install packages, configure services, manage users, and deploy applications.
25. What does idempotency mean in Infrastructure as Code?
- Executing the same configuration repeatedly creates unlimited duplicate resources
- Repeated execution produces the same intended state when the relevant inputs and external conditions remain unchanged
- Infrastructure must be configured manually every time
- All configuration changes are permanently disabled
Answer: B) Repeated execution produces the same intended state when the relevant inputs and external conditions remain unchanged
Explanation:
Idempotency means that applying the same desired configuration multiple times does not introduce additional unintended changes. It is an important property of declarative infrastructure and configuration management systems.
26. What is configuration drift in Infrastructure as Code?
- A process of creating new programming languages
- A method of increasing database storage
- A difference between the declared infrastructure configuration and the actual infrastructure state
- A technique for compressing configuration files
Answer: C) A difference between the declared infrastructure configuration and the actual infrastructure state
Explanation:
Configuration drift occurs when infrastructure is changed outside the IaC workflow or when actual resources no longer match the desired configuration. Drift detection helps teams identify and address these differences.
27. How does version control benefit Infrastructure as Code?
- It tracks configuration changes and supports collaboration and rollback
- It automatically replaces all cloud providers
- It removes the need for infrastructure documentation
- It prevents teams from reviewing configuration changes
Answer: A) It tracks configuration changes and supports collaboration and rollback
Explanation:
Version control systems such as Git maintain a history of infrastructure code changes. Teams can review modifications, collaborate through branches, identify errors, and restore earlier versions when necessary.
28. Which Git practice is useful for reviewing IaC changes before merging them?
- Deleting the repository history
- Disabling code reviews
- Sharing administrator credentials
- Creating pull requests and reviewing proposed changes
Answer: D) Creating pull requests and reviewing proposed changes
Explanation:
Pull requests allow team members to inspect infrastructure changes before merging them into the main branch. Reviewers can identify incorrect resource definitions, security problems, and potentially destructive modifications.
29. What is the purpose of testing Infrastructure as Code?
- To increase the number of manual deployment steps
- To identify configuration errors, policy violations, and unintended infrastructure changes
- To eliminate the need for version control
- To replace all infrastructure monitoring systems
Answer: B) To identify configuration errors, policy violations, and unintended infrastructure changes
Explanation:
IaC testing helps verify that configurations are valid, secure, and consistent with expected requirements. Testing can include syntax validation, static analysis, policy checks, and deployment tests.
30. Which Terraform command checks configuration syntax and internal consistency?
- terraform destroy
- terraform output
- terraform validate
- terraform login
Answer: C) terraform validate
Explanation:
The `terraform validate` command checks whether Terraform configuration files are syntactically valid and internally consistent. It does not confirm that resources can be successfully created in a real environment.
31. What is the purpose of the Terraform fmt command?
- To format Terraform configuration files consistently
- To remove all infrastructure resources
- To create remote state automatically
- To install cloud provider operating systems
Answer: A) To format Terraform configuration files consistently
Explanation:
The `terraform fmt` command automatically formats Terraform configuration files according to standard formatting conventions. Consistent formatting improves readability and simplifies code reviews.
32. What is a Terraform data source used for?
- To delete existing infrastructure resources
- To store Terraform provider credentials in plain text
- To replace all resource blocks
- To retrieve information about existing resources or external data
Answer: D) To retrieve information about existing resources or external data
Explanation:
Terraform data sources allow configurations to read information about existing infrastructure or external systems. They can be used to reference existing networks, images, resource identifiers, and other values without managing those objects directly.
33. What is the purpose of a Terraform workspace?
- To create a graphical application interface
- To manage separate state instances for the same configuration
- To replace infrastructure providers
- To automatically convert imperative code into declarative code
Answer: B) To manage separate state instances for the same configuration
Explanation:
Terraform workspaces allow a configuration to use multiple separate state instances. They can be useful for managing distinct environments, although separate configurations or other isolation strategies may be more appropriate for complex production environments.
34. What is a backend in Terraform?
- A programming language for writing application interfaces
- A tool used only for container image creation
- A component that determines how Terraform state is stored and managed
- A database used exclusively for application analytics
Answer: C) A component that determines how Terraform state is stored and managed
Explanation:
A Terraform backend defines where and how state is stored. Backends may use local storage or remote services that support shared access and, depending on the backend, state locking and versioning.
35. Why should sensitive values be protected in IaC configurations?
- To prevent credentials, tokens, and other confidential information from being exposed
- To make infrastructure configurations unreadable to authorized users
- To eliminate the need for authentication
- To allow every developer to access all secrets
Answer: A) To prevent credentials, tokens, and other confidential information from being exposed
Explanation:
IaC files and state data may contain sensitive information. Teams should use secret management systems, restricted access, encryption, and secure CI/CD practices to protect credentials and confidential values.
36. What is policy as code in Infrastructure as Code?
- Writing infrastructure requirements in printed documents only
- Disabling automated infrastructure checks
- Replacing resource definitions with manual instructions
- Representing governance and security rules as executable policies
Answer: D) Representing governance and security rules as executable policies
Explanation:
Policy as Code defines organizational rules in a machine-readable form. Automated policy checks can prevent infrastructure configurations that violate security, compliance, or resource management requirements.
37. Which tool can be used to enforce policy rules in Terraform workflows?
- VLC Media Player
- Open Policy Agent (OPA)
- Microsoft Paint
- Adobe Acrobat Reader
Answer: B) Open Policy Agent (OPA)
Explanation:
Open Policy Agent is an open-source policy engine that evaluates policies against structured data. It can be integrated into infrastructure workflows to enforce governance and security requirements.
38. What is the role of CI/CD pipelines in Infrastructure as Code?
- To replace all infrastructure configuration files
- To manage employee access cards
- To automate validation, testing, review, and deployment of infrastructure changes
- To prevent infrastructure changes from being tracked
Answer: C) To automate validation, testing, review, and deployment of infrastructure changes
Explanation:
CI/CD pipelines automate steps involved in managing infrastructure code. They can run formatting checks, validation, security scans, Terraform plans, approvals, and deployment operations.
39. What is immutable infrastructure?
- An approach in which existing infrastructure instances are replaced rather than modified in place for changes
- A method of manually editing every server configuration
- A system that prevents infrastructure from being deployed
- A technique for storing application source code
Answer: A) An approach in which existing infrastructure instances are replaced rather than modified in place for changes
Explanation:
Immutable infrastructure uses replacement rather than modifying existing instances when changes are needed. New instances are created with the desired configuration, tested, and then used in place of older instances.
40. What is configuration management in infrastructure automation?
- Managing financial budgets for cloud providers
- Creating software marketing plans
- Tracking employee attendance
- Maintaining systems in a defined configuration by managing settings, packages, and services
Answer: D) Maintaining systems in a defined configuration by managing settings, packages, and services
Explanation:
Configuration management ensures that systems maintain the required software packages, settings, services, and other configurations. Tools such as Ansible, Puppet, and Chef support configuration management and automation.
41. Which tool is commonly associated with declarative configuration management?
- Microsoft Paint
- Puppet
- Adobe Photoshop
- VLC Media Player
Answer: B) Puppet
Explanation:
Puppet is a configuration management tool that uses a declarative model to describe the desired state of systems. It helps automate configuration enforcement across multiple machines.
42. What is the main difference between Infrastructure as Code and traditional manual provisioning?
- IaC does not support cloud infrastructure
- Manual provisioning always requires less effort
- IaC uses reusable, version-controlled definitions and automation instead of relying mainly on manual configuration
- There is no difference between the two approaches
Answer: C) IaC uses reusable, version-controlled definitions and automation instead of relying mainly on manual configuration
Explanation:
Traditional manual provisioning depends on people configuring infrastructure through individual commands or graphical interfaces. IaC defines infrastructure in code, allowing teams to automate, review, reproduce, and track changes.
43. What is drift detection in Infrastructure as Code?
- Identifying differences between declared configuration and actual infrastructure
- Measuring application user engagement
- Monitoring employee attendance
- Testing frontend page layouts
Answer: A) Identifying differences between declared configuration and actual infrastructure
Explanation:
Drift detection compares the expected infrastructure state with the actual deployed resources. It helps teams identify manual changes, unexpected modifications, and configuration inconsistencies.
44. Which of the following is a major advantage of using IaC in cloud environments?
- It eliminates the need for cloud security
- It prevents teams from creating multiple environments
- It requires all resources to be managed manually
- It enables repeatable and automated provisioning of cloud resources
Answer: D) It enables repeatable and automated provisioning of cloud resources
Explanation:
IaC allows teams to create cloud resources using reusable configuration files. The same infrastructure definitions can be applied across development, testing, staging, and production environments with appropriate parameter values.
45. What is the purpose of an IaC plan or preview operation?
- To delete all existing infrastructure automatically
- To review proposed infrastructure changes before applying them
- To disable configuration validation
- To replace remote state storage
Answer: B) To review proposed infrastructure changes before applying them
Explanation:
A plan or preview operation shows the infrastructure changes that a tool intends to perform. Reviewing these changes helps teams detect unexpected resource creation, modification, or deletion before deployment.
46. Which practice improves the security of Infrastructure as Code repositories?
- Storing all credentials directly in public configuration files
- Giving every contributor administrator access
- Using secret management, access controls, and automated security scanning
- Disabling repository review and audit history
Answer: C) Using secret management, access controls, and automated security scanning
Explanation:
Secure IaC practices include protecting credentials, limiting repository permissions, scanning configurations for vulnerabilities, and reviewing changes before deployment. These controls reduce the risk of accidental exposure and insecure infrastructure.
47. What is the purpose of a resource dependency in Terraform?
- To define relationships that determine the order in which resources are created or modified
- To store passwords in configuration files
- To disable resource provisioning
- To replace provider configurations
Answer: A) To define relationships that determine the order in which resources are created or modified
Explanation:
Terraform uses dependencies to determine the correct execution order for infrastructure operations. Some dependencies are inferred from references between resources, while explicit dependencies can be declared when necessary.
48. What is the purpose of the depends_on argument in Terraform?
- To define input variable types
- To configure the remote state backend
- To format Terraform files
- To specify an explicit dependency between resources or modules
Answer: D) To specify an explicit dependency between resources or modules
Explanation:
The `depends_on` argument tells Terraform that one resource or module must wait for another resource or module. It is useful when a dependency cannot be determined automatically through configuration references.
49. Which statement best describes the relationship between Infrastructure as Code and DevOps?
- IaC replaces all DevOps practices
- IaC supports DevOps by automating infrastructure provisioning and enabling consistent, repeatable environments
- DevOps does not use infrastructure automation
- IaC is used only for frontend application development
Answer: B) IaC supports DevOps by automating infrastructure provisioning and enabling consistent, repeatable environments
Explanation:
Infrastructure as Code is an important DevOps practice because it brings automation, version control, testing, and repeatability to infrastructure management. It helps development and operations teams manage infrastructure changes through shared workflows.
50. A company uses Infrastructure as Code to provision 20 identical development environments. Manual provisioning takes 45 minutes per environment, while automated provisioning takes 9 minutes per environment. How much total time is saved by using IaC?
- 10 hours
- 12 hours
- 15 hours
- 18 hours
Answer: C) 12 hours
Explanation:
Manual provisioning time for 20 environments = 20 × 45 = 900 minutes.
Automated provisioning time for 20 environments = 20 × 9 = 180 minutes.
Total time saved = 900 - 180 = 720 minutes.
Convert minutes into hours: 720 / 60 = 12 hours.
Therefore, using Infrastructure as Code saves a total of 12 hours when provisioning all 20 environments.