Terraform

Skill
DevOps

Top 50 Terraform Interview Questions and Answers 2025

56 questions found

Updated 29 Nov 2024

Q1. Write a terraform code for a resource?

Ans.

Terraform code for creating an AWS EC2 instance

  • Define provider and resource block in main.tf file

  • Specify the AMI, instance type, key pair, and security group in the resource block

  • Run 'terraform init', 'terraform plan', and 'terraform apply' commands to create the EC2 instance

View 1 answer

Q2. What are modules in terraform?

Ans.

Modules in Terraform are reusable configurations that can be used to create multiple instances of resources.

  • Modules help in organizing and reusing Terraform configurations.

  • They allow for creating reusable components that can be shared across different projects.

  • Modules can be used to encapsulate related resources and configurations.

  • They promote code reusability and maintainability in Terraform scripts.

Add your answer

Q3. What is ansible and terraform?

Ans.

Ansible and Terraform are both infrastructure as code tools used for automation and configuration management.

  • Ansible is a tool for automating software provisioning, configuration management, and application deployment.

  • Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently.

  • Ansible uses YAML-based playbooks to define tasks and configurations, while Terraform uses a domain-specific language (DSL) called HCL.

  • Both tools are popular in the ...read more

Add your answer

Q4. Explain the modules in Terraform

Ans.

Terraform modules are reusable components that define a set of resources in a Terraform configuration.

  • Modules help organize and reuse Terraform code

  • They encapsulate a set of resources and can be shared across projects

  • Modules can have input variables and output values

  • They can be stored locally or remotely in a version control system like Git

Add your answer
Are these interview questions helpful?

Q5. What’s terraform and chef

Ans.

Terraform is an infrastructure as code tool used for building, changing, and versioning infrastructure safely and efficiently. Chef is a configuration management tool used for automating the deployment, scaling, and management of infrastructure.

  • Terraform is used to define and provision infrastructure using declarative configuration files.

  • Chef is used to automate the configuration and management of servers and applications.

  • Terraform supports multiple cloud providers such as AW...read more

View 1 answer
Frequently asked in

Q6. write code of provider.tf

Ans.

provider.tf code for Softwaretest Engineer interview

  • Use Terraform to define the provider configuration in provider.tf

  • Specify the provider type and version in the code

  • Example: provider.tf - provider "aws" { region = "us-west-2" }

Add your answer
Share interview questions and help millions of jobseekers 🌟

Q7. Write terraform module for any AWS resources.

Ans.

Terraform module for creating an AWS S3 bucket

  • Define variables for bucket name, region, and tags

  • Create S3 bucket resource with specified variables

  • Add bucket policy for access control

  • Output bucket ARN for reference

Add your answer

Q8. What errors you have faced while applying terraform code?

Ans.

I have faced errors such as resource conflicts, syntax errors, and provider version mismatches while applying Terraform code.

  • Resource conflicts occur when multiple resources are trying to create the same resource at the same time.

  • Syntax errors can occur due to incorrect syntax in the Terraform code, such as missing brackets or incorrect attribute names.

  • Provider version mismatches can occur when the Terraform code is written for a specific provider version but a different vers...read more

Add your answer

Terraform Jobs

Sr DevOps Engineer 12-17 years
IBM India Pvt. Limited
4.1
Bangalore / Bengaluru
Application Developer: AWS Cloud FullStack 4-8 years
IBM India Pvt. Limited
4.1
Hyderabad / Secunderabad
Application Developer: AWS Cloud FullStack 4-8 years
IBM India Pvt. Limited
4.1
Hyderabad / Secunderabad

Q9. What is Docker, Terraform?

Ans.

Docker is a platform for developing, shipping, and running applications in containers. Terraform is an infrastructure as code tool for building, changing, and versioning infrastructure safely and efficiently.

  • Docker allows applications to be packaged with all dependencies into a container for easy deployment.

  • Terraform enables infrastructure to be defined in code, making it easier to manage and scale.

  • Both tools are commonly used in DevOps practices to streamline development and...read more

Add your answer

Q10. Are you aware of script / terraform

