Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
19dfae3
Update provider.tf
Rageshmookoth Apr 13, 2021
0df6d79
Update provider.tf
Rageshmookoth Apr 13, 2021
c907774
initial
Rageshmookoth Apr 13, 2021
fe5c612
ec2-build
Rageshmookoth Apr 13, 2021
2a301bb
upload
Rageshmookoth Apr 13, 2021
928e390
nameupdated
Rageshmookoth Apr 13, 2021
8311af8
fixed-error
Rageshmookoth Apr 13, 2021
3e388bb
Version-1
Rageshmookoth Apr 13, 2021
3c21a58
ec2-config.updated
Rageshmookoth Apr 13, 2021
dd5671e
updated version
Rageshmookoth Apr 13, 2021
23d1d62
deleted-output
Rageshmookoth Apr 13, 2021
ee4439c
updated-variable
Rageshmookoth Apr 13, 2021
8207d74
ec2-location-updated
Rageshmookoth Apr 13, 2021
e11997f
updated version
Rageshmookoth Apr 13, 2021
771b3f2
deleted vpc
Rageshmookoth Apr 14, 2021
b3cce8b
ec2-with-variable
Rageshmookoth Apr 14, 2021
3105fbf
provider-update
Rageshmookoth Apr 14, 2021
f067e4a
provider-removed
Rageshmookoth Apr 14, 2021
613e5f4
variable defined
Rageshmookoth Apr 14, 2021
1d77d7f
output-added
Rageshmookoth Apr 14, 2021
0d34678
output-file-corected
Rageshmookoth Apr 14, 2021
c761f5b
updated
Rageshmookoth Apr 14, 2021
feca3e6
updated-code
Rageshmookoth Apr 14, 2021
f2c66a1
updated
Rageshmookoth Apr 14, 2021
ad961fb
updated-correct-value
Rageshmookoth Apr 15, 2021
19d26a8
ami-changed
Rageshmookoth Apr 15, 2021
0358e85
us-east-ami-id update
Rageshmookoth Apr 15, 2021
9bcd107
AMI ID update as STD image
Rageshmookoth Apr 16, 2021
11b5b30
added AMI ID
Rageshmookoth May 1, 2021
a5c037e
updated size variable
Rageshmookoth May 1, 2021
a5893bc
delete output file
Rageshmookoth May 1, 2021
7d2add3
volume-size-removed
Rageshmookoth May 3, 2021
2c46c09
output-committed
Rageshmookoth May 6, 2021
ddf793d
ansibleupate
Rageshmookoth May 6, 2021
ea96c3b
removed provisioner
Rageshmookoth May 8, 2021
6822310
key-pair-name-updated
Rageshmookoth May 10, 2021
065b6d1
ansible-provisioner addeded
Rageshmookoth May 10, 2021
3af044e
ansibe provisioner update
Rageshmookoth May 10, 2021
69e904b
provisioner updated
Rageshmookoth May 10, 2021
961ed7b
apache installation steps updated
Rageshmookoth May 10, 2021
93d00af
ansible-update
Rageshmookoth May 10, 2021
8ae1bee
debug logging enabled
Rageshmookoth May 10, 2021
7d3581b
updated ansible command
Rageshmookoth May 10, 2021
c7348b5
ansible-updated
Rageshmookoth May 10, 2021
517fea3
inventory-file-created
Rageshmookoth May 10, 2021
10e1880
reference
Rageshmookoth May 10, 2021
1a2d65c
resources ec2
Rageshmookoth May 11, 2021
19443c1
output updated
Rageshmookoth May 11, 2021
6141336
upated outputfile
Rageshmookoth May 11, 2021
fd01d47
output version update
Rageshmookoth May 11, 2021
1f8f10d
Updated output
Rageshmookoth May 11, 2021
0ed9412
variable and output file updated
Rageshmookoth May 14, 2021
f173382
output
Rageshmookoth May 14, 2021
c128f90
variable updated
Rageshmookoth May 14, 2021
00698a5
public ip redirection updated
Rageshmookoth May 14, 2021
c19d18b
sleep implemented
Rageshmookoth May 14, 2021
94c3486
output variable name updated
Rageshmookoth May 14, 2021
771cd30
resource-updated
Rageshmookoth May 14, 2021
a776ca9
resources
Rageshmookoth May 14, 2021
6127f2a
resource
Rageshmookoth May 14, 2021
e57130a
resource dependency added
Rageshmookoth May 14, 2021
f60da72
inventoryfile updated
Rageshmookoth May 14, 2021
eea1524
jenkins-file-updated
Rageshmookoth May 14, 2021
3c2e6db
jenkins-pipeline
Rageshmookoth May 15, 2021
415ed97
jenkins-files update
Rageshmookoth May 30, 2021
fa79ce2
Tag info updated
Rageshmookoth May 30, 2021
c052d47
variable 9pdated
Rageshmookoth May 30, 2021
f11d210
resources file updated
Rageshmookoth May 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions Jenkins-file
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
pipeline {
agent any
tools {
terraform 'terraform-Rag'
}
parameters {
//string(name: 'environment', defaultValue: 'default', description: 'Workspace/environment file to use for deployment')
//string(name: 'version', defaultValue: '', description: 'Version variable to pass to Terraform')
//choice choices: ['AWS', 'AZURE', 'OracleCloud'], description: '''Select the cloud platform
//''', name: 'Cloud'
choice choices: ['us-west-1', 'ap-south-1', 'eu-central-1'], description: '''Select the region
''', name: 'Region'
choice choices: ['Ragesh', 'Moiz'], description: '''Server owner
''', name: 'Owner'
choice choices: ['DEV-GROUP', 'IT-GROUP'], description: '''Server Group
''', name: 'Group'
string defaultValue: '', description: 'Project', name: 'Project', trim: false
choice choices: ['t2.micro', 't2.small', 't2.medium'], description: '''Select the appropriate instance type.
For more information
https://aws.amazon.com/ec2/instance-types/
''', name: 'Configuration'
string defaultValue: '', description: 'Input server Name', name: 'ServerName', trim: false

booleanParam(name: 'autoApprove', defaultValue: false, description: 'Automatically run apply after generating plan?')
}

environment {
AWS_ACCESS_KEY_ID = credentials('AWS-ACCESS-KEY-ID')
AWS_SECRET_ACCESS_KEY = credentials('AWS-SECRET-KEY')
TF_IN_AUTOMATION = '1'
}

stages {
stage('Git Checkout'){
steps{
git credentialsId: 'GITHUB-RAGEH', url: 'https://github.com/Rageshmookoth/iac-demo'
}
}
stage('Plan') {
steps {
//script {
// currentBuild.displayName = params.version
//}
sh 'terraform init -input=false'
//sh 'terraform workspace select ${environment}'
sh "terraform plan -input=false -out tfplan -var 'region=${params.Region}' -var 'instance_type=${params.Configuration}' -var 'instance_name=${params.ServerName}' -var 'Group=${params.Group}' -var 'Owner=${params.Owner}' -var 'Project=${params.Project}'"
sh 'terraform show -no-color tfplan > tfplan.txt'
}
}

stage('Approval') {
when {
not {
equals expected: true, actual: params.autoApprove
}
}

steps {
script {
def plan = readFile 'tfplan.txt'
input message: "Do you want to apply the plan?",
parameters: [text(name: 'Plan', description: 'Please review the plan', defaultValue: plan)]
}
}
}

stage('Apply') {
steps {
sh "terraform apply -input=false tfplan"
}
}
stage('Remove State file') {
steps {
sh "rm -fr terraform.tfstate"
}
}


}
post {
success {
mail to: 'rageshmoorkoth@gmail.com',
subject: "Server build completed",
body: "Server name ${params.ServerName}"
}
}
}
1 change: 1 addition & 0 deletions inventory.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${web_public_ip}
91 changes: 91 additions & 0 deletions jenkins-configuration
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
pipeline {
agent any
tools {
terraform 'terraform-Rag'
}
parameters {
//string(name: 'environment', defaultValue: 'default', description: 'Workspace/environment file to use for deployment')
//string(name: 'version', defaultValue: '', description: 'Version variable to pass to Terraform')
//choice choices: ['Oracle Linux', 'Microsoft Windows'], description: '''Select the Operating System
//''', name: 'OS'
choice choices: ['us-west-1', 'ap-south-1', 'eu-central-1'], description: '''Select the region
''', name: 'Region'
choice choices: ['Ragesh', 'Moiz','Sourabh'], description: '''Server owner
''', name: 'Owner'
choice choices: ['t2.micro', 't2.small', 't2.medium'], description: '''Select the appropriate instance type.
For more information
https://aws.amazon.com/ec2/instance-types/
''', name: 'Configuration'
string defaultValue: '', description: 'Input server Name', name: 'ServerName', trim: false

booleanParam(name: 'autoApprove', defaultValue: false, description: 'Automatically run apply after generating plan?')
}

environment {
AWS_ACCESS_KEY_ID = credentials('AWS-ACCESS-KEY-ID')
AWS_SECRET_ACCESS_KEY = credentials('AWS-SECRET-KEY')
TF_IN_AUTOMATION = '1'
}
stages {
stage('Git Checkout'){
steps{
git credentialsId: 'GITHUB-RAGEH', url: 'https://github.com/Rageshmookoth/iac-demo'
}
}
stage('OS Image select'){

steps{

}

}

stage('Plan') {
steps {
//script {
// currentBuild.displayName = params.version
//}
sh 'terraform init -input=false'
//sh 'terraform workspace select ${environment}'
sh "terraform plan -input=false -out tfplan -var 'region=${params.Region}' -var 'instance_type=${params.Configuration}' -var 'instance_name=${params.ServerName}'"
sh 'terraform show -no-color tfplan > tfplan.txt'
}
}

stage('Approval') {
when {
not {
equals expected: true, actual: params.autoApprove
}
}

steps {
script {
def plan = readFile 'tfplan.txt'
input message: "Do you want to apply the plan?",
parameters: [text(name: 'Plan', description: 'Please review the plan', defaultValue: plan)]
}
}
}

stage('Apply') {
steps {
sh "terraform apply -input=false tfplan"
}
}
stage('Remove State file') {
steps {
sh "rm -fr terraform.tfstate"
}
}


}
post {
success {
mail to: 'rageshmoorkoth@gmail.com',
subject: "Server build completed",
body: "Server name ${params.ServerName}"
}
}
}
11 changes: 11 additions & 0 deletions output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
output "ip" {
value = "${aws_instance.Ragesh.public_ip}"
}
resource "local_file" "ansible_inventory_hosts" {
content = templatefile("inventory.template",
{
web_public_ip = aws_instance.Ragesh.public_ip,
}
)
filename = "inventory"
}
13 changes: 13 additions & 0 deletions playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- hosts: all
become: yes
become_user: root
become_method: sudo
tasks:
- name: Install httpd
yum:
name: httpd
state: latest
- name: Restart httpd
service: name=httpd state=restarted
become: yes
4 changes: 2 additions & 2 deletions provider.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
provider "aws" {
region = "ap-south-1"
}
region = var.region
}
42 changes: 42 additions & 0 deletions resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
resource "aws_instance" "Ragesh" {
ami = var.ami
instance_type = var.instance_type
key_name = "POC-STD-KEY-PAIR"
tags = {
Name = var.instance_name
Owner = var.Owner
Group = var.Group
Project = var.Project
}
}
#resource "null_resource" "step1" {
#provisioner "local-exec" {
# command = "echo ${aws_instance.Ragesh.public_ip}"
# }
#}
resource "null_resource" "wait" {
depends_on = [
aws_instance.Ragesh,
# null_resource.step1,
# null_resource.wait,
]
provisioner "local-exec" {
command = "sleep 180"
}
}
resource "null_resource" "Ansible-play" {
depends_on = [
null_resource.wait,
]
# using ansible, declarative approach of configuration management
provisioner "local-exec" {
command ="ansible-playbook -i inventory playbook.yml --private-key=${var.private_key} --user ${var.ansible_user}"
}
}





