-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
77 lines (71 loc) · 2.14 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
pipeline {
agent {
node {
label "master"
}
}
parameters {
choice(
choices: ['Apply' , 'Destroy'],
description: 'Do you like to execute "apply" or "destroy" terraform?',
name: 'REQUESTED_ACTION')
}
stages {
stage('fetch_latest_code') {
steps {
git url: 'https://github.com/Omidznlp/Terraform-Jenkins.git'
}
}
stage('TF Init&Plan') {
when {
expression { params.REQUESTED_ACTION == 'Apply' }
}
steps {
withAWS(credentials: 'terraform-credentials') {
sh 'terraform -chdir=terraform init'
sh 'terraform -chdir=terraform plan'
}
}
}
stage('Approval') {
when {
expression { params.REQUESTED_ACTION == 'Apply' }
}
steps {
script {
def userInput = input(id: 'confirm', message: 'Apply Terraform?', parameters: [ [$class: 'BooleanParameterDefinition', defaultValue: false, description: 'Apply terraform', name: 'confirm'] ])
}
}
}
stage('TF Apply') {
when {
expression { params.REQUESTED_ACTION == 'Apply' }
}
steps {
withAWS(credentials: 'terraform-credentials') {
sh 'terraform -chdir=terraform apply -input=false --auto-approve'
}
}
}
stage('Removal') {
when {
expression { params.REQUESTED_ACTION == 'Destroy' }
}
steps {
script {
def userInput = input(id: 'confirm', message: 'Destroy Terraform?', parameters: [ [$class: 'BooleanParameterDefinition', defaultValue: false, description: 'Destroy terraform', name: 'confirm'] ])
}
}
}
stage('TF Destroy') {
when {
expression { params.REQUESTED_ACTION == 'Destroy' }
}
steps {
withAWS(credentials: 'terraform-credentials') {
sh 'terraform -chdir=terraform destroy -input=false --auto-approve'
}
}
}
}
}