Ans.

Yes, I am aware of both script and Terraform.

  • I have experience writing scripts in languages like Python, Bash, and PowerShell.

  • I have used Terraform to automate infrastructure provisioning and management.

  • I am familiar with creating and managing infrastructure as code using Terraform.

Add your answer
Frequently asked in

Q11. How would you handle terraform state in file system?

Ans.

Terraform state in file system can be managed using remote backends or local state files.

  • Use remote backends like S3, Azure Blob Storage, or Google Cloud Storage for better collaboration and security.

  • If using local state files, store them in a version-controlled directory to track changes and prevent conflicts.

  • Consider using Terraform Cloud for centralized state management and collaboration among team members.

Add your answer

Q12. What are namespaces in terraform

Ans.

Namespaces in Terraform are used to group resources together and prevent naming conflicts.

  • Namespaces allow you to organize resources within a Terraform configuration

  • They help prevent naming conflicts by prefixing resource names with a specified namespace

  • Namespaces are defined using the 'namespace' parameter in Terraform configurations

  • Example: namespace = 'prod' will prefix all resources with 'prod_'

Add your answer

Q13. How did you use terraform to build the infrastructure?

Ans.

I used Terraform to automate the provisioning and management of infrastructure resources.

  • I defined infrastructure as code using Terraform configuration files

  • I used Terraform commands to create, update, and destroy infrastructure resources

  • I leveraged Terraform modules to reuse and share infrastructure configurations

  • I integrated Terraform with version control systems for collaboration and versioning

  • I utilized Terraform providers to interact with different cloud providers and se...read more

Add your answer
Frequently asked in

Q14. What will lookup function do in terraform

Ans.

Lookup function in Terraform retrieves the value of a named attribute from a named data source.

  • Lookup function is used to retrieve the value of a named attribute from a named data source.

  • It is commonly used to retrieve values from remote systems or data sources.

  • If the attribute is not found, it returns a default value.

  • Syntax: lookup(map, key, default_value)

  • Example: lookup(var.my_map, "key_name", "default_value")

Add your answer

Q15. What is tf State file in terraform

Ans.

Terraform state file is a file that keeps track of the resources managed by Terraform in a specific infrastructure.

  • Terraform state file stores metadata about the resources being managed.

  • It helps Terraform understand the current state of the infrastructure and track changes over time.

  • State file is usually stored locally or remotely in a backend like AWS S3 or Terraform Cloud.

  • It should be stored securely to prevent unauthorized access or modifications.

Add your answer
Frequently asked in

Q16. what is tf state files

Ans.

Tf state files are files generated by Terraform to store the state of your infrastructure.

  • Tf state files store information about the resources managed by Terraform

  • They help Terraform track the current state of your infrastructure

  • Tf state files should be stored securely to prevent unauthorized access

Add your answer
Frequently asked in

Q17. What is NullResource in terraform.

Ans.

NullResource in Terraform is a resource that performs no actions when applied, but can be used to trigger provisioners or other side effects.

  • NullResource is a resource type in Terraform that allows you to run provisioners without creating any infrastructure.

  • It can be used to trigger actions like running scripts or commands on the local machine or remote servers.

  • NullResource is often used for tasks like running initialization scripts, setting up configurations, or executing cu...read more

Add your answer

Q18. How terraform Metaarguments works in multiple scenario scenarios

Ans.

Terraform Metaarguments are used to modify the behavior of resources in different scenarios.

  • Metaarguments can be used to control how Terraform handles resources, such as count, depends_on, lifecycle, provider, etc.

  • They can be used to define dependencies between resources, manage resource creation and deletion, and specify resource behavior.

  • Metaarguments can be used in various scenarios like defining resource dependencies, managing resource lifecycle, specifying provider confi...read more

Add your answer
Frequently asked in

Q19. How to write composite terraform module and pass their values to other modules.

Ans.

Creating composite Terraform modules and passing values to other modules.

  • Create a main module that calls other modules

  • Define input variables in the main module and pass them to the child modules

  • Use output variables in the child modules to return values to the main module

  • Example: main.tf calls moduleA and moduleB, passing variables and using outputs

