DevOps

Wednesday, 17 July 2019

When I try to run git pull origin master, I got the below error.

Git stash

[ec2-user@ip-ec2-instance]$ git pull origin master
From https://git-codecommit.eu-west-2.amazonaws.com/v1/repos/project-repo
 * branch            master     -> FETCH_HEAD
Updating 2ef21e9..5ddaa4e
error: Your local changes to the following files would be overwritten by merge:
        modules/cmx_developer/api_asg_config.tf
Please commit your changes or stash them before you merge.
Aborting

Useful link for Git :

https://git-scm.com/docs/git-stash

Tuesday, 16 July 2019

Terraform State Lock

Terraform state lock looks like below:

[ec2-user@ip-ec2-instance]$ ./terraform taint -module=Module_name null_resource.Resource_name
Acquiring state lock. This may take a few moments...
Error locking state: Error acquiring the state lock: ConditionalCheckFailedException: The conditional request failed
        status code: 400, request id: AEMDRUFBFFVJF66Q9ASUAAJG
Lock Info:
  ID:        a793-kto83-jkfyeoi34h3y2gf
  Path:      env/terraform.tfstate
  Operation: OperationTypePlan
  Who:       @765343
  Version:   0.11.3
  Created:   2019-07-16 15:36:04.221201814 +0000 UTC
  Info:


Terraform acquires a state lock to protect the state from being written
by multiple users at the same time. Please resolve the issue above and try
again. For most commands, you can disable locking with the "-lock=false"
flag, but this is not recommended.

Terraform Installation in and creating AWS EC2 Instance


Install wget and unzip

[root@ip-ec2-instance centos]# yum install wget
[root@ip-ec2-instance centos]# yum install unzip

Download Terraform binary from terraform.io 

[root@ip-ec2-instance centos]# wget https://releases.hashicorp.com/terraform/0.12.4/terraform_0.12.4_linux_amd64.zip
--2019-07-16 07:36:28--  https://releases.hashicorp.com/terraform/0.12.4/terraform_0.12.4_linux_amd64.zip
Resolving releases.hashicorp.com (releases.hashicorp.com)... 151.101.153.183, 2a04:4e42:24::439
Connecting to releases.hashicorp.com (releases.hashicorp.com)|151.101.153.183|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 16039674 (15M) [application/zip]
Saving to: ‘terraform_0.12.4_linux_amd64.zip’

100%[================================================================================================>] 16,039,674  58.1MB/s   in 0.3s

2019-07-16 07:36:28 (58.1 MB/s) - ‘terraform_0.12.4_linux_amd64.zip’ saved [16039674/16039674]

Unzip Terraform binary to /usr/local/bin 

[root@ip-ec2-instance centos]# unzip terraform_0.12.4_linux_amd64.zip -d /usr/local/bin
Archive:  terraform_0.12.4_linux_amd64.zip
  inflating: /usr/local/bin/terraform

Export path to $PATH

[root@ip-ec2-instance ~]# export PATH=$PATH:/usr/local/bin
[root@ip-ec2-instance ~]# echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/root/usr/local/bin:/usr/local/bin

Run terraform command and test

[root@ip-ec2-instance ~]# terraform
Usage: terraform [-version] [-help] <command> [args]

Create a dir and a .tf file with below code

[root@ip-ec2-instance ~]# mkdir terraform
[root@ip-ec2-instance ~]# cd terraform/
[root@ip-ec2-instance terraform]# vi launch_instance.tf

provider "aws" {
        access_key = "XXXXXXX"
        secret_key = "XXXXXXXXXXXXXXXX"
        region = "ap-south-1"
}

resource "aws_instance" "example" {
        ami = "ami-02e60be79e78fef21"
        instance_type = "t2.micro"
        key_name = "key-name"
        tags = {
         Name = "test-instance"
        }
}

AWS access_key and secret_key can also be configured with aws configure command.

In  .aws/credentials file

[terraform]
aws_access_key_id = xxxxxxxxxxxxxxxxxxx
aws_secret_access_key = xxx/xxxxxxxxxxxxx/xxxx
provider "aws" {
  region                  = "eu-west-2"
  shared_credentials_file = "/home/USER/.aws/credentials"
  profile                 = "terraform"
}

Run terraform init to initalize the backend

[root@ip-ec2-instance terraform]# terraform init

Initializing the backend...

Initializing provider plugins...
- Checking for available provider plugins...
- Downloading plugin for provider "aws" (terraform-providers/aws) 2.19.0...

Run terraform plan 

[root@ip-ec2-instance terraform]# terraform plan

Run Terraform apply

[root@ip-ec2-instance terraform]# terraform apply

Wednesday, 10 July 2019

Periodic Table for DevOps Tools

DevOps

What is DevOps?

DevOps is a culture which promotes collaboration between Development and Operations Team to deploy code to production faster in an automated & repeatable way. The word 'DevOps' is a combination of two words 'development' and 'operations.'
DevOps helps to increases an organization's speed to deliver applications and services. It allows organizations to serve their customers better and compete more strongly in the market.
In simple words, DevOps can be defined as an alignment of development and IT operations with better communication and collaboration.

AWS

What is Cloud Computing?

Cloud computing is a term referred to storing and accessing data over the internet. It doesn't store any data on the hard disk of your personal computer. In cloud computing, you can access data from a remote server.

What is AWS?

Amazon web service is a platform that offers flexible, reliable, scalable, easy-to-use and cost-effective cloud computing solutions.
AWS is a comprehensive, easy to use computing platform offered Amazon. The platform is developed with a combination of infrastructure as a service (IaaS), platform as a service (PaaS) and packaged software as a service (SaaS) offerings.