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

terraform topic

Uploaded by

madhavi.ndp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

terraform topic

Uploaded by

madhavi.ndp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

- Explanation: Removes the specified Auto Scaling Group and all its

associated resources.

Terraform Interview Question & Answers

Terraform interview question and answers for BEGINER LEVEL

1. Q: What is Terraform?
A: Terraform is an open-source infrastructure as code (IaC) tool
developed by HashiCorp. It allows you to define and manage your
infrastructure using declarative configuration files.

2. Q: How does Terraform work?


A: Terraform works by reading the configuration files (written in
HashiCorp Configuration Language or HCL) that describe the desired state
of your infrastructure. It then compares the desired state with the current
state and makes the necessary changes to bring the infrastructure to the
desired state.

3. Q: What are the advantages of using Terraform?


A: Some advantages of using Terraform are:
- Infrastructure as code: Allows you to define and manage infrastructure
using code, which brings version control, collaboration, and
reproducibility benefits.
- Platform-agnostic: Works with multiple cloud providers and
infrastructure technologies.
- Automation and orchestration: Automates the provisioning and
management of infrastructure resources.
- State management: Keeps track of the current state of the infrastructure
and enables incremental updates.
- Reusability: Supports code reuse through modules, making it easier to
manage and scale infrastructure.
4. Q: How do you initialize a Terraform project?
A: To initialize a Terraform project, you can use the `terraform init`
command. This command initializes the working directory, downloads the
necessary provider plugins, and sets up the backend configuration.

5. Q: What is a Terraform module?


A: A Terraform module is a self-contained and reusable package of
Terraform configuration files that define a set of resources with specific
input and output variables. Modules allow you to encapsulate and abstract
infrastructure components, promoting reusability and modular design.

6. Q: How do you apply changes to your infrastructure with


Terraform?
A: You can apply changes to your infrastructure using the `terraform
apply` command. This command reads the configuration files, creates an
execution plan, and then prompts for approval before making any changes.
Once approved, Terraform applies the changes to your infrastructure.

7. Q: How does Terraform handle state management?


A: Terraform uses a state file to keep track of the current state of your
infrastructure. The state file contains information about the resources
managed by Terraform, their properties, and any dependencies between
them. Terraform uses this state file to determine the changes needed to
achieve the desired state and to track the infrastructure over time.

8. Q: What is the difference between `terraform plan` and `terraform


apply`?
A: `terraform plan` generates an execution plan by comparing the
desired state in the configuration files with the current state. It shows what
changes will be made without actually applying them. `terraform apply`
executes the plan and applies the changes to the infrastructure, after
receiving approval from the user.

9. Q: How can you destroy infrastructure created with Terraform?


A: You can destroy the infrastructure created with Terraform using the
`terraform destroy` command. This command reads the Terraform
configuration, creates a destruction plan, and prompts for approval before
executing the plan. Once approved, Terraform destroys the infrastructure
and removes all associated resources.
10. Q: Can Terraform manage resources in multiple cloud providers?
A: Yes, Terraform is cloud-agnostic and can manage resources in
multiple cloud providers. It supports various cloud platforms, including
Amazon Web Services (AWS), Microsoft Azure, Google Cloud Platform
(GCP), and many others.

Terraform interview question and answers for INTERMEDIATE


LEVEL
1. Q: What are Terraform workspaces and when would you use them?
A: Terraform workspaces allow you to manage multiple instances of a
single infrastructure in separate environments. Workspaces are useful
when you need to maintain different sets of resources, such as
development, staging, and production environments, while sharing the
same Terraform configuration.

2. Q: What is the purpose of Terraform variables?


A: Terraform variables allow you to parameterize your configurations
and make them more dynamic and reusable. They enable you to pass
inputs into modules, define values for different environments, and promote
flexibility in your infrastructure code.

3. Q: How can you manage secrets and sensitive data in Terraform?


A: Terraform provides several methods to manage secrets and sensitive
data:
- Input variables: You can prompt users to input sensitive information
interactively during the Terraform run.
- Environment variables: You can use environment variables to pass
sensitive data to Terraform.
- External data sources: You can fetch secrets from external sources like
key management services or secret stores using data sources.
- Vault integration: Terraform integrates with HashiCorp Vault, a secrets
management tool, to securely retrieve and manage secrets.

