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