Terraform Answers
Terraform Answers
Terraform Basics:
What is Terraform, and how does it differ from other IaC tools like? CloudFormation or Ansible?
A: Terraform is not platform specific allows users to provision computing in different cloud platforms
A: Provider enables terraform to interact with external resources which includes different cloud
providers.
What are the different Terraform commands? (e.g., terraform init , terraform
A: ., terraform init—It initates the working directory containing terraform configuration files.
Terraform Apply makes the configuration changes as per terraform configuration files.
A: Terraform state file is the reference file for terraform which contains the information of
infrastructure and configuration-Terraform state file helps in maintaining the deployments stable and
reliable.
How can you store Terraform state remotely, and why is it useful?
A: Terraform state file can be remotely stored using remote storage sources of different cloud
platforms like AWS S3, Azure cloud storage.
Remote state file can be used to share it among different users and can be common source for
updates and changes in the configuration.
A: Terraform resources helps in defining Infrastructure or services that needs to be managed Ex:
Servers, database, Storage and network configurations
How do you define variables in Terraform? What are input variables and output
variables?
A: Variable is the place holder for values : Variable can be defined using variable block and variable
name—with in the block attributes and values can be defined.
Output variables are like return values which stores the output of the files.
What are data sources in Terraform, and how are they used?
A: Data source helps in sourcing the information from external sources and use it in terraform
configuration, Data source used using the data keyword configuration.
What are providers in Terraform? How do you configure the AWS provider?
A: Provider enables terraform to interact with external resources which includes different cloud
providers.
Terraform provider can be configured using provider blocks in the main module of a Terraform
configuration:
bucket = "my-unique-bucket-name"
tags = {
Name = "MyS3Bucket"
enabled.
bucket = "my-unique-bucket-name"
tags = {
Name = "MyS3Bucket"
bucket = aws_s3_bucket.bucket.id
versioning_configuration {
status = "Enabled"
bucket = aws_s3_bucket.bucket.id
Ami=amiid
What are the key attributes needed for the EC2 instance (e.g., AMI ID,
A: SSH Key-gen command is used to generate keys bother private and public keys
Modify your EC2 instance configuration to use variables for AMI ID and instance
type.
A: ami =var.amiid
Type=var.type
How do you define variables in Terraform?
Tfvar file is for giving the actual variable values which are used during execution
A: .tfvar file allow you to store the default values of the variables mentioned in variable.tf file and
user can override the values mentioned in tfvar file.
Create a VPC with a public subnet, Internet Gateway, and route table using
Terraform.
A:
resource "aws_route_table_association" "name" {
}
7. Task 5 - Auto-scaling and Load Balancing:
A:
resource "aws_autoscaling_group" "groupname" {
How can you attach the Load Balancer to your Auto Scaling group?
How can you create a module for deploying an EC2 instance and reuse it?
A:Provider “aws”{
Region=default region
}
Module ec2_instance{
}
How do you source modules from the Terraform Registry?
A: Modules on the public Terraform Registry can be referenced using a registry source address of
the form <NAMESPACE>/<NAME>/<PROVIDER>.
role = "${aws_iam_role.sto-test-role.name}"
policy_arn = "${data.aws_iam_policy.rolename.arn}"
bucket = "rstatebuck1"
key = "rlock1"
region = "us-east-1"
dynamodb_table = "lockfile1"
A: State management helps in securing the state file from unauthorised deletion or changes and also
helps in sharing the file with other team members with ease.
A: Creating a bucket
Table is created in Dyanamo DB and keyed upon using LockID and it is set
upon to bucket name.
How do you configure a backend with an S3 bucket and DynamoDB table for
state management?
staging, prod).
A: Workspace allows you to manage multiple environments for infrastructure resources using single
configuration—I logically divides the configuration based on environments like dev.prod.deploy
How do you create different environments using workspaces?
How can you use a data source to reference an existing VPC or AMI in
AWS?
cloud-init allows you to pass a shell script to your instance that installs or configures the
machine to your specifications.
script?
Use AWS Secrets Manager with Terraform to securely store sensitive information.
How do you create secrets in AWS Secrets Manager using Terraform?
A:
What are Security Groups, and how do you create them in Terraform?
How do you create Network ACLs (NACLs) for controlling traffic at the
subnet level?
30 days.