Code Monkey home page Code Monkey logo

terraform-workshop's Introduction

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

terraform-workshop's People

Contributors

canaokar avatar

Stargazers

Wei He avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.