Terraform – Notes – Day 1 – August

DevOps

MOTOSHARE 🚗🏍️
Turning Idle Vehicles into Shared Rides & Earnings

From Idle to Income. From Parked to Purpose.
Earn by Sharing, Ride by Renting.
Where Owners Earn, Riders Move.
Owners Earn. Riders Move. Motoshare Connects.

With Motoshare, every parked vehicle finds a purpose. Owners earn. Renters ride.
🚀 Everyone wins.

Start Your Journey with Motoshare
============================
LUNCH Hour - 12PM MALAY == 10 AM IST
BREAK - 	11 AM MALAY == 8:30 AM IST
		3 PM MALAY == 12:00


Demo and LAb == AWS
===================================
https://devopsschool.com/slides/terraform/index.html
=====================================================


What is Terraform?
--------------------------------
	I A A C
	Coding for Infra
	Infra Auto Tool

	Release
		Community   	-- CMD - FREE
		Enterprise  	-- GUI - PAID -> Hosted
		Cloud		-- GUI - PAID -> Cloud
	Version - 1.5.5

	Written in Go

	by Hashicorp
	https://www.hashicorp.com/

Why Terraform?
------------------------------------------------------------
			ONE CODING STANDARD FOR ALL (3441 Apps)
					Automate for all
					coding for all
AWS ---> Cloudformation
Azure ----> ARM
Kubernetes -> Helm
Github -> Shell
20 Apps -----> 20 Diff Method of CODING STANDARD TO AUTOMATE


Whats in Infra? -- 3441 Apps
----------------------------------------
Azure  - AWS - GoogleC -> Github - Kubernetes
https://registry.terraform.io/browse/providers

==================================================
How Terraform Works?
==================================================



API CALL
	====	
	PROGRAMMER	- Create 	- Read 		- Update 	- Delete
	
	USER		- POST		GET 		PUT		DELETE
			=======================================================
			POST + PUT 	Delete		GET
			===========	=========	===========
			Apply		Destroy		SHow

			DRY run
			===============
			plan

========================================================
Step 1 - How to install Terraform?
----------------------------------------------------------
https://developer.hashicorp.com/terraform/downloads
<blockquote class="wp-embedded-content" data-secret="axZJqPRXsW"><a href="https://www.devopsschool.com/blog/terraform-install-configurations/">Terraform Tutorials: Installation & Configurations</a></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="position: absolute; visibility: hidden;" title="“Terraform Tutorials: Installation & Configurations” — DevOpsSchool.com" src="https://www.devopsschool.com/blog/terraform-install-configurations/embed/#?secret=GSDH6yMyIj#?secret=axZJqPRXsW" data-secret="axZJqPRXsW" width="600" height="338" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>

C:\tools\terraform

C:\Users\Rajesh Kumar>doskey /h
terraform
terraform -version
doskey /h
============================================
INstall with reg entry --- 	Standalone
============================================
BLOCKED				DOWNLOAD --> Extracting -> USING

C:\tools\terraform\terraform









	Code language: JavaScript (javascript)
C:\tools\terraform\terraform

workstation
-------------------------
100.25.170.215
ubuntu
rajesh123
=================================================
How to store code?
.tf

dir/
	file1.tf	file2.tf	file3.tf
	========================================
			ONEFILE
-------------------------
How to download Providers?

$ terraform init

C:\Users\Rajesh Kumar\Desktop\Terraform\prj1\.terraform>tree
Folder PATH listing for volume Windows
Volume serial number is DCF7-F64C
C:.
└───providers
    └───registry.terraform.io
        ├───hashicorp
        │   ├───aws
        │   │   └───5.12.0
        │   │       └───windows_amd64
        │   └───azurerm
        │       └───3.69.0
        │           └───windows_amd64
        └───integrations
            └───github
                └───5.33.0
                    └───windows_amd64

C:\Users\Rajesh Kumar\Desktop\Terraform\prj1\.terraform>
terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "5.12.0"
    }
	azurerm = {
      source = "hashicorp/azurerm"
      version = "3.69.0"
    }
	github = {
      source = "integrations/github"
      version = "5.33.0"
    }
  }
}

provider "aws" {
  # Configuration options
}


provider "azurerm" {
  # Configuration options
}

provider "github" {
  # Configuration options
}Code language: PHP (php)
resource "aws_instance" "web" {
  ami           = "ami-053b0d53c279acc90"
  instance_type = "t3.micro"

  tags = {
    Name = "RajeshKumar"
  }
}


resource "aws_instance" "web" {
  ami           = "ami-053b0d53c279acc90"
  instance_type = "t3.micro"

  tags = {
    Name = "RajeshKumar-Update"
  }
}


$ terraform plan
$ terraform apply
$ terraform show
$ terraform destroyCode language: JavaScript (javascript)
provider "github" {
  token = "ddddzBmbF0PyIML"
}


resource "github_repository" "example" {
  name        = "Rajesh-Aug-2023"
  description = "My awesome codebase"
  visibility = "public"
}

https://www.devopsschool.com/blog/how-to-generate-personal-access-tokens-in-github/Code language: JavaScript (javascript)
How to see the output of terraform Run?
https://www.devopsschool.com/blog/terraform-output-variable-example/


output "vms_publicip" {
  value = aws_instance.web.public_ip
}

output "github_repo_name" {
  value = github_repository.example.git_clone_url
}

$ terraform plan
$ terraform apply
$ terraform show
$ terraform destroy
$ terraform outputCode language: JavaScript (javascript)
CODE - https://www.devopsschool.com/blog/terraform-variables-complete-reference-guide/

variable "instance_count" {
  type = number
  default = 1
}


resource "aws_instance" "example" {
  count = var.instance_count
  ami           = "ami-053b0d53c279acc90"
  instance_type = "t2.micro"
}

variable "instance_name" {
  type = string
  default = "my-instance"
}

resource "aws_instance" "example-number" {
  count = var.instance_count
  ami           = "ami-053b0d53c279acc90"
  instance_type = "t2.micro"
}


variable "security_groups" {
  type = list(string)
  default = ["default"]
}


resource "aws_instance" "example-list" {
  ami           = "ami-053b0d53c279acc90"
  instance_type = "t2.micro"
  vpc_security_group_ids = var.security_groups
}



variable "instance_tags" {
  type = map(string)
  default = {
    Name = "my-instance"
  }
}

resource "aws_instance" "example-map" {
  ami           = "ami-053b0d53c279acc90"
  instance_type = "t2.micro"
  tags = var.instance_tags
}

variable "create_vm" {
  description = "If set to true, it will create vm"
   type   = bool
}

resource "aws_instance" "example-bool" {
  count   = var.create_vm ? 1 : 0
  ami           = "ami-053b0d53c279acc90"
  instance_type = "t2.micro"
  tags = var.instance_tags
}Code language: PHP (php)
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x