Add your answer
Frequently asked in

Q20. Deep dive in Terraform and Python

Ans.

Terraform is an infrastructure as code tool, while Python is a versatile programming language often used for automation in DevOps.

  • Terraform is used for provisioning and managing infrastructure resources in a declarative way.

  • Python is commonly used for scripting, automation, and building tools in the DevOps ecosystem.

  • Terraform can be integrated with Python scripts to enhance automation capabilities.

  • Both Terraform and Python have extensive community support and documentation fo...read more

Add your answer

Q21. Devops implementation process for terraform deployments

Ans.

DevOps implementation process for Terraform deployments involves version control, infrastructure as code, automation, and collaboration.

  • Utilize version control systems like Git to manage Terraform code

  • Implement infrastructure as code principles to define and provision resources

  • Leverage automation tools like Jenkins or GitLab CI/CD pipelines for continuous deployment

  • Encourage collaboration between development and operations teams for seamless deployment processes

Add your answer

Q22. Terraform and its workspace

Ans.

Terraform workspaces allow multiple environments to be managed with a single configuration.

  • Terraform workspaces are used to manage multiple environments such as development, staging, and production.

  • Each workspace has its own state file, allowing for separate configurations and resources.

  • Workspaces can be created, selected, and deleted using the terraform workspace command.

  • Variables can be set for each workspace using the -var-file flag.

  • Terraform Enterprise allows for more adv...read more

Add your answer

Q23. Terraform state files and where are they stored?

Ans.

Terraform state files store the current state of infrastructure managed by Terraform.

  • State files are JSON files that contain information about the resources being managed by Terraform.

  • They are stored locally by default, but can also be stored remotely in a backend like S3 or Consul.

  • State files should be treated as sensitive information and stored securely.

  • Terraform uses state files to plan and apply changes to infrastructure.

  • State files can be manually edited, but this is not...read more

Add your answer

Q24. Terraform templates to create aks

Ans.

Terraform templates can be used to create AKS clusters.

  • Use the azurerm_kubernetes_cluster resource in Terraform to create an AKS cluster.

  • Specify the required parameters such as resource group, location, node count, and node size.

  • Use the azurerm_kubernetes_service_principal resource to create a service principal for the AKS cluster.

  • Use the azurerm_kubernetes_cluster_node_pool resource to create node pools with specific configurations.

  • Use the azurerm_kubernetes_cluster_role_ass...read more

Add your answer
Frequently asked in

Q25. Container creation in terraform

Ans.

Container creation in terraform involves defining a container resource in a terraform configuration file.

  • Define a container resource in the terraform configuration file using the 'docker_container' or 'container' provider.

  • Specify the image, name, ports, and other necessary configurations for the container.

  • Run 'terraform init' and 'terraform apply' to create the container based on the defined configuration.

Add your answer
Frequently asked in

Q26. Terraform experience with EKS clusters creation

Ans.

Experience with Terraform for creating EKS clusters

  • Utilize Terraform modules to define EKS cluster resources

  • Leverage Terraform provider for AWS to interact with EKS API

  • Use Terraform state management for tracking cluster changes

Add your answer

Q27. Deploying the resources through terraform

Ans.

Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently.

  • Terraform uses configuration files to define the infrastructure resources needed.

  • It allows for the creation, modification, and deletion of resources in a repeatable manner.

  • Terraform supports various cloud providers such as AWS, Azure, and Google Cloud.

  • State files are used to track the current state of the infrastructure and manage changes.

  • Terraform plans the execution of changes b...read more

Add your answer
Frequently asked in

Q28. Write the terraform script

Ans.

Writing a terraform script for infrastructure provisioning

  • Define provider and required variables

  • Create resources like instances, networks, and storage

  • Use modules for reusable code

  • Implement variables and outputs for flexibility

  • Leverage terraform state for tracking changes

Add your answer
Frequently asked in

Q29. How would you provide security to your credentials while using Terraform

Ans.

