Skip to main content

Posts

LOCAL PROVISIONER

make one folder projectB projectB : make one file index.html generate key : ssh-kegen  VIM AR.TF   provider "aws" {   region     = "us-east-1"   access_key = "AUGQ"   secret_key = "Kt1aurid" } variable "privatekey" {   default = "dev" } resource "aws_key_pair" "dev" {   key_name   = "dev"   public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDhI176Z0ylP2WdWAbI2hrFf5oEHlnZ0zcSm85SGysuwx/lMl0F+muOcke0wS90f5NU+bUAKNL2hWFozx/HxEtaquM77go+eWY9lg1E7q9Ls8nzVv1pddNgtS7Cihgzd7UaXDq0ayhOUBO1y6nMZYobFNy4E63vBuCYyhHwPAT7mheZm2GphKYrkd1Qt4qvcZcJ4CBmjCwQ3VBdwOhk8ZdKc7BdpLNPENNCLkzswhNcpRInRADMAM1ZgPikKt8wEaeMX/Hg2Mrk0MS49mYFnPxc1G5DuSsW7P9L+7IzbGI2pl4RSLM8/IlFef/i1HWgdaDCJpejgxLX4Hux9EUyqtd1 root@ip-172-31-46-6.ap-south-1.compute.internal" } resource "aws_instance" "web" {   ami           = "ami-02e136e904f3da870"   instance_type = "t3.nano"   key_name = "d...

Apache configration via terraform using REMOTE provisioner

 Apache configration via terraform using provisioner in every instance use key pair  craete one file index.html write anything   here we haven't used security group it will use the default but make sure you will go to inbound rules do it anywhere. now check public IP it will show our index message  if we want to go inside instance  ssh -I developer ec2-user@publickey ==================================================== VI AWS.TF provider "aws" {   region     = "us-east-1"   access_key = "AQ"   secret_key = "Kaurid" } resource "aws_key_pair" "developer" {   key_name   = "developer"   public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDhI176Z0ylP2WdWAbI2hrFf5oEHlnZ0zcSm85SGysuwx/lMl0F+muOcke0wS90f5NU+bUAKNL2hWFozx/HxEtaquM77go+eWY9lg1E7q9Ls8nzVv1pddNgtS7Cihgzd7UaXDq0ayhOUBO1y6nMZYobFNy4E63vBuCYyhHwPAT7mheZm2GphKYrkd1Qt4qvcZcJ4CBmjCwQ3VBdwOhk8ZdKc7BdpLNPENNCLkzswhNcpRInRADMAM1ZgPikKt8wEaeMX/Hg2Mrk0MS49mYFnPxc1...

TERRAFORM STATE MANAGEMENT S3

NOTE: make three directory  mkdir project1  - handled by harry mkdir project1     - danish mkdir project1    - moon vim aws,tf make three instances multiple ppl are working on project1 harry wrote script now danish want to add more so he will copy code from harry and do changes    cp /root/project_a/aws.tf . once danish will try to add some changes but it didnt got backup file.  so it will craete new setup because in his local system state file was NOT existed if danish want to work on same file then he need tfstate file as well cp /root/project_a/aws.tf . cp /root/project_a/terraform.tfstate . store tfstste file in remote  search terraform s3 remote create s3 bucket terraform {   backend "s3" {     bucket = "mybucket"--- bucketname     key    = "abid/moon" inside bucket it will create two folders  abid -- inisde -- moon     region = "us-east-1"     access_key =   ...

OUTPUT VALUE

 note: if we need information about resources like elastic IP, volume etc .  provider "aws" {   region     = "us-east-1"   access_key = "AGQ"   secret_key = "Kkt1aurid" } resource "aws_instance" "web" {   ami           = "ami-02e136e904f3da870"   instance_type = "t3.micro"   tags = {     Name = "moon"   } } resource "aws_vpc" "main" {   cidr_block       = "10.0.0.0/16"   instance_tenancy = "default"   tags = {     Name = "main"   } } ===================================================== VIM OUTPUT.TF output "instance-wrnhole" {   value = aws_instance.web.arn } output "instance-id" {   value = aws_instance.web.id } output "instance-ami" {   value = aws_instance.web.ami } output "vpc-cidr" {   value = aws_vpc.main.cidr_block } output "vpc-tedency" {   value = aws_vpc.main.instance_tenancy } output ...

LOCAL VALUE

  NOTE:  we can use multiple services from one account. we can use tag for each resource . ==local value is good concept than tags ==  if we need to change tag only we need to change local value.. provider "aws" {   region     = "us-east-1"   access_key = "AUGQ"   secret_key = "Kfkt1aurid" } locals {   common_tag = {    Name = "uk-project"    Owner = "moon" } } locals {  usa = {  Name = "us-pro" } } resource "aws_instance" "web" {   ami           = "ami-0ed9277fb7eb570c9"   instance_type = "t3.micro"   tags           = local.common_tag } resource "aws_vpc" "main" {   cidr_block       = "10.0.0.0/16"   instance_tenancy = "default"   tags           = local.common_tag } resource "aws_ebs_volume" "example" {   availability_zone = "us-east-1a"   size    ...

copying snap from one REGION to another

 while copying snap from one to another we need to change region provider "aws" {   region     = "us-west-1"   access_key = "AGQ"   secret_key = "Kurid" } resource "aws_ebs_snapshot_copy" "example_copy" {   source_snapshot_id = "snap-08bc5c27dad8e82b3"   source_region      = "us-east-1"   tags = {     Name = "HelloWorld_copy_snap"   } }

EBS & SNAPSHOT

 provider "aws" {   region     = "us-east-1"   access_key = "AUGQ"   secret_key = "Kf1aurid" } resource "aws_ebs_volume" "example" {   availability_zone = "us-east-1a"   size              = 10   tags = {     Name = "HelloWorld"   } } resource "aws_ebs_snapshot" "example_snapshot" {   volume_id = aws_ebs_volume.example.id   tags = {     Name = "HelloWorld_snap"