4. Q: What is the purpose of Terraform state locking, and how can


you enable it?
A: Terraform state locking is a mechanism used to prevent concurrent
access and modification of the Terraform state file. It ensures that only one
user or process can make changes to the infrastructure at a time. You can
enable state locking by configuring a backend with locking support, such
as using a remote backend with a distributed locking mechanism.
5. Q: What is the difference between a Terraform provisioner and a
resource?
A: A Terraform resource represents a provisionable infrastructure object,
such as an AWS EC2 instance or an Azure virtual machine. Resources
define the desired state of the infrastructure. On the other hand,
provisioners are used to execute scripts or commands on the resource after
it is created or updated. Provisioners are typically used for tasks like
software provisioning, configuration management, or application
deployment.

6. Q: How can you manage Terraform state when working with a


team?
A: When working with a team, it's important to have a centralized and
shared state management approach. Some common practices include:
- Using a remote backend: Store the state file in a remote backend (such
as an object storage bucket or a version control system) that can be
accessed by all team members.
- Implementing a state locking mechanism: Enable state locking to
prevent concurrent modifications to the state file by different team
members.
- Setting up a CI/CD pipeline: Integrate Terraform with a CI/CD pipeline
to automate the execution of Terraform commands and ensure consistent
state management.

7. Q: What are Terraform data sources, and how are they used?
A: Terraform data sources allow you to fetch information or query
existing resources outside of Terraform configuration. Data sources
provide a way to import data into Terraform, which can be used to make
decisions, populate variables, or retrieve information needed for resource
configuration.

8. Q: Can you rollback changes made by Terraform?


A: Terraform does not natively support rolling back changes. However,
you can restore a previous state of the infrastructure by reverting to a
previous state file, such as one stored in version control. It's important to
maintain backups or versions of the state file to facilitate rollback if
needed.
9. Q: What is Terraform's "plan refresh" process?
A: The "plan refresh" process in Terraform involves reading the current
state of the infrastructure and comparing
it with the configured resources. It determines the changes that need to be
made to align the current state with the desired state. The plan refresh
process is triggered automatically when running `terraform plan` or
`terraform apply`.

10. Q: Can Terraform manage resources that were not created by


Terraform itself?
A: Yes, Terraform can manage existing resources that were not
originally created by Terraform. This can be achieved using Terraform's
"import" feature, where you can import existing resources into the
Terraform state and start managing them using Terraform.

Terraform interview question and answers for ADVANCED LEVEL

1. Q: What are Terraform backends, and why are they important?


A: Terraform backends are components responsible for storing and
retrieving the Terraform state. They define where the state file is stored
and how it is accessed. Backends are crucial for collaboration, concurrent
access, and state management in a team setting. They enable remote
storage, locking, and versioning of the state.

2. Q: What is the purpose of Terraform providers, and how can you


create a custom provider?
A: Terraform providers are plugins that interact with infrastructure APIs
and enable Terraform to manage resources. They define the available
resources, their properties, and the actions Terraform can perform on them.
To create a custom provider, you need to develop a plugin that adheres to
the Terraform Provider Protocol and implement the necessary CRUD
operations for resource management.

3. Q: Explain the concept of Terraform remote execution. How does it


work, and when is it useful?
A: Terraform remote execution allows you to run Terraform commands
remotely, such as on a server or in a CI/CD pipeline. It involves separating
the Terraform CLI from the backend storage, enabling the execution of
Terraform operations in a different environment. Remote execution is
useful when you want to decouple the execution environment from the
backend storage, enhance security, and enable centralized control and
automation.

4. Q: What are Terraform modules, and how can you structure


modules effectively?
A: Terraform modules are self-contained, reusable components that
encapsulate a set of resources and provide input and output variables. To
structure modules effectively, you can follow best practices such as:
- Keeping modules focused and single-purpose.
- Providing clear documentation and examples for module usage.
- Designing modules with flexibility and reusability in mind.
- Defining input variables to customize module behavior.
- Providing informative outputs to enable easy consumption of module
results.