Use encrypted variables, limit access to credentials, and utilize secure storage solutions.

  • Encrypt sensitive variables using tools like Vault or AWS KMS

  • Limit access to credentials by using least privilege principles

  • Store credentials securely in a password manager or key vault

  • Avoid hardcoding credentials in Terraform configuration files

Add your answer
Frequently asked in

Q30. Different between Terraform and ansible

Ans.

Terraform is used for infrastructure provisioning and management, while Ansible is used for configuration management and automation.

  • Terraform is used for defining and managing infrastructure as code, focusing on provisioning resources like virtual machines, networks, and storage.

  • Ansible is used for configuration management and automation of software deployment, focusing on tasks like installing packages, configuring services, and managing files.

  • Terraform uses declarative lang...read more

Add your answer

Q31. Explain Terraform modules and give an example

Ans.

Terraform modules are reusable components that allow you to encapsulate and organize your infrastructure code.

  • Modules help in creating reusable infrastructure components

  • They allow for better organization and encapsulation of code

  • Modules can be shared and reused across different projects

  • Example: A Terraform module for creating a VPC with subnets, security groups, and route tables

Add your answer
Frequently asked in

Q32. What is dynamic block?

Ans.

Dynamic blocks in CAD software are customizable and can change shape, size, or appearance based on user input.

  • Dynamic blocks allow users to create a single block that can be modified in various ways without creating multiple block definitions.

  • Parameters can be added to dynamic blocks to control visibility, position, scale, rotation, and other properties.

  • Dynamic blocks are commonly used in architectural and engineering drawings to streamline the design process.

  • Examples of dyna...read more

Add your answer
Frequently asked in

Q33. How will you mentain a terraform state file, if someone manually changes the resource configuration.

Ans.

Maintaining Terraform state file after manual resource configuration changes.

  • Regularly back up the state file to prevent loss of changes.

  • Use version control to track changes made to the state file.

  • Implement automated checks to detect any discrepancies between the state file and actual resources.

  • Educate team members on the importance of not manually changing resource configurations.

  • Consider implementing a policy or process for reviewing and approving any manual changes to reso...read more

Add your answer

Q34. What is Terraform and why we used it

Ans.

Terraform is an infrastructure as code tool used for building, changing, and versioning infrastructure safely and efficiently.

  • Terraform allows for defining infrastructure in code using a declarative configuration language.

  • It supports multiple cloud providers such as AWS, Azure, and Google Cloud Platform.

  • Terraform helps in automating the provisioning of infrastructure, making it easier to manage and scale.

  • It provides a way to create reproducible infrastructure, enabling consis...read more

Add your answer

Q35. what if terraform?

Ans.

Terraform is an infrastructure as code tool used to provision and manage cloud resources.

  • Terraform allows you to define your infrastructure in code using a declarative configuration language.

  • It supports multiple cloud providers such as AWS, Azure, and Google Cloud.

  • Terraform helps in automating the deployment and management of infrastructure.

  • It provides a way to version control your infrastructure code for better collaboration and reproducibility.

Add your answer
Frequently asked in

Q36. what is ansible and what is the difference between ansible and terraform?

Ans.

Ansible is a configuration management and automation tool, while Terraform is an infrastructure provisioning tool.

  • Ansible is used for configuration management, application deployment, and task automation.

  • Terraform is used for infrastructure provisioning and managing cloud resources.

  • Ansible uses YAML-based playbooks to define tasks and configurations, while Terraform uses HCL (HashiCorp Configuration Language) to define infrastructure as code.

  • Ansible is agentless, meaning it d...read more

Add your answer

Q37. How to manage terraform state file in common place so if one making changes other get modified file.

Ans.

Use remote backend in Terraform to manage state file in a common place.

  • Use remote backend in Terraform to store state file in a shared location like AWS S3 bucket or Azure Blob Storage.

  • Configure Terraform to use the remote backend by specifying the backend configuration in the Terraform configuration file.

  • Ensure proper access control and permissions are set up for the shared storage to prevent unauthorized access.

  • Use locking mechanisms provided by the remote backend to preven...read more

Add your answer

Q38. What is Terraform 10k

Ans.

