×

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)?

  1. A method of manually installing operating systems
  2. The practice of defining and managing infrastructure through machine-readable configuration files
  3. A programming language used only for frontend development
  4. 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?

  1. To eliminate the use of cloud computing
  2. To replace application programming languages
  3. To automate and standardize infrastructure provisioning and management
  4. 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?

  1. Terraform
  2. Adobe Photoshop
  3. Microsoft Word
  4. 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?

  1. Internet as a Component
  2. Integration and Configuration
  3. Infrastructure and Computing
  4. 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?

  1. Manual provisioning
  2. Declarative approach
  3. Imperative approach
  4. 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?

  1. Defining only the final infrastructure state
  2. Describing infrastructure without specifying operations
  3. Specifying the sequence of commands or actions required to configure infrastructure
  4. 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?

  1. HCL
  2. HTML
  3. CSS
  4. 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?

  1. .json
  2. .yaml
  3. .tfstate
  4. .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?

  1. To delete all managed infrastructure
  2. To initialize a Terraform working directory and download required providers and modules
  3. To display application logs
  4. 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?

  1. terraform destroy
  2. terraform output
  3. terraform plan
  4. 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?

  1. terraform apply
  2. terraform validate
  3. terraform fmt
  4. 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?

  1. To format configuration files
  2. To validate Terraform syntax
  3. To display output variables
  4. 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?

  1. A configuration file containing only provider credentials
  2. A record that maps Terraform configuration to managed infrastructure resources
  3. A document containing application source code
  4. 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?

  1. main.py
  2. package.json
  3. terraform.tfstate
  4. 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?

  1. It allows teams to share state and coordinate infrastructure management
  2. It eliminates the need for configuration files
  3. It automatically removes unused resources
  4. 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?

  1. To compile application source code
  2. To manage employee authentication
  3. To replace Terraform state files
  4. 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?

  1. A physical network device
  2. A reusable collection of Terraform configuration files
  3. A database backup file
  4. 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?

  1. They eliminate the need for infrastructure testing
  2. They require every environment to use different configurations
  3. They reduce duplicated code and promote consistent infrastructure definitions
  4. 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?

  1. To provide configurable values that can be reused in Terraform configurations
  2. To permanently store all infrastructure state
  3. To replace resource definitions
  4. 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?

  1. To delete resources after deployment
  2. To define cloud provider authentication only
  3. To replace input variables
  4. 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?

  1. AWS CloudTrail
  2. AWS CloudFormation
  3. Amazon CloudFront
  4. 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?

  1. MP3 and WAV
  2. PNG and JPEG
  3. JSON and YAML
  4. 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?

  1. Ansible
  2. Photoshop
  3. PowerPoint
  4. 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?

  1. A document containing only application screenshots
  2. A database containing cloud billing records
  3. A compiled application executable
  4. 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?

  1. Executing the same configuration repeatedly creates unlimited duplicate resources
  2. Repeated execution produces the same intended state when the relevant inputs and external conditions remain unchanged
  3. Infrastructure must be configured manually every time
  4. 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?

  1. A process of creating new programming languages
  2. A method of increasing database storage
  3. A difference between the declared infrastructure configuration and the actual infrastructure state
  4. 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?

  1. It tracks configuration changes and supports collaboration and rollback
  2. It automatically replaces all cloud providers
  3. It removes the need for infrastructure documentation
  4. 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?

  1. Deleting the repository history
  2. Disabling code reviews
  3. Sharing administrator credentials
  4. 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?

  1. To increase the number of manual deployment steps
  2. To identify configuration errors, policy violations, and unintended infrastructure changes
  3. To eliminate the need for version control
  4. 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?

  1. terraform destroy
  2. terraform output
  3. terraform validate
  4. 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?

  1. To format Terraform configuration files consistently
  2. To remove all infrastructure resources
  3. To create remote state automatically
  4. 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?

  1. To delete existing infrastructure resources
  2. To store Terraform provider credentials in plain text
  3. To replace all resource blocks
  4. 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?

  1. To create a graphical application interface
  2. To manage separate state instances for the same configuration
  3. To replace infrastructure providers
  4. 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?

  1. A programming language for writing application interfaces
  2. A tool used only for container image creation
  3. A component that determines how Terraform state is stored and managed
  4. 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?

  1. To prevent credentials, tokens, and other confidential information from being exposed
  2. To make infrastructure configurations unreadable to authorized users
  3. To eliminate the need for authentication
  4. 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?

  1. Writing infrastructure requirements in printed documents only
  2. Disabling automated infrastructure checks
  3. Replacing resource definitions with manual instructions
  4. 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?

  1. VLC Media Player
  2. Open Policy Agent (OPA)
  3. Microsoft Paint
  4. 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?

  1. To replace all infrastructure configuration files
  2. To manage employee access cards
  3. To automate validation, testing, review, and deployment of infrastructure changes
  4. 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?

  1. An approach in which existing infrastructure instances are replaced rather than modified in place for changes
  2. A method of manually editing every server configuration
  3. A system that prevents infrastructure from being deployed
  4. 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?

  1. Managing financial budgets for cloud providers
  2. Creating software marketing plans
  3. Tracking employee attendance
  4. 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?

  1. Microsoft Paint
  2. Puppet
  3. Adobe Photoshop
  4. 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?

  1. IaC does not support cloud infrastructure
  2. Manual provisioning always requires less effort
  3. IaC uses reusable, version-controlled definitions and automation instead of relying mainly on manual configuration
  4. 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?

  1. Identifying differences between declared configuration and actual infrastructure
  2. Measuring application user engagement
  3. Monitoring employee attendance
  4. 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?

  1. It eliminates the need for cloud security
  2. It prevents teams from creating multiple environments
  3. It requires all resources to be managed manually
  4. 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?

  1. To delete all existing infrastructure automatically
  2. To review proposed infrastructure changes before applying them
  3. To disable configuration validation
  4. 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?

  1. Storing all credentials directly in public configuration files
  2. Giving every contributor administrator access
  3. Using secret management, access controls, and automated security scanning
  4. 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?

  1. To define relationships that determine the order in which resources are created or modified
  2. To store passwords in configuration files
  3. To disable resource provisioning
  4. 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?

  1. To define input variable types
  2. To configure the remote state backend
  3. To format Terraform files
  4. 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?

  1. IaC replaces all DevOps practices
  2. IaC supports DevOps by automating infrastructure provisioning and enabling consistent, repeatable environments
  3. DevOps does not use infrastructure automation
  4. 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?

  1. 10 hours
  2. 12 hours
  3. 15 hours
  4. 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.

Comments and Discussions!

Load comments ↻



Copyright © 2026 www.includehelp.com. All rights reserved.