Thursday, April 18, 2019

How to create EC2 instances using Terraform in Windows | Terraform Files for provisioning EC2 instance on AWS Cloud

Terraform can provision resources on any cloud platform. We will see how we can use Terraform to provision EC2 instance using Windows laptop. Please do the below steps for provisioning EC2 instances on AWS:

Login to AWS console, click on username and go to My security credentials.
 Continue on security credentials, click on access keys

Create a new access key if you don't have one. Make sure you download the keys in your local machine.


Perform below commands in Windows laptop where you have installed Terraform:

First setup your access keys, secret keys and region code locally.
aws configure

Open Git bash and enter below commands:

cd c:

mkdir project-terraform
cd project-terraform

Create Terraform Files
start notepad

variable "aws_region" {
       description = "The AWS region to create things in." 
       default     = "us-east-2

variable "key_name" { 
    description = " SSH keys to connect to ec2 instance" 
    default     =  "myJune2021Key

variable "instance_type" { 
    description = "instance type for ec2" 
    default     =  "t2.micro" 

variable "security_group" { 
    description = "Name of security group" 
    default     = "my-jenkins-security-group-2022" 

variable "tag_name" { 
    description = "Tag Name of for Ec2 instance" 
    default     = "my-ec2-instance" 
variable "ami_id" { 
    description = "AMI for Ubuntu Ec2 instance" 
    default     = "ami-0b9064170e32bde34
save above file as "" under c:\project-terraform folder

start notepad

provider "aws" {
  region = var.aws_region

resource "aws_vpc" "main" {
  cidr_block = ""
  instance_tenancy = "default"
  tags = {
    Name = "main"

#Create security group with firewall rules
resource "aws_security_group" "jenkins-sg-2022" {
  name        = var.security_group
  description = "security group for jenkins"

  ingress {
    from_port   = 8080
    to_port     = 8080
    protocol    = "tcp"
    cidr_blocks = [""]

 ingress {
    from_port   = 22
    to_port     = 22
    protocol    = "tcp"
    cidr_blocks = [""]

 # outbound from Jenkins server
  egress {
    from_port   = 0
    to_port     = 65535
    protocol    = "tcp"
    cidr_blocks = [""]

  tags= {
    Name = var.security_group

resource "aws_instance" "myFirstInstance" {
  ami           = var.ami_id
  key_name = var.key_name
  instance_type = var.instance_type
  vpc_security_group_ids = []
  tags= {
    Name = var.tag_name

save above file as "" under c:\project-terraform folder.
If you dont provide double quote, it will be .txt in the end.

Now execute the below command:
terraform init
* version = "~> 1.22"
Terraform has been successfully initialized!

and then execute the below command
terraform plan
the above command will show how many resources will be added.
Plan: 3 to add, 0 to change, 0 to destroy.

Execute the below command
terraform apply
Plan: 3 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
List Resources created by Terraform
Execute the below command to view list of the resources created by Terraform.
terraform state list
The above command will list three resources created.

Now login to AWS EC2 console, you would see the new instances up and running.

How to push Terraform files into GitHub
First create SSH keys and upload public keys into GitHub by executing below command:
This should generate both public and private keys. Now navigate to c:\users\your_username\.ssh folder and open key) file probably in notepad and copy the whole content of it and upload into GitHub. 

Create Remote repo in GitHub
Create a new repo with below name, make sure it is a private repo. Also do not click on initialize this repository with a README option.

 Note down the remote url as highlighted below:

All Terraform files should be checked into version control systems such as GitHub, BitBucket or GitLab. Let us see how to push code changes into GitHub. Make sure you are in the directory where Terraform files are created.

Initialize the directory first
Once you uploaded make sure you are in the directory where you had created tf files.
git init

The above command will create local git repository.
Now add terraform files.
git add *.tf

You need to setup your email address and user name.
git config --global ""

git config --global "your_userid"
git commit -m "added terraform files"
Copy the below green highligted url from above screenshots circled in red.
git remote add origin

Now push the code into GitHub
git push -u origin master

Now Login to GitHub to view the Terraform files

If you have any issues in uploading tf files, you may not have created ssh-keys and uploaded into GitHub. Create ssh keys using ssh-keygen command:
This should generate both public and private keys.
navigate to c:\users\your_username\.ssh folder and open key) file and copy the content of it and upload into GitHub. 

Monday, April 15, 2019

Install Sonarqube on Ubuntu - How to install SonarQube on Ubuntu 16.0.4 - How to setup Sonar on Ubuntu?

Please find steps for installing SonarQube on Ubuntu EC2. Make sure port 9000 is opened in security group(firewall rule).

SonarQube is java based tool along with back end - back end can be MySQL, Oracle or PostgreSQL. We will use Postgres for set up on Ubuntu.

Let us start with java install (skip java install if you already have it installed)

1. Java steps 

sudo apt-get update
sudo apt-get install default-jdk -y

Verify Java Version

java -version

openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.16.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

2. Postgres Installation

1. sudo sh -c 'echo "deb `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'

2. sudo wget -q -O - | sudo apt-key add -

3. sudo apt-get -y install postgresql postgresql-contrib

4. sudo systemctl start postgresql
5. sudo systemctl enable postgresql

Login as postgres user now
7. sudo su - postgres

8. Now create a user below
createuser sonar

9. Switch to sql shell by entering

Execute the below three lines (one by one)

ALTER USER sonar WITH ENCRYPTED password 'password';

type exit to come out of postgres user.

3. Now install SonarQube Web App

sudo wget

sudo apt-get -y install unzip
sudo unzip -d /opt

sudo mv /opt/sonarqube-6.4 /opt/sonarqube -v

Modify file
sudo vi /opt/sonarqube/conf/
uncomment the below lines by removing # and add values highlighted yellow

Next, uncomment the below line, removing #

Press escape, and enter :wq! to come out of the above screen.

Create Sonar as a service

Execute the below command:
sudo vi /etc/systemd/system/sonar.service

add the below code in green color:
Description=SonarQube service


inux-x86-64/ start
nux-x86-64/ stop



sudo systemctl enable sonar
sudo systemctl start sonar
sudo systemctl status sonar
type q now to come out of this mode.
Now execute the below command to see if Sonarqube is up and running. This may take a few minutes.

tail -f /opt/sonarqube/logs/sonar.log

Make sure you get the below message that says sonarqube is up..
Now access sonarQube UI by going to browser and enter public dns name with port 9000

Click here to learn how to integrate SonarQube with Jenkins.

Please watch above steps in myYouTube video as well:

Tuesday, April 9, 2019

Build Pipelines in Azure DevOps | How to build Azure Build pipelines to migrate Java WebApp to Azure Cloud

Building pipelines in Azure DevOps is really easy, you can migrate your web application code from any where into Azure Cloud by using Azure pipelines.

We are going to migrate Java Web App that was setup in Azure Git into Azure Cloud by creating a WebApp in Azure.


You need to create WebApp in Azure Cloud. WebApp is an App service (mostly Platform as a Service) provide by Azure Cloud to migrate any web applications.

Once you sign in to Azure Portal, you need to create an app service which is a WebApp.

Steps for Creating WebApp in Azure Portal

1. Now login to
2. Click on App services

3.Click on + Add or click on Create app service

Click on Web App.

Choose Free Azure subscription

Create a new resource group(for first time if you create an app service, otherwise you can use existing group name)
Enter App service name(it should be unique)
Publish as Code
Run time stack as Java 11 --> Tomcat9.0
Operating System as Linux
Region as South Central US
Enter LinuxPlan name
Choose SKU and size as given below:
Choose DEV/Test and use 1 GB memory

Click on Apply
Now click on Apply & Create
This will take bit time to create the app service.

Once WebApp is created, go resources, click on WebApp name and click on the URL.

You should see the app service home page some thing like below:

Since our WebApp is up and running, now we can start creating pipelines to migrate to Azure cloud.

2. Creating pipelines in Azure Devops

1. Now go to your visual studio project page -->
Select the Project dashboard you already created.

Click on Pipelines, Builds.

2. Click on New pipeline and click on use the classic editor to create a pipeline without YAML

3. Select source repository as Azure Repo Git and click continue

4. Since our application is Java stack, type Java and Choose Azure WebApp for Java

5. Click on pipeline name and re-name per your naming standard

6. Modify maven goal as clean install and also choose POM.xml by clicking on three dots ...

7. Leave the value as it is for Copy Files to staging folder

8. Leave the value as it is for Publish Artifact: Drop
9. Click on Stop Azure WebApp step, Enter Azure WebApp details - where  you would like to deploy your app in Azure. Select Free trial subscription from the drop down. Click on Authorize button.
Make sure you disable popup blocker.

10. Do the same in Deploy Azure WebApp & Start Azure WebApp steps.

Enable Webhooks in Pipeline

11. Click on Triggers and then enable check box for Continuous Integration

12. Now click on Save and Queue

13. If your configurations are correct, you should be able to see the build success and able to access in the Azure. Click on Pipelines and pipeline name

Now you will see that Azure DevOps would have started build.

14. Make sure build is success, it should have all green like below.

After successful build, you can check the output by accessing below URL:


Top 10 DevOps Popular Tools | Popular DevOps Tools You Must Know In 2024 | Learn DevOps Tools in 2024

Here are the top 10 DevOps Tools to focus on to put your DevOps learning on a  faster track  and kick start your career quickly as a success...