Terraform 10k is a fictional term and does not have a specific meaning in the context of DevOps or infrastructure automation.

  • Terraform 10k is not a real term used in the DevOps industry

  • It may have been mistakenly referenced in the interview question

  • Terraform is a popular infrastructure as code tool, but there is no version called 10k

Add your answer

Q39. Write terraform code for vpc and subnet

Ans.

Terraform code for creating VPC and subnet

  • Define VPC resource with CIDR block

  • Create subnet within VPC with CIDR block

  • Associate subnet with VPC

Add your answer
Frequently asked in

Q40. Ansible terraform usage

Ans.

Ansible and Terraform are tools used for automation and infrastructure management.

  • Ansible is used for configuration management and automation of IT infrastructure.

  • Terraform is used for infrastructure as code and provisioning of resources.

  • Both tools can be used together to manage infrastructure and automate deployment.

  • Ansible can be used to configure servers and deploy applications, while Terraform can be used to provision the necessary infrastructure.

  • For example, Ansible can ...read more

Add your answer
Frequently asked in

Q41. Explain about terraform infra creation

Ans.

Terraform is a tool used for infrastructure as code to create, manage, and update infrastructure resources.

  • Terraform uses declarative configuration files to define infrastructure resources.

  • It supports various cloud providers such as AWS, Azure, and Google Cloud Platform.

  • Terraform creates a 'terraform plan' to show the changes it will make before applying them.

  • Infrastructure resources are created by running 'terraform apply'.

Add your answer

Q42. what is tf state file

Ans.

Tf state file is a JSON file that stores the current state of your infrastructure managed by Terraform.

  • Contains information about resources, their attributes, and dependencies

  • Used by Terraform to keep track of the infrastructure state

  • Should be stored securely and not shared publicly

Add your answer

Q43. What are modules in Terraform, share your screen and write module

Ans.

Modules in Terraform are reusable components that allow you to encapsulate and organize your infrastructure code.

  • Modules help in breaking down complex infrastructure into smaller, manageable components

  • They promote reusability and maintainability of code

  • Modules can be shared and used across different projects

  • Example: Creating a module for provisioning a virtual machine in Azure

Add your answer
Frequently asked in

Q44. How to import resources that are not managed by terraform? How to run terraform apply on specific resource?

Ans.

To import resources not managed by Terraform, use the 'terraform import' command. To run 'terraform apply' on a specific resource, use the '-target' flag.

  • To import resources, use the 'terraform import' command followed by the resource type and ID.

  • For example: 'terraform import aws_instance.example i-12345678'

  • To run 'terraform apply' on a specific resource, use the '-target' flag followed by the resource address.

  • For example: 'terraform apply -target=aws_instance.example'

Add your answer
Frequently asked in

Q45. How you use Terraform?

Ans.

Terraform is used to automate infrastructure provisioning and management.

  • Terraform is a tool for defining and provisioning infrastructure as code.

  • It allows you to create, modify, and destroy infrastructure resources using declarative configuration files.

  • Terraform supports various cloud providers like AWS, Azure, and GCP.

  • You can define infrastructure resources such as virtual machines, networks, and storage using Terraform's domain-specific language (DSL).

  • Terraform provides a ...read more

Add your answer
Frequently asked in

Q46. If i delete an instance on the console and then i deploy the same instance terraform template how will terraform behave?

Ans.

Terraform will recreate the instance as per the template

  • Terraform will detect that the instance is missing and recreate it based on the template

  • The new instance will have the same configuration as defined in the template

  • Any changes made to the instance outside of Terraform will be lost

Add your answer
Frequently asked in

Q47. Life cycle of terraform

Ans.

Terraform life cycle involves initialization, planning, applying, and destroying infrastructure.

  • Terraform initializes by downloading providers and modules

  • Planning phase creates an execution plan for infrastructure changes

  • Apply phase executes the plan and makes changes to infrastructure

  • Destroy phase removes all resources created by Terraform

  • Terraform can also import existing infrastructure into its state

View 1 answer
Frequently asked in

Q48. states in terraform

Ans.