### https://a4ank.medium.com/aws-terraform-ansible-end-to-end-automation-9072f2ecf624
####https://medium.com/on-the-cloud/one-click-environment-creation-with-terraform-ansible-in-under-10-6e8d9284f60
52 changes: 52 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#------------------------------------------------------------------------------
# Misc
#------------------------------------------------------------------------------
variable "instance_name" {
description = "Name prefix for resources on AWS"
type = string
default = "test-instance"
}

#------------------------------------------------------------------------------
# AWS CREDENTIALS AND REGION
#------------------------------------------------------------------------------
variable "instance_type" {
description = "AWS EC2 instance type"
default = "t2.micro"
}
variable "region" {
description = "AWS Region the infrastructure is hosted in"
default = "us-east-1"
}
variable "ami" {
description = "AMI Image"
default = "ami-045e6fa7127ab1ac4"
}
variable "cloudprovider" {
description = "Select the Cloud Provider"
default = "AWS"
}
variable "size" {
description = "Provide size"
default = "100"
}
variable "Owner" {
description = "Owner name"
default = "Ragesh"
}
variable "private_key" {
default = "POC-STD-KEY-PAIR.pem"
}
variable "ansible_user" {
default = "ec2-user"
}
variable "Group" {
description = "Group Tag"
type = string
default = "No-Group"
}
variable "Project" {
description = "Project name Tag"
type = string
default = "No-Project"
}
9 changes: 0 additions & 9 deletions vpc.tf

This file was deleted.