Bird
Raised Fist0
AWScloud~30 mins

CloudFormation vs Terraform awareness in AWS - Hands-On Comparison

Choose your learning style10 modes available
CloudFormation vs Terraform Awareness
📖 Scenario: You are working as a cloud engineer who needs to understand the basics of two popular infrastructure tools: AWS CloudFormation and Terraform. Both help you create and manage cloud resources, but they use different ways to describe your infrastructure.Imagine you want to create a simple cloud setup with a virtual server. You will write small pieces of code to represent this setup in both CloudFormation and Terraform formats.
🎯 Goal: Build simple configuration snippets for AWS EC2 instance creation using both CloudFormation and Terraform syntax. This will help you see how each tool defines infrastructure and understand their differences.
📋 What You'll Learn
Create a CloudFormation template snippet defining an EC2 instance with a specific name and instance type.
Create a Terraform configuration snippet defining an EC2 instance with the same name and instance type.
Add a variable or parameter to each snippet to specify the instance type.
Show the final combined snippets representing the EC2 instance creation in both tools.
💡 Why This Matters
🌍 Real World
Cloud engineers often need to write infrastructure code to create and manage cloud resources. Knowing both CloudFormation and Terraform helps them work with different teams and projects.
💼 Career
Understanding these tools is essential for roles like Cloud Engineer, DevOps Engineer, and Site Reliability Engineer, as they automate cloud infrastructure deployment and management.
Progress0 / 4 steps
1
Create CloudFormation EC2 Instance Snippet
Create a CloudFormation template snippet that defines an EC2 instance resource named MyEC2Instance with the instance type t2.micro. Use the resource type AWS::EC2::Instance and set the InstanceType property to t2.micro.
AWS
Hint

Use YAML format with Resources as the root key. Define MyEC2Instance under it with the correct type and properties.

2
Add CloudFormation Parameter for Instance Type
Add a CloudFormation Parameters section to your template with a parameter named InstanceTypeParam. Set its type to String and default value to t2.micro. Then update the InstanceType property of MyEC2Instance to use this parameter with !Ref InstanceTypeParam.
AWS
Hint

Parameters go at the top level. Use !Ref to refer to the parameter inside the resource properties.

3
Create Terraform EC2 Instance Snippet
Create a Terraform configuration snippet that defines an AWS EC2 instance resource named my_ec2_instance using the resource type aws_instance. Set the instance_type attribute to t2.micro and the ami attribute to ami-0c55b159cbfafe1f0 (a common Amazon Linux 2 AMI).
AWS
Hint

Use Terraform HCL syntax. The resource block starts with resource "aws_instance" "my_ec2_instance".

4
Add Terraform Variable for Instance Type
Add a Terraform variable named instance_type with a default value of t2.micro. Then update the instance_type attribute of my_ec2_instance resource to use this variable with var.instance_type.
AWS
Hint

Define variables outside resource blocks. Use var.instance_type inside the resource to refer to the variable.

Practice

(1/5)
1. Which statement best describes the main difference between AWS CloudFormation and Terraform?
easy
A. CloudFormation works only with AWS, while Terraform supports multiple cloud providers.
B. Terraform is only for AWS, CloudFormation supports all clouds.
C. Both tools only work with AWS services.
D. CloudFormation supports multiple clouds, Terraform is AWS-only.

Solution

  1. Step 1: Understand CloudFormation scope

    CloudFormation is designed specifically for AWS and manages AWS resources only.
  2. Step 2: Understand Terraform scope

    Terraform supports many cloud providers like AWS, Azure, Google Cloud, and more.
  3. Final Answer:

    CloudFormation works only with AWS, while Terraform supports multiple cloud providers. -> Option A
  4. Quick Check:

    CloudFormation = AWS-only, Terraform = multi-cloud [OK]
Hint: CloudFormation = AWS-only; Terraform = many clouds [OK]
Common Mistakes:
  • Thinking Terraform only works with AWS
  • Believing CloudFormation supports multiple clouds
  • Confusing both as identical tools
2. Which of the following is the correct way to define a resource in AWS CloudFormation?
easy
A. resource "aws_ec2_instance" "web" {}
B. resource "aws_instance" "web" {}
C. AWS::EC2::Instance:
D. resource "ec2_instance" "web" {}