Using states in Terraform to manage infrastructure

  • Terraform state is used to store information about the infrastructure being managed

  • State files can be stored locally or remotely

  • State files should be stored securely to prevent unauthorized access

Add your answer

Q49. Phases while using terraform

Ans.

Phases in using Terraform include initialization, planning, applying, and destroying.

  • Initialization: Setting up Terraform environment with 'terraform init'

  • Planning: Preview changes with 'terraform plan'

  • Applying: Execute changes with 'terraform apply'

  • Destroying: Remove resources with 'terraform destroy'

Add your answer
Frequently asked in

Q50. Terraform destroy plan how to know?

Ans.

Terraform destroy plan can be known by running 'terraform plan -destroy'

  • Run 'terraform plan -destroy' to see the destroy plan before executing it

  • Review the output to ensure only the intended resources will be destroyed

  • Use '--out' flag to save the plan to a file for later execution

Add your answer

Q51. terraform differenece between count and for

Ans.

In Terraform, 'count' is used to create multiple instances of a resource based on a single configuration, while 'for_each' is used to create multiple instances of a resource based on a map or set of strings.

  • Count is used with a static number to create multiple instances of a resource.

  • For_each is used with a map or set of strings to create multiple instances of a resource.

  • Count is more suitable for creating a fixed number of instances, while for_each is more flexible for dynam...read more

Add your answer
Frequently asked in

Q52. Security in Terraform

Ans.

Security in Terraform involves managing sensitive data, implementing access controls, and using secure communication channels.

  • Use Terraform's sensitive data handling features like sensitive variables and sensitive outputs to protect sensitive information.

  • Implement access controls using Terraform's built-in features like IAM policies, resource-level permissions, and secure storage backends.

  • Use secure communication channels like HTTPS for Terraform API calls and encrypt sensiti...read more

Add your answer
Frequently asked in

Q53. Add mount points automatically when system restarted Terraform state file storing so that it can accessible by other developers

Ans.

Automate the process of adding mount points on system restart and store Terraform state file for accessibility by other developers.

  • Use a configuration management tool like Ansible to automatically add mount points on system restart.

  • Utilize cloud storage services like AWS S3 or Azure Blob Storage to store Terraform state file for easy access by other developers.

  • Implement scripts or automation workflows to handle the mounting of storage volumes and managing Terraform state file...read more

Add your answer
Frequently asked in

Q54. Terraform code for ec2

Ans.

Terraform code for creating an EC2 instance

  • Use the 'aws_instance' resource in Terraform

  • Specify the AMI, instance type, key pair, and security group in the resource block

  • Define any additional configurations like tags or user data

  • Run 'terraform init', 'terraform plan', and 'terraform apply' to create the EC2 instance

Add your answer

Q55. Terraform Best practice

Ans.

Terraform best practices ensure efficient infrastructure provisioning and management.

  • Use version control to track changes in infrastructure code.

  • Separate infrastructure into reusable modules for scalability.

  • Leverage variables and data sources for flexibility and reusability.

  • Implement state management to track infrastructure state.

  • Apply security best practices, such as using secure credentials and managing access control.

  • Use Terraform workspaces to manage multiple environments...read more

View 1 answer

Q56. modules in terrafrom

Ans.

Modules in Terraform are reusable configurations that can be used to create resources in a consistent and efficient manner.

  • Modules help in organizing and reusing Terraform configurations

  • They can be used to create resources, manage infrastructure, and define policies

  • Modules can be shared and reused across different projects

  • Example: Creating a module for provisioning an AWS EC2 instance

Add your answer
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Interview experiences of popular companies

3.7
 • 10.3k Interviews
3.9
 • 8k Interviews
3.7
 • 7.5k Interviews
3.7
 • 5.5k Interviews
3.8
 • 4.8k Interviews
3.5
 • 3.7k Interviews
3.8
 • 2.9k Interviews
4.4
 • 155 Interviews
3.7
 • 62 Interviews
View all
Terraform Interview Questions
Share an Interview
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
70 Lakh+

Reviews

5 Lakh+

Interviews

4 Crore+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter