Skip to content

canaokar/terraform-workshop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Instalation:

Step 1:

Install Terraform : https://developer.hashicorp.com/terraform/install

Step 2:

  1. Install AWS CLI: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html

  2. Run command aws configure and follow instructions.

Tasks:

Step 1: Build an EC2 instance with Terraform

  1. Create a directory, use any name you like.

  2. Create a main.tf file:

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.16"
    }
  }

  required_version = ">= 1.2.0"
}

provider "aws" {
  region = "ap-south-1"
}

resource "aws_instance" "app_server_[YOUR_NAME]" {
  ami           = "ami-0f58b397bc5c1f2e8"
  instance_type = "t2.micro"

  tags = {
    Name = "my-terraform-demo-[YOUR_NAME]"
  }
}

output "instance_ip_address" {
  description = "The public IP address of the instance"
  value       = aws_instance.app_server_[YOUR_NAME].public_ip
}
  1. In the directory, run the command terraform init

  2. Run terraform plan

  3. Run terraform apply, enter Yes.

Step 2: Change Infrastructure

  1. Change the ami value in the main.tf file to ami-02e1a4ebef29334f9

  2. Run terraform plan

  3. Run terraform apply, enter Yes

Step 3: Add Variables

  1. Create a new file variables.tf:
variable "instance_name" {
  description = "Value of the Name tag for the EC2 instance"
  type        = string
  default     = "my-new-terraform-demo-[YOUR_NAME]"
}
  1. Make changes to the main.tf file:

    In the tags section, replace Name = "my-terraform-demo-[YOUR_NAME] with Name = var.instance_name

  2. Run terraform plan

  3. Run terraform apply, enter Yes

Step 4: Destroy the Infrastructure

  1. Run terraform destroy, enter Yes

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages