-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjenkinsfile
75 lines (70 loc) · 2.07 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
pipeline {
agent any
options {
ansiColor('xterm')
}
stages {
stage('AWS list') {
steps {
sh '''
aws configure list
'''
}
}
stage('Checkout repository') {
steps {
checkout scm
}
}
stage('Runs <terraform get>') {
steps {
sh '''
terraform get -update=true
'''
}
}
stage('Runs <terraform init>') {
steps {
sh '''
terraform init -backend=true -input=false -backend-config=./backend/backend-${ENV}.tfvars
'''
}
}
stage('Runs testing plan') {
steps {
sh '''
ls ./tfvars/
'''
}
}
stage('Runs <terraform plan>') {
steps {
script {
def plan = 'terraform plan -out=tfplan -input=false -var-file="./tfvars/poc-${ENV}.tfvars" '
if ("$TF_DESTROY" == "true") {
plan = plan + ' -destroy'
}
plan = plan + ' '
def planExitCode = sh(script: plan, returnStatus: true)
if (planExitCode == 1) {
error 'Error executing Terraform plan.'
}
}
}
}
stage('Asks approval for <terraform apply>') {
steps {
script {
def userInput = input(id: 'confirm', message: 'Apply Terraform?', parameters: [ [$class: 'BooleanParameterDefinition', defaultValue: false, description: 'Apply terraform', name: 'confirm'] ])
}
}
}
stage('Runs <terraform apply>') {
steps {
sh '''
terraform apply -lock=false -input=false tfplan
'''
}
}
}
}