programming beginner 10 sample questions

Infrastructure As Code (iac) MCQ Practice Test

Using tools like Terraform to manage cloud resources programmatically.

Q1. You're managing a multi-region deployment using Terraform. Your main state file is stored in a remote backend (e.g., S3). A developer accidentally deletes a crucial resource in the 'us-east-1' region. Which Terraform command, executed in the root module directory, will MOST efficiently identify the difference between the desired state (defined in your Terraform configuration) and the actual state in 'us-east-1', *without* applying changes?

Explanation: While `terraform refresh` updates the state file from the remote backend, it doesn't show the differences between the desired and actual state. `terraform show` displays the current state, not the comparison. `terraform state list` lists all resources, not just the differences. `terraform plan -target=us-east-1` specifically compares the desired state against the actual state in 'us-east-1', pinpointing the discrepancies without applying any changes.

Q2. You're managing infrastructure as code using Terraform for a multi-region application. Your state file is stored in a remote backend using the AWS S3 backend. To ensure that only authorized users can modify the state file and prevent accidental deletion or corruption, which of the following configurations offers the STRONGEST security posture?

Explanation: Using IAM roles provides fine-grained access control, limiting actions to only what's needed. While bucket policies and IP restrictions offer some security, IAM roles offer more granular control and are less prone to configuration errors. Server-side encryption is important for data protection at rest, but access control is paramount for preventing unauthorized modifications.

Q3. When using Terraform to manage AWS infrastructure as code, which of the following best describes the purpose of a "module"?

Explanation: In Terraform, a module is a reusable collection of Terraform configurations that can be used to provision multiple resources. This allows developers to break down large infrastructure configurations into smaller, more manageable pieces and reuse them across multiple environments.

Q4. In a Terraform configuration, you want to create a resource that depends on another resource that is created by a different Terraform module. Which of the following Terraform constructs can be used to achieve this?

Explanation: Terraform Module Output can be used to expose values from a module to the parent configuration, allowing dependent resources to be created. This is achieved by using the output keyword in the module configuration and then referencing the output value in the parent configuration using the module output name.

Q5. In a Terraform configuration, which statement is used to specify the AWS IAM role that an AWS Lambda function assumes?

Explanation: In Terraform, the role of an AWS Lambda function is specified using the 'role' attribute within the 'resource' block for the AWS Lambda function. The 'aws_iam_role' resource is used to create the IAM role, and its ARN is referenced by the Lambda function.

Q6. In Terraform, what is the purpose of the 'terraform state' file?

Explanation: The 'terraform state' file is used to store the current state of the infrastructure, including the IDs of all resources created by Terraform. This allows Terraform to keep track of the resources it has created and make changes to them as needed.

Q7. What is the primary purpose of using a “state file” in a Terraform configuration?

Explanation: A state file in Terraform is used to store the current state of the infrastructure as code configuration, allowing Terraform to track changes and ensure consistency between the desired state and the actual state of the infrastructure.

Q8. In a Terraform configuration, which of the following statements is used to create a new resource, but only if it doesn't already exist?

Explanation: In Terraform, the "resource null" statement is used to create a new resource only if it doesn't already exist. This is known as a 'null resource'. It's often used to create a resource and then delete it immediately, effectively creating the resource only if it doesn't already exist. This is useful for idempotency and ensuring that resources are only created when needed.

Q9. In Terraform, what is the purpose of the "depends_on" argument in a resource block?

Explanation: The "depends_on" argument in Terraform is used to specify that one resource depends on another resource being created first. This ensures that the dependent resource is created only after the resource it depends on has been created.

Q10. Which Terraform configuration statement is used to create a new AWS Elastic Load Balancer in a VPC?

Explanation: In Terraform, the aws_lb resource type is used to create and manage Elastic Load Balancers in AWS. When creating a new Elastic Load Balancer in a VPC, the aws_lb resource type is used along with the alb_target_group and alb_listener resources to configure the load balancer. The aws_elastic_lb resource type is deprecated in Terraform 0.12 and later, and should not be used.

That was just a sample. Sign up to unlock the full question bank with timed tests and certificates.

Sign Up Free
Infrastructure As Code (iac) MCQ Practice Test | Mind Hustle