5. Q: What is the "Terraform state" and how can you manage it in a


team environment?
A: The Terraform state represents the current state of the managed
infrastructure. It includes information about resources, their properties, and
dependencies. To manage the state in a team environment:
- Use a shared remote backend to store the state file, enabling
collaboration.
- Implement a state locking mechanism to prevent concurrent
modifications.
- Define clear ownership and access controls for the state file.
- Consider implementing a state versioning strategy for better
traceability and rollback options.

6. Q: How can you implement infrastructure testing and validation


with Terraform?
A: Infrastructure testing and validation can be achieved using tools and
practices such as:
- Using Terraform's built-in `terraform validate` command to check for
configuration errors and syntax.
- Employing automated testing frameworks like Terratest or Kitchen-
Terraform to write and execute infrastructure tests.
- Incorporating linting tools like TFLint to enforce best practices and
coding standards.
- Leveraging integration and end-to-end testing to validate the behavior
of the infrastructure.
7. Q: Explain the concept of "Terraform as a service" and its benefits.
A: "Terraform as a service" refers to the practice of providing Terraform
functionality as a managed service. Benefits of Terraform as a service
include:
- Simplified infrastructure provisioning and management.
- Centralized control and visibility across multiple environments.
- Reduced operational overhead, as the service provider manages the
infrastructure hosting Terraform.
- Seamless integration with other DevOps tools and workflows.

8. Q: What are Terraform workspaces, and how can they be leveraged


effectively?

A: Terraform workspaces enable the management of multiple instances of


the same infrastructure in separate environments. To leverage workspaces
effectively:
- Use workspaces to separate development, staging, and production
environments.
- Define workspace-specific variables to customize behavior for each
environment.
- Utilize workspace-specific state files to isolate state between
environments.
- Automate workspace creation and switching using scripts or CI/CD
pipelines.

9. Q: Explain the concept of "Immutable Infrastructure" and how


Terraform supports it.
A: Immutable Infrastructure refers to the practice of treating
infrastructure as disposable and never modifying it once provisioned.
Terraform supports Immutable Infrastructure by promoting the recreation
of resources instead of in-place updates. By using Terraform's `destroy`
and `apply` commands, resources can be destroyed and recreated with
each change, ensuring a consistent and predictable infrastructure state.

10. Q: How can you handle complex dependency management and


resource ordering in Terraform?
A: To handle complex dependency management and resource ordering
in Terraform:
- Leverage implicit and explicit dependencies defined in the Terraform
configuration.
- Utilize Terraform's `depends_on` parameter to enforce ordering
between resources.
- Use the `terraform state` command to modify resource ordering in the
Terraform state file, if necessary.
- Consider breaking down complex configurations into smaller modules
to simplify dependency management.
Remember to dive deeper into advanced Terraform concepts, explore real-
world use cases, and stay up-to-date with the latest features and best
practices. Continuous learning and hands-on experience will help you
excel in Terraform at an advanced level.

Terraform interview question and answers SCENARIO BASED


1. Scenario: You are managing infrastructure for a web application
that consists of an Amazon EC2 instance, an Amazon RDS database,
and an Elastic Load Balancer. How would you configure Terraform to
create this infrastructure?
Answer: To configure Terraform for this scenario, you would define the
necessary resources in the Terraform configuration files. You would use
the appropriate AWS provider to provision the EC2 instance, RDS
database, and ELB resources. You would specify the required settings
such as instance type, database engine, load balancer listeners, and security
groups. Additionally, you could use variables to make the configuration
more flexible and reusable.

2. Scenario: You have been tasked with managing infrastructure


across multiple cloud providers, including AWS, Azure, and GCP.
How would you structure your Terraform project to support this
multi-cloud environment?
Answer: To support a multi-cloud environment in Terraform, you can
structure your project using modules. Create separate directories for each
cloud provider, and within each directory, define the necessary provider
configurations and resource definitions. Use Terraform workspaces to
manage environments (e.g., development, staging, production) for each
cloud provider. Encapsulate cloud-specific configurations and resource
definitions within their respective modules to ensure modularity and
reusability.

