Git Product home page Git Product logo

tf_awscli-commandssyntax_public's Introduction

TF_AWSCLI-CommandsSyntax_Public

Description Details:

This repository provides a detailed step-by-step guide to installing Terraform CLI and AWS CLI on various operating systems. From installation on macOS to configuring AWS credentials, it includes instructions for Windows and Linux. Additionally, it offers an introduction to basic Terraform commands and how to create, verify, and destroy an EC2 instance.

Terraform & AWS CLI Installation

Step-01: Introduction

  • Install Terraform CLI
  • Install AWS CLI
  • Install VS Code Editor
  • Install HashiCorp Terraform plugin for VS Code

Step-02: MACOS: Terraform Install

# Copy binary zip file to a folder
mkdir /Users/<YOUR-USER>/Documents/terraform-install
COPY Package to "terraform-install" folder

# Unzip
unzip <PACKAGE-NAME>
unzip terraform_0.14.3_darwin_amd64.zip

# Copy terraform binary to /usr/local/bin
echo $PATH
mv terraform /usr/local/bin

# Verify Version
terraform version

# To Uninstall Terraform (NOT REQUIRED)
rm -rf /usr/local/bin/terraform

Step-03: MACOS: IDE for Terraform - VS Code Editor

Step-04: MACOS: Install AWS CLI

# Install AWS CLI V2
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /
which aws
aws --version

# Uninstall AWS CLI V2 (NOT REQUIRED)
which aws
ls -l /usr/local/bin/aws
sudo rm /usr/local/bin/aws
sudo rm /usr/local/bin/aws_completer
sudo rm -rf /usr/local/aws-cli

Step-05: MACOS: Configure AWS Credentials

  • Pre-requisite: Should have AWS Account.
  • Generate Security Credentials using AWS Management Console
    • Go to Services -> IAM -> Users -> "Your-Admin-User" -> Security Credentials -> Create Access Key
  • Configure AWS credentials using SSH Terminal on your local desktop
# Configure AWS Credentials in command line
$ aws configure
AWS Access Key ID [None]: xxxxx
AWS Secret Access Key [None]: xxxxx
Default region name [None]: us-east-1
Default output format [None]: json

# Verify if we are able list S3 buckets
aws s3 ls
  • Verify the AWS Credentials Profile
cat $HOME/.aws/credentials 

Step-06: WindowsOS: Terraform & AWS CLI Install

Step-07: LinuxOS: Terraform & AWS CLI Install

Terraform Command Basics

Step-01: Introduction

  • Understand basic Terraform Commands
    • terraform init
    • terraform validate
    • terraform plan
    • terraform apply
    • terraform destroy

Step-02: Review terraform manifest for EC2 Instance

  • Pre-Conditions-1: Ensure you have default-vpc in that respective region
  • Pre-Conditions-2: Ensure AMI you are provisioning exists in that region if not update AMI ID
  • Pre-Conditions-3: Verify your AWS Credentials in $HOME/.aws/credentials
# Terraform Settings Block
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      #version = "~> 3.21" # Optional but recommended in production
    }
  }
}

# Provider Block
provider "aws" {
  profile = "default" # AWS Credentials Profile configured on your local desktop terminal  $HOME/.aws/credentials
  region  = "us-east-1"
}

# Resource Block
resource "aws_instance" "ec2demo" {
  ami           = "ami-04d29b6f966df1537" # Amazon Linux in us-east-1, update as per your region
  instance_type = "t2.micro"
}

Step-03: Terraform Core Commands

# Initialize Terraform
terraform init

# Terraform Validate
terraform validate

# Terraform Plan to Verify what it is going to create / update / destroy
terraform plan

# Terraform Apply to Create EC2 Instance
terraform apply 

Step-04: Verify the EC2 Instance in AWS Management Console

  • Go to AWS Management Console -> Services -> EC2
  • Verify newly created EC2 instance

Step-05: Destroy Infrastructure

# Destroy EC2 Instance
terraform destroy

# Delete Terraform files 
rm -rf .terraform*
rm -rf terraform.tfstate*

Step-08: Conclusion

  • Re-iterate what we have learned in this section
  • Learned about Important Terraform Commands
    • terraform init
    • terraform validate
    • terraform plan
    • terraform apply
    • terraform destroy

tf_awscli-commandssyntax_public's People

Contributors

gerardodavidlopezcastillo avatar

Stargazers

 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.