- What is Terraform?
- Answer: Terraform is an Infrastructure as Code (IaC) tool used for building, changing, and versioning infrastructure efficiently and safely.
- Answer: Terraform is an Infrastructure as Code (IaC) tool used for building, changing, and versioning infrastructure efficiently and safely.
- What are the key features of Terraform?
- Answer: Key features include Infrastructure as Code (IaC), execution plans, resource graphing, change automation, and immutable infrastructure.
- Answer: Key features include Infrastructure as Code (IaC), execution plans, resource graphing, change automation, and immutable infrastructure.
- How do you define infrastructure in Terraform?
- Answer: Infrastructure is defined using configuration files written in HashiCorp Configuration Language (HCL) or JSON format.
- Answer: Infrastructure is defined using configuration files written in HashiCorp Configuration Language (HCL) or JSON format.
- What is the purpose of Terraform’s state file?
- Answer: The state file maintains a mapping between resources in your configuration and real-world infrastructure. It’s used to track resource dependencies and manage updates.
- Answer: The state file maintains a mapping between resources in your configuration and real-world infrastructure. It’s used to track resource dependencies and manage updates.
- How do you initialize a Terraform configuration?
- Answer: Use the
terraform init
command to initialize a Terraform configuration. This command downloads the necessary plugins and modules.
- Answer: Use the
- Can you provide an example of a basic Terraform configuration file?
- Answer:
provider "aws" {
region = "us-west-2"
}
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
}
- What is the purpose of providers in Terraform?
- Answer: Providers are responsible for interacting with APIs and exposing resources. They are essential for defining the target infrastructure platform.
- Answer: Providers are responsible for interacting with APIs and exposing resources. They are essential for defining the target infrastructure platform.
- How do you apply changes to infrastructure with Terraform?
- Answer: Use the
terraform apply
command. It evaluates the configuration, generates an execution plan, and applies changes to the infrastructure.
- Answer: Use the
- What is a Terraform module?
- Answer: A module is a reusable collection of Terraform configuration files. It encapsulates a set of resources and can be shared across different configurations.
- Answer: A module is a reusable collection of Terraform configuration files. It encapsulates a set of resources and can be shared across different configurations.
- How do you destroy infrastructure provisioned by Terraform?
- Answer: Use the
terraform destroy
command. It removes all resources defined in the configuration from the target infrastructure.
- Answer: Use the
- How can you manage sensitive data such as passwords or API tokens in Terraform?
- Answer: Terraform supports input variables and environment variables, allowing you to pass sensitive data securely without storing it in configuration files.
- Answer: Terraform supports input variables and environment variables, allowing you to pass sensitive data securely without storing it in configuration files.
- What is the purpose of the
terraform plan
command?- Answer: The
terraform plan
the command generates an execution plan based on the current configuration and displays the actions Terraform will take when applying changes.
- Answer: The
- How do you manage multiple environments (e.g., dev, staging, production) with Terraform?
- Answer: Use Terraform workspaces or separate configuration files for each environment, each with environment-specific variables and settings.
- Answer: Use Terraform workspaces or separate configuration files for each environment, each with environment-specific variables and settings.
- Explain the difference between Terraform’s state file and configuration files.
- Answer: Configuration files (
.tf
files) define the desired state of infrastructure, while the state file (usuallyterraform.tfstate
) maintains the current state of deployed infrastructure.
- Answer: Configuration files (
- Can you specify multiple providers in a single Terraform configuration? If yes, how?
- Answer: Yes, you can specify multiple providers by defining each with a unique provider block. For example:
- /code
provider "aws" {
region = "us-west-2"
}
provider "google" {
project = "my-project"
region = "us-central1"
}
- How does Terraform handle dependencies between resources?
- Answer: Terraform automatically manages resource dependencies based on resource definitions in the configuration. It creates resources in the correct order to satisfy dependencies.
- Answer: Terraform automatically manages resource dependencies based on resource definitions in the configuration. It creates resources in the correct order to satisfy dependencies.
- What is the purpose of the
.terraform
directory?- Answer: The
.terraform
directory contains plugin binaries, module dependencies, and other internal Terraform files used to manage and execute configurations.
- Answer: The
- Explain the difference between Terraform’s
plan
andapply
commands.- Answer: The
terraform plan
command generates an execution plan without applying changes, whileterraform apply
executes the plan and applies changes to the infrastructure.
- Answer: The
- How do you manage third-party Terraform modules?
- Answer: Third-party modules can be sourced from version control repositories (e.g., GitHub) or the Terraform Registry using module blocks in configuration files.
- Answer: Third-party modules can be sourced from version control repositories (e.g., GitHub) or the Terraform Registry using module blocks in configuration files.
- Can you use Terraform to manage resources across different cloud providers (e.g., AWS, Azure, GCP)?
- Answer: Yes, Terraform is cloud-agnostic and supports managing resources across various cloud providers by configuring appropriate provider blocks for each provider.
- Answer: Yes, Terraform is cloud-agnostic and supports managing resources across various cloud providers by configuring appropriate provider blocks for each provider.