0% found this document useful (0 votes)
14 views

Terraform

Uploaded by

hemanth-moka
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Terraform

Uploaded by

hemanth-moka
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1. What is Terraform?

 Terraform is an open-source infrastructure as code software tool created by


HashiCorp. It allows users to define and provision infrastructure using a
declarative configuration language.
2. What are the key features of Terraform?
 Infrastructure as code, Execution plans, Resource graph, Change automation,
and Provisioning.
3. Explain the difference between Terraform state and Terraform plan.
 Terraform state is a snapshot of the infrastructure's current state, while
Terraform plan is a preview of the changes Terraform will make to achieve the
desired state.
4. What is a Terraform module?
 A Terraform module is a container for multiple resources that are used
together. It allows for reusable and shareable configurations.
5. How does Terraform manage dependencies between resources?
 Terraform manages dependencies automatically by creating a resource graph
based on the configuration. It determines the order in which resources should
be created, updated, or destroyed.
6. What is the difference between provider and resource in Terraform?
 A provider is responsible for interacting with APIs to manage resources, while
a resource represents a single piece of infrastructure, such as an AWS instance
or a Google Cloud Storage bucket.
7. How does Terraform handle secrets and sensitive data?
 Terraform provides several methods for managing secrets, including
environment variables, encrypted state files, and integration with third-party
secret management tools like HashiCorp Vault.
8. Explain the concept of Terraform workspaces.
 Terraform workspaces allow you to manage multiple environments (such as
development, staging, and production) with separate state files and
configurations.
9. What is the purpose of Terraform's "plan" command?
 The "terraform plan" command generates an execution plan showing what
actions Terraform will take to change the infrastructure. It provides a preview
of changes before they are applied.
10. How does Terraform handle drift in infrastructure?
 Terraform compares the current state of the infrastructure with the desired
state defined in the configuration. If there are differences (drift), Terraform can
update the infrastructure to match the desired state using the "terraform
apply" command.
11. What are the benefits of using Terraform?
 Terraform provides repeatability, consistency, and scalability in
infrastructure management. It allows for version-controlled
infrastructure, easier collaboration, and reduced manual errors.
12. Explain the difference between Terraform's "remote" and "local"
backend types.
 The "local" backend stores the Terraform state file on the local
filesystem, while the "remote" backend stores it remotely, such as in an
S3 bucket or Azure Blob Storage.
13. How does Terraform handle resource dependencies across different
providers?
 Terraform manages cross-provider dependencies automatically by
understanding the relationships between resources defined in the
configuration.
14. What is the purpose of Terraform's "output" block?
 The "output" block in Terraform allows you to extract information from
the Terraform state, such as IP addresses or DNS names, and display it
after applying changes.
15. How does Terraform handle updates to existing resources?
 Terraform compares the desired state defined in the configuration with
the current state of the infrastructure and applies only the necessary
changes to bring the infrastructure into the desired state.
16. Explain the concept of Terraform's "provisioners".
 Provisioners in Terraform are used to execute scripts or commands on
local or remote machines after resource creation. They are often used
for tasks such as installing software or configuring resources.
17. What is the purpose of Terraform's "terraform init" command?
 The "terraform init" command initializes a Terraform configuration,
downloading necessary plugins and modules and preparing the
working directory for Terraform operations.
18. How can you manage Terraform configurations across different
environments?
 Terraform configurations can be managed using workspaces, variables,
and conditional logic to adapt configurations to different environments
while maintaining consistency and reusability.
19. Explain the difference between "terraform apply" and "terraform
destroy" commands.
 "terraform apply" applies changes to infrastructure as defined in the
configuration, while "terraform destroy" removes all resources defined
in the configuration from the infrastructure.
20. How can you manage state locking in Terraform to prevent concurrent
operations?
 Terraform provides state locking mechanisms, such as using a backend
that supports locking (like S3 with DynamoDB), to prevent concurrent
operations from multiple users or systems.

21. What are Terraform providers?


 Terraform providers are responsible for translating the desired state
described in Terraform configuration files into API calls to interact with
specific infrastructure platforms, such as AWS, Azure, or Google Cloud
Platform.
22. How does Terraform handle changes to infrastructure configurations
over time?
 Terraform tracks changes to infrastructure configurations over time by
maintaining a state file. When changes are made to the configuration,
Terraform generates a new execution plan and applies only the
necessary changes to the infrastructure.
23. Explain the difference between Terraform's "variables" and "outputs".
 Variables are placeholders used to parameterize Terraform
