Terraform
Top 50 Terraform Interview Questions and Answers 2025
56 questions found
Updated 29 Nov 2024
Q1. Write a terraform code for a resource?
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
Q2. What are modules in terraform?
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.
Q3. What is ansible and terraform?
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
Q4. Explain the modules in Terraform
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
Q5. What’s terraform and chef
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
Q6. write code of provider.tf
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" }
Q7. Write terraform module for any AWS resources.
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
Q8. What errors you have faced while applying terraform code?
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
Terraform Jobs
Q9. What is Docker, Terraform?
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
Q10. Are you aware of script / terraform
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.
Q11. How would you handle terraform state in file system?
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.
Q12. What are namespaces in terraform
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_'
Q13. How did you use terraform to build the infrastructure?
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
Q14. What will lookup function do in terraform
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")
Q15. What is tf State file in terraform
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.
Q16. what is tf state files
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
Q17. What is NullResource in terraform.
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
Q18. How terraform Metaarguments works in multiple scenario scenarios
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
Q19. How to write composite terraform module and pass their values to other modules.
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
Q20. Deep dive in Terraform and Python
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
Q21. Devops implementation process for terraform deployments
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
Q22. Terraform and its workspace
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
Q23. Terraform state files and where are they stored?
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
Q24. Terraform templates to create aks
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
Q25. Container creation in terraform
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.
Q26. Terraform experience with EKS clusters creation
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
Q27. Deploying the resources through terraform
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
Q28. Write the terraform script
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
Q29. How would you provide security to your credentials while using Terraform
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
Q30. Different between Terraform and ansible
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
Q31. Explain Terraform modules and give an example
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
Q32. What is dynamic block?
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
Q33. How will you mentain a terraform state file, if someone manually changes the resource configuration.
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
Q34. What is Terraform and why we used it
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
Q35. what if terraform?
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.
Q36. what is ansible and what is the difference between ansible and terraform?
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
Q37. How to manage terraform state file in common place so if one making changes other get modified file.
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
Q38. What is Terraform 10k
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
Q39. Write terraform code for vpc and subnet
Terraform code for creating VPC and subnet
Define VPC resource with CIDR block
Create subnet within VPC with CIDR block
Associate subnet with VPC
Q40. Ansible terraform usage
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
Q41. Explain about terraform infra creation
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'.
Q42. what is tf state file
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
Q43. What are modules in Terraform, share your screen and write module
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
Q44. How to import resources that are not managed by terraform? How to run terraform apply on specific resource?
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'
Q45. How you use Terraform?
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
Q46. If i delete an instance on the console and then i deploy the same instance terraform template how will terraform behave?
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
Q47. Life cycle of terraform
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
Q48. states in terraform
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
Q49. Phases while using terraform
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'
Q50. Terraform destroy plan how to know?
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
Q51. terraform differenece between count and for
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
Q52. Security in Terraform
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
Q53. Add mount points automatically when system restarted Terraform state file storing so that it can accessible by other developers
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
Q54. Terraform code for ec2
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
Q55. Terraform Best practice
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
Q56. modules in terrafrom
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
Top Interview Questions for Related Skills
Interview Questions of Terraform Related Designations
Interview experiences of popular companies
Reviews
Interviews
Salaries
Users/Month