Terraform Assignment– 2

Providers & Resources

Basic Questions

  1. Configure the AWS provider in a Terraform configuration file with region set to us-east-1.
  2. Configure the Azure provider in a Terraform configuration file with a subscription ID.
  3. Configure the GCP provider in a Terraform configuration file with a project ID.
  4. Configure the Kubernetes provider with cluster credentials.
  5. Write a resource block to create an AWS S3 bucket.
  6. Write a resource block to create an AWS IAM user.
  7. Write a resource block to create an AWS EC2 instance.
  8. Create an output that prints the S3 bucket name.
  9. Create an output that prints the IAM user name.
  10. Create an output that prints the public IP of the EC2 instance.
  11. Write a resource block to create an AWS Security Group.
  12. Write a resource block to create an Azure Resource Group.
  13. Write a resource block to create a GCP Storage Bucket.
  14. Write a resource block to create a Kubernetes Namespace.
  15. Write a resource block to create a Kubernetes Pod running Nginx.
  16. Use a data source to fetch the latest Amazon Linux 2 AMI.
  17. Use a data source to fetch the current AWS caller identity.
  18. Use a data source to fetch the list of available AWS regions.
  19. Run terraform plan and note the resources that will be created.
  20. Apply the configuration and verify the resources in the cloud console.

Intermediate Questions

  1. Write a Terraform configuration that creates an S3 bucket and attaches a bucket policy.
  2. Write a configuration that creates an IAM role with an attached policy.
  3. Create an EC2 instance and attach an IAM role to it.
  4. Launch an EC2 instance and attach a security group.
  5. Write a configuration that creates a GCP Compute Instance.
  6. Write a configuration that creates an Azure Virtual Machine.
  7. Use a data source to fetch the current Azure client configuration.
  8. Use a data source to fetch GCP project details.
  9. Write a configuration that launches an EC2 instance only after an S3 bucket is created (explicit dependency).
  10. Write a configuration that creates a Kubernetes Deployment after a Namespace is created (implicit dependency).
  11. Write a configuration that tags all AWS resources with project name and environment.
  12. Create an IAM role and attach it to an EC2 instance using Terraform.
  13. Write a configuration that creates an S3 bucket and enables versioning.
  14. Write a configuration that creates an S3 bucket with server-side encryption.
  15. Use a data source to fetch an existing S3 bucket name and print it.
  16. Use depends_on to ensure an IAM role is created before an EC2 instance.
  17. Create an output that prints both EC2 public and private IPs.
  18. Create an output that prints IAM role ARN.
  19. Write a configuration to create multiple S3 buckets using count.
  20. Write a configuration to create multiple EC2 instances using for_each.

Advanced Questions

  1. Write a Terraform configuration that provisions an S3 bucket, IAM role, and EC2 instance together in one file.
  2. Add explicit dependency so that the EC2 instance is created only after IAM role creation.
  3. Write a configuration that provisions an S3 bucket with lifecycle policies.
  4. Write a configuration that provisions an IAM role with inline policies and attach it to an instance.
  5. Write a configuration that provisions an EC2 instance with user data that installs Apache.
  6. Create a configuration that provisions an EC2 instance and outputs its public DNS name.
  7. Write a configuration that provisions a GCP instance and attaches a service account.
  8. Write a configuration that provisions an Azure VM and attaches a managed disk.
  9. Write a Terraform configuration using data sources to fetch AMI IDs, IAM roles, and VPC IDs dynamically.
  10. Write a complete configuration: AWS Provider → S3 bucket → IAM role → Security Group → EC2 instance → Outputs.