configurations, allowing for flexibility and reusability. Outputs, on the
other hand, extract information from the Terraform state after applying
changes and make it available for further use or display.
24. What are Terraform modules, and why are they useful?
 Terraform modules are reusable components that encapsulate a set of
resources and configurations. They promote code reuse,
maintainability, and consistency across projects by abstracting complex
infrastructure configurations into reusable building blocks.
25. How can you manage secrets securely in Terraform configurations?
 Secrets can be managed securely in Terrafo rm configurations using
techniques such as environment variables, encrypted variables, external
secret management tools like HashiCorp Vault, or integration with
cloud-native secret management services provided by infrastructure
platforms.
26. What is the purpose of Terraform's "data sources"?
 Terraform's data sources allow you to fetch information from external
sources, such as cloud providers' APIs or external databases, and use
that information within Terraform configurations. This enables dynamic
configuration based on real-time data.
27. Explain the concept of Terraform "lifecycle" configuration.
 Terraform lifecycle configuration allows you to control when certain
actions, such as resource creation, updating, or deletion, occur during
the Terraform execution lifecycle. It provides fine-grained control over
resource management behaviors.
28. How does Terraform handle state management in a team environment?
 Terraform supports collaborative state management by allowing
multiple team members to work on the same infrastructure
configuration concurrently through remote state storage and locking
mechanisms provided by backends like S3, Azure Blob Storage, or
Consul.
29. What are Terraform "locals", and when are they used?
 Terraform locals are variables that are computed from expressions
within the configuration. They are useful for simplifying complex
expressions, avoiding repetition, and improving readability of Terraform
code.
30. What strategies can be employed to manage Terraform configuration
drift?
 Strategies to manage Terraform configuration drift include regularly
auditing and comparing the current infrastructure state with the
desired state defined in Terraform configurations, implementing
automated tests, and utilizing version control to track changes.
31. How does Terraform handle resource dependencies within modules?
 Terraform automatically manages dependencies within modules by
analyzing the relationships between resources defined in the module
and ensuring they are created, updated, or destroyed in the correct
order based on these dependencies.
32. Explain Terraform's "count" and "for_each" meta-arguments.
 The "count" meta-argument allows you to create multiple instances of
a resource based on an integer value, while "for_each" allows you to
create multiple instances of a resource based on a map or set of
strings.4
33. What is Terraform's "remote state" feature, and why is it important?
 Terraform's remote state feature allows you to store the state file
remotely, enabling collaboration, concurrency, and state locking among
team members working on the same infrastructure configuration.
34. How does Terraform handle idempotency in resource management?
 Terraform ensures idempotency by comparing the desired state
defined in the configuration with the current state of the infrastructure.
It applies only the necessary changes to bring the infrastructure into
the desired state, regardless of the initial or intermediate states.
35. Explain the purpose of Terraform's "backend" configuration.
 Terraform's backend configuration specifies where Terraform state files
are stored and how state locking is managed. It allows you to choose
different backends based on your requirements, such as local file
storage or remote storage with state locking.
36. What is the difference between Terraform's "apply" and "validate"
commands?
 The "terraform apply" command applies changes to infrastructure
according to the configuration, while the "terraform validate" command
checks the validity of the Terraform configuration syntax and
configuration files without making any changes.
37. How can you manage Terraform state across multiple environments?
 Terraform allows you to use separate state files for different
environments, such as development, staging, and production, using
Terraform workspaces or by configuring different backend
configurations for each environment.
38. Explain the concept of Terraform's "null_resource" and when it is used.
 The "null_resource" in Terraform represents a resource that performs
arbitrary actions without being directly associated with a specific
infrastructure component. It is typically used for executing local
provisioners or running commands.
39. What are Terraform's "providers" and "provisioners"?
 Terraform providers are responsible for managing resources on specific
infrastructure platforms, while provisioners are used to execute scripts
or commands on local or remote machines during resource creation or
update.
40. How does Terraform handle updates to existing infrastructure without
causing downtime?
 Terraform supports rolling updates and blue-green deployments by
applying changes to infrastructure in a controlled manner, such as
updating one instance at a time or redirecting traffic gradually to new
resources, to minimize or eliminate downtime.

The purpose of null_resource in Terraform is to act as a placeholder for arbitrary actions that
don't directly create, update, or destroy resources. It's commonly used for running
provisioners, executing external scripts, handling dependencies, or performing cleanup tasks
within Terraform configurations.

terraform {
backend "s3" {
bucket = "my-terraform-state"
key = "terraform.tfstate"
region = "us-west-2"
encrypt = true
dynamodb_table = "terraform-lock"
}
}

You might also like