Skip to content

Commit aca8ff0

Browse files
committed
updated jenkins file
1 parent 1f380ca commit aca8ff0

File tree

2 files changed

+72
-38
lines changed

2 files changed

+72
-38
lines changed
Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,65 @@
1-
pipeline {
1+
2+
pipeline {
3+
24
parameters {
3-
string(defaultValue: 'vijaysnode', description: 'select node', name: 'node')
4-
}
5+
string(name: 'environment', defaultValue: 'terraform', description: 'Workspace/environment file to use for deployment')
6+
booleanParam(name: 'autoApprove', defaultValue: false, description: 'Automatically run apply after generating plan?')
57

6-
agent {
7-
node {
8-
label params.node
9-
}
10-
}
11-
stages{
12-
stage('terraform-Demo') {
13-
steps {
14-
script {
15-
dir("ta-setup")
16-
{
17-
git branch: 'tf-jenkins', url: 'https://github.com/easyawslearn/Terraform-Tutorial.git'
18-
sh 'cd EC2withJenkins '
19-
sh 'terraform init -upgrade=true -get=true -input=false -force-copy'
20-
sh 'terraform workspace new "terraform-demo"'
21-
sh 'echo "INFO: New terraform-demo workspace added."'
22-
sh 'terraform workspace select terraform-demo'
23-
sh 'echo "INFO: Terraform -> Planning..."'
24-
sh 'terraform plan -out plan_terraform -lock=true'
25-
sh 'echo "INFO: Terraform -> Executing..."'
26-
sh 'terraform apply plan_plan_terraform'
8+
}
9+
10+
11+
environment {
12+
AWS_ACCESS_KEY_ID = credentials('AWS_ACCESS_KEY_ID')
13+
AWS_SECRET_ACCESS_KEY = credentials('AWS_SECRET_ACCESS_KEY')
14+
}
15+
16+
agent any
17+
options {
18+
timestamps ()
19+
ansiColor('xterm')
20+
}
21+
stages {
22+
stage('checkout') {
23+
steps {
24+
script{
25+
dir("terraform")
26+
{
27+
git "https://github.com/easyawslearn/Terraform-Tutorial.git"
28+
}
2729
}
28-
}
2930
}
30-
}
31-
}
31+
}
32+
33+
stage('Plan') {
34+
steps {
35+
sh 'pwd;ls ; terraform init -input=false'
36+
// sh 'terraform workspace new ${environment}'
37+
sh 'terraform workspace select ${environment};pwd;ls'
38+
sh "pwd;cd terraform/aws-instance-first-script ;terraform plan -input=false -out tfplan ;pwd;ls"
39+
sh 'pwd;cd terraform/aws-instance-first-script ;terraform show -no-color tfplan > tfplan.txt'
40+
}
41+
}
42+
stage('Approval') {
43+
when {
44+
not {
45+
equals expected: true, actual: params.autoApprove
46+
}
47+
}
48+
49+
steps {
50+
script {
51+
def plan = readFile 'tfplan.txt'
52+
input message: "Do you want to apply the plan?",
53+
parameters: [text(name: 'Plan', description: 'Please review the plan', defaultValue: plan)]
54+
}
55+
}
3256
}
57+
58+
stage('Apply') {
59+
steps {
60+
sh "pwd;cd terraform/aws-instance-first-script ; terraform apply -input=false tfplan"
61+
}
62+
}
63+
}
64+
65+
}

terraform-aws-elb-alb/elb.tf

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ resource "aws_lb" "elb_example" {
1515
}
1616
}
1717

18+
resource "aws_lb_listener" "front_end" {
19+
load_balancer_arn = aws_lb.elb_example.arn
20+
port = "80"
21+
protocol = "HTTP"
22+
23+
default_action {
24+
type = "forward"
25+
target_group_arn = aws_lb_target_group.test.arn
26+
27+
}
28+
}
29+
1830
resource "aws_lb_target_group" "test" {
1931
name = "tf-example-lb-tg"
2032
port = 80
@@ -34,17 +46,6 @@ resource "aws_lb_target_group_attachment" "test1" {
3446
port = 80
3547
}
3648

37-
resource "aws_lb_listener" "front_end" {
38-
load_balancer_arn = aws_lb.elb_example.arn
39-
port = "80"
40-
protocol = "HTTP"
41-
42-
default_action {
43-
type = "forward"
44-
target_group_arn = aws_lb_target_group.test.arn
45-
46-
}
47-
}
4849

4950
output "elb_example" {
5051
description = "The DNS name of the ELB"

0 commit comments

Comments
 (0)