AWS Assignment– 7
Infrastructure as Code (CloudFormation & Terraform)
Basic Questions
- Write a CloudFormation YAML template to create a single EC2 instance.
- Modify the template to add a Security Group allowing SSH (22).
- Add an S3 bucket resource to the CloudFormation template.
- Deploy the stack using AWS Console and note outputs.
- Deploy the same CloudFormation stack using AWS CLI.
- Update the CloudFormation stack to add a second EC2 instance.
- Delete the CloudFormation stack and verify cleanup.
- Write a Terraform configuration to launch a t2.micro EC2 instance.
- Add a Security Group in Terraform allowing HTTP (80).
- Use terraform plan and terraform apply to deploy.
- Add an output variable in Terraform to print the EC2 public IP.
- Define an input variable for instance type in Terraform.
- Use terraform fmt to format the configuration.
- Import an existing S3 bucket into Terraform state.
- Destroy the Terraform-managed resources with terraform destroy.
- Write a CloudFormation JSON template to create an IAM user.
- Create a Terraform configuration for an S3 bucket with versioning enabled.
- Add tags to AWS resources in both CloudFormation and Terraform.
- Compare the difference between CloudFormation and Terraform templates.
- Document basic IaC workflow for DevOps teams.
Intermediate Questions
- Create a CloudFormation template with a VPC, subnet, and Internet Gateway.
- Add an EC2 instance into the subnet using the above template.
- Configure parameters in CloudFormation for VPC CIDR and instance type.
- Use CloudFormation outputs to export values (e.g., Subnet ID).
- Deploy a nested CloudFormation stack (VPC + EC2 in separate templates).
- Write a Terraform module for creating an EC2 instance.
- Use the module to create 2 EC2 instances with different tags.
- Configure Terraform remote state backend using S3 and DynamoDB.
- Create a Terraform configuration with a VPC, subnet, and Internet Gateway.
- Deploy the VPC configuration with Terraform.
- Use Terraform variables to manage environment differences (dev, stage, prod).
- Write a Terraform locals block for resource naming conventions.
- Add a Terraform count argument to deploy multiple subnets dynamically.
- Use Terraform for_each to create multiple Security Groups.
- Manage IAM roles and policies using Terraform.
- Automate stack deployment via Jenkins pipeline using Terraform CLI.
- Automate stack deployment via CodePipeline using CloudFormation.
- Enable drift detection in CloudFormation and review drift results.
- Use Terraform data sources to fetch an existing AMI.
- Document best practices for structuring IaC projects in Git repos.
Advanced Questions
- Write a CloudFormation template for a 3-tier architecture (VPC, ALB, EC2, RDS).
- Deploy the template with parameters for environment (dev, stage, prod).
- Write a Terraform configuration to replicate the same 3-tier architecture.
- Use Terraform workspaces to manage multiple environments.
- Configure CloudFormation stack sets to deploy across multiple AWS accounts.
- Use Terraform to provision resources across two AWS regions.
- Implement conditional logic in CloudFormation templates (e.g., enable/disable resources).
- Write a Terraform script that provisions EC2 + ALB + Auto Scaling Group.
- Integrate Terraform with GitHub Actions for automated plan & apply on commits.
- Final Hands-on Project:
- Use CloudFormation to provision networking stack (VPC, subnets, gateways)
- Use Terraform to provision compute stack (EC2, ASG, ALB)
- Store Terraform state in S3 with DynamoDB locking
- Automate deployments with Jenkins/CodePipeline
- Apply tagging, parameters, outputs, and drift detection
- Document how DevOps teams can mix CloudFormation + Terraform in large-scale projects