Solution

  1. Step 1: Identify CloudFormation syntax

    CloudFormation uses YAML or JSON with resource types like 'AWS::EC2::Instance'.
  2. Step 2: Recognize Terraform syntax

    Terraform uses 'resource "aws_instance" "name" {}'.
  3. Final Answer:

    CloudFormation resource types use 'AWS::Service::Resource' format. -> Option C
  4. Quick Check:

    CloudFormation uses AWS:: notation [OK]
Hint: CloudFormation uses AWS::Service::Resource format [OK]
Common Mistakes:
  • Confusing Terraform resource syntax with CloudFormation
  • Using Terraform resource blocks in CloudFormation
  • Misnaming resource types
3. Given this Terraform snippet:
resource "aws_s3_bucket" "bucket" {
  bucket = "my-unique-bucket"
  acl    = "private"
}

What will happen when you run terraform apply?
medium
A. Creates a public S3 bucket named 'my-unique-bucket' in AWS.
B. Fails because bucket names cannot be unique.
C. Throws a syntax error due to missing region.
D. Creates a private S3 bucket named 'my-unique-bucket' in AWS.

Solution

  1. Step 1: Analyze Terraform resource block

    The resource defines an AWS S3 bucket with name 'my-unique-bucket' and ACL set to 'private'.
  2. Step 2: Understand Terraform apply behavior

    Terraform will create the bucket with the specified name and private access control.
  3. Final Answer:

    Creates a private S3 bucket named 'my-unique-bucket' in AWS. -> Option D
  4. Quick Check:

    ACL 'private' means private bucket [OK]
Hint: ACL 'private' means bucket is private [OK]
Common Mistakes:
  • Assuming default ACL is public
  • Expecting syntax error without region (region is set elsewhere)
  • Thinking bucket names cannot be unique (they must be unique)
4. You wrote this CloudFormation snippet:
Resources:
  MyBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: my-bucket
      AccessControl: PublicRead

But deployment fails with an error about bucket name. What is the likely cause?
medium
A. BucketName must be globally unique and 'my-bucket' is already taken.
B. AccessControl property is invalid in CloudFormation.
C. Resource type AWS::S3::Bucket is incorrect.
D. BucketName cannot be specified in CloudFormation.

Solution

  1. Step 1: Understand S3 bucket naming rules

    S3 bucket names must be globally unique across all AWS accounts.
  2. Step 2: Analyze error cause

    If 'my-bucket' is already used, deployment fails due to name conflict.
  3. Final Answer:

    BucketName must be globally unique and 'my-bucket' is already taken. -> Option A
  4. Quick Check:

    S3 bucket names are global and unique [OK]
Hint: S3 bucket names must be globally unique [OK]
Common Mistakes:
  • Thinking AccessControl is invalid (it is valid)
  • Assuming resource type is wrong
  • Believing BucketName is optional or disallowed
5. Your team wants to manage infrastructure across AWS, Azure, and Google Cloud with one tool. Which approach is best?
hard
A. Use AWS CloudFormation for all clouds to keep consistency.
B. Use Terraform because it supports multiple cloud providers.
C. Use separate CloudFormation stacks for each cloud provider.
D. Use manual console setup for each cloud to avoid tool complexity.

Solution

  1. Step 1: Identify tool cloud support

    CloudFormation only supports AWS, so it cannot manage Azure or Google Cloud.
  2. Step 2: Choose tool for multi-cloud management

    Terraform supports AWS, Azure, Google Cloud, and others in one tool.
  3. Step 3: Evaluate other options

    Separate CloudFormation stacks or manual setup increase complexity and reduce automation benefits.
  4. Final Answer:

    Use Terraform because it supports multiple cloud providers. -> Option B
  5. Quick Check:

    Terraform = multi-cloud support [OK]
Hint: Terraform supports many clouds; CloudFormation is AWS-only [OK]
Common Mistakes:
  • Assuming CloudFormation works outside AWS
  • Thinking manual setup is simpler for multi-cloud
  • Believing separate CloudFormation stacks can manage non-AWS clouds
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard