#Lab: Infrastructure as Code
Deploy infrastructure using Terraform.
#🎯 Objectives
- Write Terraform configuration
- Manage state
- Deploy and destroy resources
#Task 1: Basic AWS Infrastructure
hcl
1# main.tf
2terraform {
3 required_providers {
4 aws = {
5 source = "hashicorp/aws"
6 version = "~> 5.0"
7 }
8 }
9}
10
11provider "aws" {
12 region = "us-east-1"
13}
14
15resource "aws_instance" "web" {
16 ami = "ami-0c55b159cbfafe1f0"
17 instance_type = "t2.micro"
18
19 tags = {
20 Name = "lab-instance"
21 }
22}
23
24output "public_ip" {
25 value = aws_instance.web.public_ip
26}#Task 2: Deploy
bash
terraform init
terraform plan
terraform apply#Task 3: Clean Up
bash
terraform destroy#✅ Success Criteria
- Terraform initialized
- Plan shows changes
- Instance deployed
- Instance destroyed