3. Scenario: You have a Terraform configuration that provisions an


AWS EC2 instance. You need to pass sensitive information, such as
SSH key pairs or database passwords, to the instance securely. How
would you handle this situation?
Answer: To handle sensitive information securely in Terraform, you can
leverage input variables and environment variables. Define input variables
for sensitive information and use the `sensitive` argument to mark them as
confidential. Prompt the user to enter the sensitive information
interactively during the Terraform run. Alternatively, you can use
environment variables to pass sensitive data to Terraform, ensuring that
they are securely managed and protected.
4. Scenario: You are working in a team where multiple developers are
making changes to the infrastructure concurrently. How would you
ensure that Terraform state is managed properly and avoid conflicts?
Answer: To manage Terraform state in a team environment and prevent
conflicts, you can use a shared remote backend with state locking.
Configure the backend to store the state file in a central location accessible
by all team members. Enable state locking to ensure that only one user can
make changes to the state at a time, preventing conflicts. This way,
everyone in the team can work on the same infrastructure code while
maintaining consistent state management.

5. Scenario: You need to deploy a multi-tier application stack


consisting of a frontend web server, an application server, and a
database server. How would you model this infrastructure using
Terraform?
Answer: To model a multi-tier application stack in Terraform, you can
define separate modules for each tier. Create a module for the frontend
web server, another module for the application server, and a separate
module for the database server. Define the necessary resources,
dependencies, and variables within each module. Use Terraform's output
variables to capture important information from each module, such as
server addresses or connection strings, and pass them between modules to
establish the required connectivity.

6. Scenario: You have been tasked with deploying infrastructure


across multiple environments, including development, staging, and
production. How would you structure your Terraform project to
manage these environments effectively?
Answer: To manage multiple environments effectively in Terraform, you
can adopt a directory structure approach. Create separate directories for
each environment, such as "dev," "staging," and "prod." Within each
directory, define the necessary Terraform configuration files specific to
that environment. Use Terraform workspaces to switch between
environments and maintain separate state files for each. This approach
helps keep the configurations and state files organized and provides clear
separation between environments.

7. Scenario: You need to provision infrastructure in AWS, and it


requires some custom configuration after resource creation, such as
installing software or running scripts. How would you achieve this
with Terraform?
Answer: To achieve custom configuration after resource creation in
Terraform, you can utilize provisioners. Provisioners are blocks of code
that run on the created resources. You can use the `remote-exec`
provisioner to SSH into an EC2 instance and execute commands or scripts.
Alternatively, you can use configuration management tools like Ansible or
Chef as provisioners to perform more complex configurations. By
leveraging provisioners, you can automate post-provisioning tasks in your
infrastructure deployment.

8. Scenario: You are deploying a Kubernetes cluster on AWS using


Terraform. How would you handle the configuration and installation
of Kubernetes components?
Answer: To handle the configuration and installation of Kubernetes
components in Terraform, you can utilize the Kubernetes provider. The
provider allows you to define Kubernetes resources, such as pods,
services, or deployments, directly in your Terraform configuration. You
can use Terraform variables to parameterize the Kubernetes configuration
and enable customization. Additionally, you can use the `kubernetes-
alpha` provider to perform more advanced Kubernetes tasks like managing
custom resources or cluster-level configurations.

9. Scenario: You are managing infrastructure in Azure using


Terraform, and you need to integrate with Azure Key Vault to store
and retrieve secrets securely. How would you achieve this?
Answer: To integrate Terraform with Azure Key Vault for secure secrets
management, you can use the Azure Key Vault provider. Define an Azure
Key Vault resource in your Terraform configuration and use it to store
sensitive information, such as passwords or API keys. Leverage data
sources to retrieve secrets from Azure Key Vault during resource
provisioning. Ensure proper access control and permissions are set on the
Key Vault to restrict access to secrets.

10. Scenario: You are deploying infrastructure using Terraform, and


