Terraform Notes – 14 July – 2023

What is Terraform?
------------------
	IAAC
	Coding for Infra.	
	-----------------
	From Hashicorp
	Written in Go.
	Release
		terraform - cli - free	======== FOCUS
		terraform enterprise - web - hosted - Paid
		terraform cloud - web - public - Paid
	version
		1.5.3
	
What is infra? == Providers
-------------------------
https://registry.terraform.io/browse/providers - 3351

Why Terraform???
======================================================
Code for Everything...
-------------------------
AWS ------> Cloud Formation
Azure -----> ARM
=====================================
ONE coding standard for ALL 
ONE CODE for ALL

ONE Code FOR ALL Providers
======================================================
How it works? Arch??
============================

Step 1 - Download Terrafrom
- https://developer.hashicorp.com/terraform/downloads
- download 
- extract
- copy to c:/tools/terraform
- set c:/tools/terraform in env path
----------------------
How to set env of tool path in powershell
How to set env of tool path in cmd
How to set env of tool path in linux
----------------------

Step 2 - Download Providers BUT using CODING
- aws
- github

#1 - How to store terraform code?
Ans - .tf

# filename
Ans - anything. main.tf

# dir/
	1.tf
	2.tf
	3.tf
------------------------
Is it one project or multiple??? 
- ONE PROJECT - ONE CODE - it merge all into oNE when u run terraform

TO DOWNLOAD PROVIDER
- Add a code to .tf
- $ terraform init



Step 3 - Write a Code
Step 4 - Run Terraform apply|destroy
Step 5 - Check the statefile







providers.tf

terraform {
  required_providers {
    github = {
      source = "integrations/github"
      version = "5.30.1"
    }
	aws = {
      source = "hashicorp/aws"
      version = "5.8.0"
    }
	azurerm = {
      source = "hashicorp/azurerm"
      version = "3.65.0"
    }
  }
}

provider "github" {
  # Configuration options
}

provider "aws" {
  # Configuration options
}

provider "azurerm" {
  # Configuration options
}

aws.tf

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

  tags = {
    Name = "HelloWorld"
  }
}

resource "aws_s3_bucket" "example" {
  bucket = "my-tf-test-bucketxxxxxxxxxxxxxx"

  tags = {
    Name        = "My bucket"
    Environment = "Dev"
  }
}

output "publicip" {
  value       = aws_instance.web.public_ip
  description = "publicip"
}

Commands

terraform init
terraform providers
terraform plan
terraform apply
terraform show
terraform output
terraform destory

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