Terraform Assignment– 2
Providers & Resources
Basic Questions
- Configure the AWS provider in a Terraform configuration file with region set to us-east-1.
- Configure the Azure provider in a Terraform configuration file with a subscription ID.
- Configure the GCP provider in a Terraform configuration file with a project ID.
- Configure the Kubernetes provider with cluster credentials.
- Write a resource block to create an AWS S3 bucket.
- Write a resource block to create an AWS IAM user.
- Write a resource block to create an AWS EC2 instance.
- Create an output that prints the S3 bucket name.
- Create an output that prints the IAM user name.
- Create an output that prints the public IP of the EC2 instance.
- Write a resource block to create an AWS Security Group.
- Write a resource block to create an Azure Resource Group.
- Write a resource block to create a GCP Storage Bucket.
- Write a resource block to create a Kubernetes Namespace.
- Write a resource block to create a Kubernetes Pod running Nginx.
- Use a data source to fetch the latest Amazon Linux 2 AMI.
- Use a data source to fetch the current AWS caller identity.
- Use a data source to fetch the list of available AWS regions.
- Run terraform plan and note the resources that will be created.
- Apply the configuration and verify the resources in the cloud console.
Intermediate Questions
- Write a Terraform configuration that creates an S3 bucket and attaches a bucket policy.
- Write a configuration that creates an IAM role with an attached policy.
- Create an EC2 instance and attach an IAM role to it.
- Launch an EC2 instance and attach a security group.
- Write a configuration that creates a GCP Compute Instance.
- Write a configuration that creates an Azure Virtual Machine.
- Use a data source to fetch the current Azure client configuration.
- Use a data source to fetch GCP project details.
- Write a configuration that launches an EC2 instance only after an S3 bucket is created (explicit dependency).
- Write a configuration that creates a Kubernetes Deployment after a Namespace is created (implicit dependency).
- Write a configuration that tags all AWS resources with project name and environment.
- Create an IAM role and attach it to an EC2 instance using Terraform.
- Write a configuration that creates an S3 bucket and enables versioning.
- Write a configuration that creates an S3 bucket with server-side encryption.
- Use a data source to fetch an existing S3 bucket name and print it.
- Use depends_on to ensure an IAM role is created before an EC2 instance.
- Create an output that prints both EC2 public and private IPs.
- Create an output that prints IAM role ARN.
- Write a configuration to create multiple S3 buckets using count.
- Write a configuration to create multiple EC2 instances using for_each.
Advanced Questions
- Write a Terraform configuration that provisions an S3 bucket, IAM role, and EC2 instance together in one file.
- Add explicit dependency so that the EC2 instance is created only after IAM role creation.
- Write a configuration that provisions an S3 bucket with lifecycle policies.
- Write a configuration that provisions an IAM role with inline policies and attach it to an instance.
- Write a configuration that provisions an EC2 instance with user data that installs Apache.
- Create a configuration that provisions an EC2 instance and outputs its public DNS name.
- Write a configuration that provisions a GCP instance and attaches a service account.
- Write a configuration that provisions an Azure VM and attaches a managed disk.
- Write a Terraform configuration using data sources to fetch AMI IDs, IAM roles, and VPC IDs dynamically.
- Write a complete configuration: AWS Provider → S3 bucket → IAM role → Security Group → EC2 instance → Outputs.