Terraform Assignment– 1

Terraform Core Concepts

Basic Questions

  1. Install Terraform on your system and verify the version.
  2. Write a simple Terraform configuration file that prints “Hello Terraform” using the local_file resource.
  3. Initialize a Terraform working directory using terraform init.
  4. Run terraform plan on a configuration file and observe the output.
  5. Run terraform apply to create a resource.
  6. Run terraform destroy to remove the resource.
  7. Create a Terraform configuration to launch a single AWS EC2 instance.
  8. Use variables for the EC2 instance type and AMI ID.
  9. Create an output that prints the public IP of the EC2 instance.
  10. Define a string variable and print its value using output.
  11. Define a number variable and print its value using output.
  12. Define a bool variable and print its value using output.
  13. Define a list variable and print the first element using output.
  14. Define a map variable and print one of its keys using output.
  15. Use interpolation to concatenate two string variables.
  16. Use interpolation to convert a number into a string.
  17. Create a local variable for project name and print it using output.
  18. Write a configuration file that defines an AWS provider with region.
  19. Format your Terraform code using terraform fmt.
  20. Validate your configuration file using terraform validate.

Intermediate Questions

  1. Write a Terraform configuration to create two EC2 instances using a list variable.
  2. Write a Terraform configuration to create three subnets inside a VPC using a list variable.
  3. Define a map variable of instance types for dev, test, and prod, and print prod instance type.
  4. Use an input variable with default value and override it using -var flag.
  5. Use a tfvars file to pass values to variables.
  6. Write a Terraform configuration to create a VPC using variables for CIDR block.
  7. Add outputs for VPC ID and CIDR block.
  8. Create a security group using Terraform and output its ID.
  9. Launch an EC2 instance and attach the security group created with Terraform.
  10. Use an expression with conditional operator to choose instance type based on environment.
  11. Create an output that prints the count of EC2 instances created.
  12. Use locals to store repeated values (e.g., project name, environment).
  13. Use a variable of type object to define multiple values (id, name, size).
  14. Use a variable of type tuple and print its values.
  15. Use the element function to get a specific subnet from a list.
  16. Create a VPC with two subnets and output their IDs.
  17. Write a Terraform configuration to tag all resources with project name and environment.
  18. Import an existing AWS resource into Terraform state using terraform import.
  19. Show the current state file using terraform show.
  20. Use terraform output command to print only the outputs.

Advanced Questions

  1. Write a Terraform configuration to create a VPC with public and private subnets.
  2. Create an internet gateway and attach it to the VPC using Terraform.
  3. Create a route table for the public subnet and associate it.
  4. Launch an EC2 instance inside the public subnet and output its public IP.
  5. Launch a database instance in the private subnet and output its private IP.
  6. Use locals to define tags and apply them to all resources.
  7. Use conditional expressions to create resources only if create_resource variable is true.
  8. Create reusable Terraform code for VPC and reference its outputs in another configuration.
  9. Use variable validation rules (length, regex) for input variables.
  10. Write a complete Terraform configuration: Provider → VPC → Subnets → Security Group → EC2 → Outputs.