you want to validate the correctness of your configuration before
applying changes. How would you perform this validation?
Answer: To validate the correctness of your Terraform configuration
before applying changes, you can use the `terraform validate` command.
Running this command checks for syntax errors, invalid resource
configurations, and missing required arguments in your Terraform
configuration files. Additionally, you can utilize linting tools like TFLint,
which provides additional checks for best practices, security issues, and
coding standards specific to Terraform.
Remember to familiarize yourself with various scenarios that align with
your target infrastructure and cloud providers. These scenario-based
questions help assess your ability to design, implement, and manage
infrastructure using Terraform in practical situations. Additionally,
demonstrating an understanding of best practices, resource dependencies,
and integration with other tools or services will showcase your expertise in
Terraform.
Terraform Commands
1. `terraform init`: Initializes a new or existing Terraform working
directory.
- Output: Initializes the working directory and downloads any required
provider plugins.
- Explanation: This command sets up the working directory for
Terraform and prepares it for further operations.

2. `terraform plan`: Creates an execution plan by comparing the


desired state with the current state.
- Output: Shows the changes that Terraform will make to achieve the
desired state.
- Explanation: This command helps you preview the infrastructure
changes Terraform will make before actually applying them.

3. `terraform apply`: Applies the changes to reach the desired state of


the configuration.
- Output: Deploys or modifies the infrastructure as defined in the
Terraform configuration files.
- Explanation: This command executes the changes defined in your
Terraform configuration and brings your infrastructure to the desired state.

4. `terraform destroy`: Destroys the infrastructure created by


Terraform.
- Output: Removes all the resources created by Terraform, effectively
destroying the infrastructure.
- Explanation: This command helps you tear down the infrastructure
provisioned using Terraform.

5. `terraform validate`: Validates the configuration files for correct


syntax and formatting.
- Output: Verifies that the Terraform configuration files are valid.
- Explanation: This command checks the syntax and structure of your
Terraform configuration files for any errors or warnings.

6. `terraform get`: Downloads and installs the providers required for


the configuration.
- Output: Retrieves the necessary provider plugins specified in the
configuration.
- Explanation: This command downloads and installs the provider
plugins required by your Terraform configuration.

7. `terraform refresh`: Updates the state file with the current real-
world infrastructure.
- Output: Updates the Terraform state file with the current state of the
deployed infrastructure.
- Explanation: This command retrieves the real-world state of the
infrastructure and updates the Terraform state file accordingly.

8. `terraform output`: Shows the output values defined in the


configuration.
- Output: Displays the values of the outputs defined in the Terraform
configuration.
- Explanation: This command helps you view the output values defined
in your Terraform configuration.

9. `terraform state list`: Lists all the resources in the Terraform state.
- Output: Lists all the resources managed by Terraform.
- Explanation: This command displays a list of all resources managed by
Terraform, including their addresses.

10. `terraform state show`: Shows the attributes of a specific resource


in the Terraform state.
- Output: Displays the attributes and details of a specific resource.
- Explanation: This command provides a detailed view of a specific
resource in the Terraform state, including its attributes and metadata.

11. `terraform state mv`: Moves a resource within the Terraform


state.
- Output: Updates the resource's address within the Terraform state.
- Explanation: This command allows you to change the address or path
of a resource within the Terraform state.

12. `terraform state rm`: Removes a resource from the Terraform


state.
- Output: Removes the specified resource from the Terraform state.
- Explanation: This command deletes a resource from the Terraform
state, but it does not destroy the actual infrastructure.

13. `terraform import`: Imports existing infrastructure into the


Terraform state.
- Output: Adds an existing resource to the Terraform state.
- Explanation: This command enables you to import an existing
resource into the Terraform state to manage it with Terraform.

14. `terraform graph`: Creates a visual representation of the


Terraform dependency graph.
- Output: Generates a DOT file that represents the infrastructure's
dependency graph.
- Explanation: This
command visualizes the dependency graph of your Terraform
configuration, helping you understand the relationships between resources.

15. `terraform fmt`: Rewrites configuration files to a consistent


