Mid-Senior Level Questions Flashcards
Q: What is the purpose of Terraform in the context of infrastructure as code (IaC)?
Terraform is a tool used for provisioning and managing infrastructure resources through code. It allows you to define and deploy infrastructure in a declarative manner, making it easier to manage and scale your infrastructure.
How does Terraform handle state management?
Terraform uses a state file to store the current state of your infrastructure. This state file tracks the resources that Terraform manages, allowing it to plan and execute changes efficiently.
How can you authenticate Terraform to interact with AWS resources?
Terraform can authenticate with AWS using access keys
You can configure the AWS CLI or provide the keys directly in your Terraform configuration using environment variables or the aws provider block.
How can you create an EC2 instance using Terraform with AWS provider?
To create an EC2 instance using Terraform, you can define a resource block of type aws_instance in your Terraform configuration file. Within this block, you specify the desired attributes of the EC2 instance, such as the instance type, AMI ID, security groups, and key pair. When you apply the configuration, Terraform will provision the EC2 instance based on the defined specifications.
What happens when you run the Terraform plan command?
Terraform analyzes your configuration files and compares it with the current state to determine what changes will be applied.
Then provides an execution plan of the resources that will be created, modified, or deleted without actually executing those changes.
What are modules in Terraform?
Modules are Terraform configuration that can be used multiple times across different projects. They can define a set of resources, inputs, and outputs, providing a way to abstract and reuse common infrastructure patterns.
What are some options for managing remote state backend in Terraform?
Terraform supports remote state management using various backends, such as AWS S3 & DynamoDB(Statelock), or Terraform Cloud
What are the benefits of a remote state backend? 3
By storing the state file remotely, you enable collaboration, versioning, and secure access to the state.
How is remote state backend configured?
Remote state is accessed using a backend configuration in your Terraform configuration files.
How can you manage infrastructure across multiple environments (e.g., development, staging, production) using Terraform?
You can use Terraform workspaces to manage infrastructure across different environments.
Explain how TF workspaces work?
Each workspace represents a separate instance of your infrastructure, allowing you to switch between environments and maintain separate state files and configuration.
What is the purpose of Terraform data sources?
Terraform data sources allow you to retrieve information about existing resources outside of the current Terraform configuration.
What are Terraform provisioners, and when are they used?
Terraform provisioners are used to execute actions or scripts on a local or remote machine after a resource is created or updated.
How can you leverage AWS services to manage secrets and sensitive data in Terraform when working with AWS services?
You can leverage AWS services like Secrets Manager or Parameter Store to store and manage secrets and sensitive data.
Terraform can then retrieve the values from these services during provisioning, ensuring secure storage and access to sensitive information
What are two command that you can use to ensure the correctness and integrity of Terraform configurations before applying them?.
You can use the terraform validate
command to check the syntax and validate the correctness of your Terraform configurations.
terraform fmt
can be used for aligning and formatting, to ensure adherence to best practices