Terraform Assignment– 1
Terraform Core Concepts
Basic Questions
- Install Terraform on your system and verify the version.
- Write a simple Terraform configuration file that prints “Hello Terraform” using the local_file resource.
- Initialize a Terraform working directory using terraform init.
- Run terraform plan on a configuration file and observe the output.
- Run terraform apply to create a resource.
- Run terraform destroy to remove the resource.
- Create a Terraform configuration to launch a single AWS EC2 instance.
- Use variables for the EC2 instance type and AMI ID.
- Create an output that prints the public IP of the EC2 instance.
- Define a string variable and print its value using output.
- Define a number variable and print its value using output.
- Define a bool variable and print its value using output.
- Define a list variable and print the first element using output.
- Define a map variable and print one of its keys using output.
- Use interpolation to concatenate two string variables.
- Use interpolation to convert a number into a string.
- Create a local variable for project name and print it using output.
- Write a configuration file that defines an AWS provider with region.
- Format your Terraform code using terraform fmt.
- Validate your configuration file using terraform validate.
Intermediate Questions
- Write a Terraform configuration to create two EC2 instances using a list variable.
- Write a Terraform configuration to create three subnets inside a VPC using a list variable.
- Define a map variable of instance types for dev, test, and prod, and print prod instance type.
- Use an input variable with default value and override it using -var flag.
- Use a tfvars file to pass values to variables.
- Write a Terraform configuration to create a VPC using variables for CIDR block.
- Add outputs for VPC ID and CIDR block.
- Create a security group using Terraform and output its ID.
- Launch an EC2 instance and attach the security group created with Terraform.
- Use an expression with conditional operator to choose instance type based on environment.
- Create an output that prints the count of EC2 instances created.
- Use locals to store repeated values (e.g., project name, environment).
- Use a variable of type object to define multiple values (id, name, size).
- Use a variable of type tuple and print its values.
- Use the element function to get a specific subnet from a list.
- Create a VPC with two subnets and output their IDs.
- Write a Terraform configuration to tag all resources with project name and environment.
- Import an existing AWS resource into Terraform state using terraform import.
- Show the current state file using terraform show.
- Use terraform output command to print only the outputs.
Advanced Questions
- Write a Terraform configuration to create a VPC with public and private subnets.
- Create an internet gateway and attach it to the VPC using Terraform.
- Create a route table for the public subnet and associate it.
- Launch an EC2 instance inside the public subnet and output its public IP.
- Launch a database instance in the private subnet and output its private IP.
- Use locals to define tags and apply them to all resources.
- Use conditional expressions to create resources only if create_resource variable is true.
- Create reusable Terraform code for VPC and reference its outputs in another configuration.
- Use variable validation rules (length, regex) for input variables.
- Write a complete Terraform configuration: Provider → VPC → Subnets → Security Group → EC2 → Outputs.