format.
- Output: Formats the Terraform configuration files in a consistent style.
- Explanation: This command automatically formats your Terraform
configuration files, ensuring consistent indentation, spacing, and other
formatting rules.

16. `terraform workspace list`: Lists all available workspaces.


- Output: Displays a list of all available Terraform workspaces.
- Explanation: This command shows all the workspaces you have
created in Terraform, which allow you to manage multiple sets of
infrastructure configurations.

17. `terraform workspace new`: Creates a new workspace.


- Output: Creates a new Terraform workspace.
- Explanation: This command creates a new workspace in Terraform,
allowing you to manage different sets of infrastructure configurations
separately.

18. `terraform workspace select`: Switches to a different workspace.


- Output: Switches the current workspace to the selected workspace.
- Explanation: This command allows you to switch between different
Terraform workspaces, making it easier to manage and deploy different
environments or configurations.

19. `terraform workspace delete`: Deletes a workspace.


- Output: Deletes the specified Terraform workspace.
- Explanation: This command deletes a specific Terraform workspace,
removing all associated state and configuration files.

20. `terraform output -json`: Shows the output values in JSON


format.
- Output: Displays the output values in JSON format.
- Explanation: This command presents the output values defined in your
Terraform configuration in a JSON format, which can be useful for
scripting and automation.

21. `terraform state pull`: Retrieves the current state and saves it to a
local file.
- Output: Saves the Terraform state to a local file.
- Explanation: This command allows you to pull the current Terraform
state and save it to a local file for analysis or backup purposes.
22. `terraform state push`: Updates the remote state with the contents
of a local state file.
- Output: Pushes the local state file to update the remote Terraform
state.
- Explanation: This command pushes the contents of a local state file to
update the remote state stored in a backend.

23. `terraform import aws_instance.example i-abcd1234`: Imports an


EC2 instance with the specified ID into the Terraform state.
- Output: Adds the specified EC2 instance to the Terraform state.
- Explanation: This command imports an existing EC2 instance with the
given ID into the Terraform state, allowing you to manage it with
Terraform.

24. `terraform import aws_s3_bucket.example my-bucket`: Imports


an S3 bucket with the specified name into the Terraform state.
- Output: Adds the specified S3 bucket to the Terraform state.
- Explanation: This command imports an existing S3 bucket with the
given name into the Terraform state, enabling you to manage it using
Terraform.

25. `terraform import aws_security_group.example sg-abcd1234`:


Imports a security group with the specified ID into the Terraform
state.
- Output: Adds the specified security group to the Terraform state.
- Explanation: This command imports an existing security group with
the given ID into the Terraform state for management.

26. `terraform import aws_vpc.example vpc-abcd1234`: Imports a


VPC with the specified ID into the Terraform state.
- Output: Adds the specified VPC to the Terraform state.
- Explanation: This command imports an existing VPC with the given
ID into the Terraform state, allowing you to manage it with Terraform.

27. `terraform import aws_route53_zone.example example.com`:


Imports a Route53 zone with the specified name into the Terraform state.
- Output: Adds the specified Route53 zone to the Terraform state.
- Explanation: This command imports an existing Route53 zone with
the given name into the Terraform state for management.
28. `terraform import azurerm_resource_group.example
/subscriptions/abcd1234/resourceGroups/my-rg`: Imports an Azure
resource group with the specified ID into the Terraform state.
- Output: Adds the specified Azure resource group to the Terraform
state.
- Explanation: This command imports an existing Azure resource group
with the given ID into the Terraform state, allowing you to manage it with
Terraform.

29. `terraform import azurerm_virtual_network.example


/subscriptions/abcd1234/resourceGroups/my-
rg/providers/Microsoft.Network/virtualNetworks/my-vnet`: Imports
an Azure virtual network with the specified ID into the Terraform
state.
- Output: Adds the specified Azure virtual network to the Terraform
state.
- Explanation: This command imports an existing Azure virtual network
with the given ID into the Terraform state for management.

30. `terraform import azurerm_storage_account.example


/subscriptions/abcd1234/resourceGroups/my-
rg/providers/Microsoft.Storage/storageAccounts/my-storage-account`:
Imports an Azure storage account with the specified ID into the
Terraform state.
- Output: Adds the specified Azure storage account to the Terraform
state.
- Explanation: This command imports an existing Azure storage account
with the given ID into the Terraform state, enabling you to manage it using
Terraform.

31. `terraform import azurerm_virtual_machine.example


/subscriptions/abcd1234/resourceGroups/my-
rg/providers/Microsoft.Compute/virtualMachines/my-vm`: Imports
an Azure virtual machine with the specified ID into the Terraform
state.
- Output: Adds the specified Azure virtual machine to the Terraform
state.
- Explanation: This command imports an existing Azure virtual machine
with the given ID into the Terraform state, allowing you to manage it with
Terraform.
32. `terraform import google_compute_instance.example projects/my-
project/zones/us-central1-a/instances/my-instance`: Imports a Google
Compute Engine instance with the specified ID into the Terraform
state.
- Output: Adds the specified Google Compute Engine instance to the
Terraform state.
- Explanation: This command imports an existing Google Compute
Engine instance with the given ID into the Terraform state for
management.

33. `terraform import google_compute_network.example projects/my-


project/global/networks/my-network`: Imports a Google Compute
Engine network with the specified ID into the Terraform state.
- Output: Adds the specified Google Compute Engine network to the
Terraform state.
- Explanation: This command imports an existing Google Compute
Engine network with the
given ID into the Terraform state, allowing you to manage it with
Terraform.

34. `terraform import google_storage_bucket.example my-bucket`:


Imports a Google Cloud Storage bucket with the specified name into
the Terraform state.
- Output: Adds the specified Google Cloud Storage bucket to the
Terraform state.
- Explanation: This command imports an existing Google Cloud Storage
bucket with the given name into the Terraform state for management.

35. `terraform import google_dns_managed_zone.example example-


com`: Imports a Google Cloud DNS managed zone with the specified
name into the Terraform state.
- Output: Adds the specified Google Cloud DNS managed zone to the
Terraform state.
- Explanation: This command imports an existing Google Cloud DNS
managed zone with the given name into the Terraform state, enabling you
to manage it using Terraform.
36. `terraform import null_resource.example my-resource`: Imports a
null resource with the specified name into the Terraform state.
- Output: Adds the specified null
resource to the Terraform state.
- Explanation: This command imports an existing null resource with the
given name into the Terraform state, allowing you to manage it with
Terraform.

37. `terraform import random_pet.example my-pet`: Imports a


random_pet resource with the specified name into the Terraform
state.
- Output: Adds the specified random_pet resource to the Terraform
state.
- Explanation: This command imports an existing random_pet resource
with the given name into the Terraform state for management.

38. `terraform import template_file.example my-template`: Imports a


template_file resource with the specified name into the Terraform
state.
- Output: Adds the specified template_file resource to the Terraform
state.
- Explanation: This command imports an existing template_file resource
with the given name into the Terraform state, allowing you to manage it
with Terraform.

39. `terraform import local_file.example my-file`: Imports a local_file


resource with the specified name into the Terraform state.
- Output: Adds the specified local_file resource to the Terraform state.
- Explanation: This command imports an existing local_file resource
with the given name into the Terraform state for management.

40. `terraform import aws_lambda_function.example my-function`:


Imports an AWS Lambda function with the specified name into the
Terraform state.
- Output: Adds the specified AWS Lambda function to the Terraform
state.
- Explanation: This command imports an existing AWS Lambda
function with the given name into the Terraform state, allowing you to
manage it with Terraform.
41. `terraform import aws_dynamodb_table.example my-table`:
Imports an Amazon DynamoDB table with the specified name into the
Terraform state.
- Output: Adds the specified Amazon DynamoDB table to the
Terraform state.
- Explanation: This command imports an existing Amazon DynamoDB
table with the given name into the Terraform state for management.

42. `terraform import aws_cloudfront_distribution.example my-


distribution`: Imports an Amazon CloudFront distribution with the
specified ID into the Terraform state.
- Output: Adds the specified Amazon CloudFront distribution to the
Terraform state.
- Explanation: This command imports an existing Amazon CloudFront
distribution with the given ID into the Terraform state, enabling you to
manage it using Terraform.

43. `terraform import aws_elasticsearch_domain.example my-


domain`: Imports an Amazon Elasticsearch domain with the specified
name into the Terraform state.
- Output: Adds the specified Amazon Elasticsearch domain to the
Terraform state.
- Explanation: This command imports an existing Amazon Elasticsearch
domain with the given name into the Terraform state, allowing you to
manage it with Terraform.

44. `terraform import aws_sqs_queue.example my-queue`: Imports an


Amazon Simple Queue Service (SQS) queue with the specified name
into the Terraform state.
- Output: Adds the specified Amazon SQS queue to the Terraform state.
- Explanation: This command imports an existing Amazon SQS queue
with the given name into the Terraform state for management.

45. `terraform import aws_sns_topic.example my-topic`: Imports an


Amazon Simple Notification Service (SNS) topic with the specified
name into the Terraform state.
- Output: Adds the specified Amazon SNS topic to the Terraform state.
- Explanation: This command imports an existing Amazon SNS topic
with the given name into the Terraform state, enabling you to manage it
using Terraform.
46. `terraform import aws_ecr_repository.example my-repo`: Imports
an Amazon Elastic Container Registry (ECR) repository with the
specified name into the Terraform state.
- Output: Adds the specified Amazon ECR repository to the Terraform
state.
- Explanation: This command imports an existing Amazon ECR
repository with
the given name into the Terraform state for management.

47. `terraform import aws_iam_role.example my-role`: Imports an


AWS Identity and Access Management (IAM) role with the specified
name into the Terraform state.
- Output: Adds the specified IAM role to the Terraform state.
- Explanation: This command imports an existing IAM role with the
given name into the Terraform state, allowing you to manage it with
Terraform.

48. `terraform import aws_kinesis_stream.example my-stream`:


Imports an Amazon Kinesis stream with the specified name into the
Terraform state.
- Output: Adds the specified Amazon Kinesis stream to the Terraform
state.
- Explanation: This command imports an existing Amazon Kinesis
stream with the given name into the Terraform state for management.

49. `terraform import aws_cloudwatch_dashboard.example my-


dashboard`: Imports an Amazon CloudWatch dashboard with the
specified name into the Terraform state.
- Output: Adds the specified Amazon CloudWatch dashboard to the
Terraform state.
- Explanation: This command imports an existing Amazon CloudWatch
dashboard with the given name into the Terraform state, enabling you to
manage it using Terraform.

50. `terraform import aws_api_gateway_rest_api.example my-api`:


Imports an Amazon API Gateway REST API with the specified ID
into the Terraform state.
- Output: Adds the specified Amazon API Gateway REST API to the
Terraform state.
- Explanation: This command imports an existing Amazon API
Gateway REST API with the given ID into the Terraform state, allowing
you to manage it with Terraform.

Ansible Interview Question & Answers

Ansible interview question and answers for BEGINER LEVEL


Q1: What is Ansible?
Ansible is an open-source automation tool that allows you to automate the
configuration, management, and deployment of systems. It uses a simple
and declarative language called YAML to define the automation tasks,
making it easy to understand and maintain.

Q2: What are the key components of Ansible?


The key components of Ansible are:
- Inventory: It is a list of hosts or servers on which Ansible performs
operations.
- Playbooks: They are YAML files that define the tasks and automation
steps.
- Modules: These are small pieces of code that Ansible executes on remote
hosts to perform specific tasks.
- Ad-hoc commands: These are commands that you can run on the
command line using the `ansible` command, without the need for a
playbook.

Q3: What is an Ansible playbook?


An Ansible playbook is a YAML file that defines a set of tasks and
configurations to be executed on remote hosts. Playbooks are used to
automate complex tasks and workflows, allowing you to define the desired
state of the system and let Ansible handle the execution.

Q4: How do you define a variable in Ansible?


In Ansible, you can define variables in multiple ways:
- In the playbook: You can define variables directly in the playbook using
the `vars` keyword.

You might also like