Terraform – Notes – Day 1 – August

============================
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
Terraform Install & Configurations
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
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
}
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 destroy
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/
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 output
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
}
Subscribe
Notify of
guest

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

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x