forked from oracle-terraform-modules/terraform-oci-oke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
78 lines (68 loc) · 1.88 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
78
pipeline {
agent any
parameters {
choice (name: 'ACTION',
choices: [ 'plan', 'apply', 'destroy'],
description: 'Run terraform plan / apply / destroy')
}
stages {
stage('Checkout') {
steps {
sh 'PATH=/usr/local/bin'
// sh 'terraform fmt'//
println 'Initiate Terraform provider'
sh 'terraform init' //only need for first run
// sh 'terraform refresh -lock=false'//
// sh 'cp terraform.tfvars .'//
sh 'ls'
}
}
stage('TF Plan') {
when { anyOf
{
environment name: 'ACTION', value: 'plan';
}
}
steps {
sh 'PATH=/usr/local/bin'
// sh 'terraform fmt'//
//sh 'terraform init' //only need for first run
// sh 'terraform refresh -lock=false'//
//sh 'cp vars.tf .'//
println 'List all files needed'
sh 'ls'
println 'Terraform plan oke'
sh 'terraform plan -lock=false -out oke_plan'
}
}
//stage('Approval') {
// steps {
// script {
// def userInput = input(id: 'confirm', message: 'Apply Terraform?', parameters: [ [$class: 'BooleanParameterDefinition', defaultValue: false, description: 'Apply terraform', name: 'confirm'] ])
// }
// }
//}
stage('TF Apply') {
when { anyOf
{
environment name: 'ACTION', value: 'apply'
}
}
steps {
println 'Apply the TF Infrastructure oke_plan'
sh 'terraform apply -lock=false -auto-approve oke_plan'
}
}
stage('TF Destroy') {
when { anyOf
{
environment name: 'ACTION', value: 'destroy';
}
}
steps {
println 'Destroy the TF Infrastructure'
sh 'terraform destroy -lock=false -auto-approve'
}
}
}
}