0
0
Terraformcloud~30 mins

Immutable infrastructure concept in Terraform - Mini Project: Build & Apply

Choose your learning style9 modes available
Immutable Infrastructure Concept with Terraform
📖 Scenario: You are working as a cloud engineer. Your team wants to use immutable infrastructure to deploy a simple web server. This means instead of changing the existing server, you will create a new server each time you deploy. This helps avoid errors and keeps the system stable.
🎯 Goal: Build a Terraform configuration that creates an AWS EC2 instance with immutable infrastructure principles. You will first define the instance data, then add a configuration variable, apply the main resource block, and finally complete the setup with a tag to identify the instance.
📋 What You'll Learn
Use Terraform to define AWS EC2 instance configuration
Create a variable for the AMI ID
Define the EC2 instance resource using the variable
Add a tag to the instance for identification
💡 Why This Matters
🌍 Real World
Immutable infrastructure helps teams deploy cloud servers safely by replacing servers instead of changing them. This reduces errors and downtime.
💼 Career
Cloud engineers and DevOps professionals use Terraform and immutable infrastructure to automate and improve cloud deployments.
Progress0 / 4 steps
1
Define the AWS provider and instance data
Write Terraform code to set the AWS provider with region us-east-1 and create a variable called ami_id with default value "ami-0c55b159cbfafe1f0".
Terraform
Need a hint?

Use provider "aws" block to set the region. Use variable "ami_id" block with default to set the AMI ID.

2
Add instance type configuration
Add a variable called instance_type with default value "t2.micro" to specify the EC2 instance type.
Terraform
Need a hint?

Use a variable block named instance_type with a default value.

3
Create the EC2 instance resource
Write a resource block named aws_instance with name web_server. Use var.ami_id for the AMI and var.instance_type for the instance type.
Terraform
Need a hint?

Use resource "aws_instance" "web_server" block. Set ami and instance_type using variables.

4
Add a Name tag to the EC2 instance
Inside the aws_instance.web_server resource, add a tags block with Name = "ImmutableWebServer" to identify the instance.
Terraform
Need a hint?

Inside the resource block, add tags = { Name = "ImmutableWebServer" } to label the instance.