Day 71  Let's prepare for some interview questions of Terraform

Day 71 Let's prepare for some interview questions of Terraform

Day 71 of #90daysofdevops

Hey Techies! Welcome to this blog

In this blog, we are going to start with some interview questions of Terraform.

Questions:-

1. What is Terraform and how it is different from other IaaC tools?

Ans: Terraform is an Infrastructure as Code(IaC) tool that allows engineers to define their software infrastructure in code. Terraform is an open-source Infrastructure as Code (IaaC) tool developed by HashiCorp. It allows users to define and provision infrastructure using a declarative configuration language. Unlike other IaaC tools, Terraform is cloud-agnostic, supporting various cloud providers, on-premises environments, and services. Its key differentiates lies in its ability to create a unified workflow for managing multi-cloud infrastructure.

2. How do you call a main.tf module?

Ans: The main.tf module in Terraform is automatically loaded without explicit invocation. Terraform expects to find and load a file named main.tf in the working directory, making it the default entry point for configuration.

3. What exactly is Sentinel? Can you provide few examples where we can use for Sentinel policies?

Ans: Sentinel Policies are rules which are enforced on Terraform runs to validate that the plan and corresponding resources are in compliance with company policies.

It helps enforce and automate governance policies in the deployment pipeline. Examples of Sentinel policies include ensuring specific resource tag conventions, restricting the use of certain cloud resources, and enforcing naming conventions.

4. You have a Terraform configuration file that defines an infrastructure deployment. However, there are multiple instances of the same resource that need to be created. How would you modify the configuration file to achieve this?

Ans: To create multiple instances of the same resource, you can use a count parameter within the resource block. This parameter specifies the number of instances to create. For example:

resource "example_resource" {
  count = 3
  # other configurations...
}

5. You want to know from which paths Terraform is loading providers referenced in your Terraform configuration (*.tf files). You need to enable debug messages to find this out. Which of the following would achieve this?

A. Set the environment variable TF_LOG=TRACE

B. Set verbose logging for each provider in your Terraform configuration

C. Set the environment variable TF_VAR_log=TRACE

D. Set the environment variable TF_LOG_PATH

Ans: A. Set the environment variable TF_LOG=TRACE enables debug messages and helps identify the paths from which Terraform is loading providers.

6. Below command will destroy everything that is being created in the infrastructure. Tell us how would you save any particular resource while destroying the complete infrastructure.

terraform destroy

Ans: While running terraform destroy, you can target a specific resource for preservation using the -target flag. For example:

terraform destroy -target=aws_instance.example

7. Which module is used to store .tfstate file in S3?

Ans: The terraform_backend_s3 module is used to store the .tfstate file in an S3 bucket.

8. How do you manage sensitive data in Terraform, such as API keys or passwords?

Ans: Sensitive data like API keys or passwords should be managed using Terraform's sensitive input variables. These values are marked as sensitive, preventing them from being displayed in the console output or stored in the state file.

9. You are working on a Terraform project that needs to provision an S3 bucket, and a user with read and write access to the bucket. What resources would you use to accomplish this, and how would you configure them?

Ans: To achieve this, you would use the aws_s3_bucket resource to create the S3 bucket and the aws_iam_user and aws_iam_user_policy resources to create a user with the necessary permissions. The policies should be attached to the user to grant read and write access to the S3 bucket.

10. Who maintains Terraform providers?

Ans: Terraform providers are maintained by the respective cloud service providers or third-party contributors. HashiCorp, the creator of Terraform, maintains some core providers, while others are developed and maintained by the community or specific organizations.

11. How can we export data from one module to another?

Ans: Data can be exported from one module to another using Terraform outputs. In the exporting module, define the data as an output variable, and in the importing module, reference the exported data using the module syntax.

Thank you so much for taking the time to read till the end! Hope you found this blog informative and helpful.

Feel free to explore more of my content, and don't hesitate to reach out if need any assistance from me or in case of you have any questions.

Happy Learning!

~kritika :)

Connect with me: LinkedIn