forked from AmanPathak-DevOps/EKS-Terraform-GitHub-Actions
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
59 lines (58 loc) · 1.99 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
properties([
parameters([
string(
defaultValue: 'dev',
name: 'Environment'
),
choice(
choices: ['plan', 'apply', 'destroy'],
name: 'Terraform_Action'
)])
])
pipeline {
agent any
stages {
stage('Preparing') {
steps {
cleanWs()
sh 'echo Preparing'
}
}
stage('Git Pulling') {
steps {
git branch: 'master', url: 'https://github.com/devopsenggr/EKS-Terraform-GitHub-Actions.git'
}
}
stage('Init') {
steps {
withAWS(credentials: 'aws-creds', region: 'us-east-1') {
sh 'terraform -chdir=eks/ init -lock=false'
} //install aws pipeline steps plugin
}
}
stage('Validate') {
steps {
withAWS(credentials: 'aws-creds', region: 'us-east-1') {
sh 'terraform -chdir=eks/ validate'
}
}
}
stage('Action') {
steps {
withAWS(credentials: 'aws-creds', region: 'us-east-1') {
script {
if (params.Terraform_Action == 'plan') {
sh "terraform -chdir=eks/ plan -var-file=${params.Environment}.tfvars"
} else if (params.Terraform_Action == 'apply') {
sh "terraform -chdir=eks/ apply -var-file=${params.Environment}.tfvars -auto-approve -lock=false"
} else if (params.Terraform_Action == 'destroy') {
sh "terraform -chdir=eks/ destroy -var-file=${params.Environment}.tfvars -auto-approve -lock=false"
} else {
error "Invalid value for Terraform_Action: ${params.Terraform_Action}"
}
}
}
}
}
}
}