-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
54 lines (50 loc) · 1.93 KB
/
Jenkinsfile
File metadata and controls
54 lines (50 loc) · 1.93 KB
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
pipeline {
agent any
parameters {
choice(
name: 'REGION',
choices: "us-east-2\nus-west-2",
description: 'SSM Region' )
}
environment {
SECRET_ACCESS_KEY = '$(aws ssm get-parameters --region $REGION --names /jenkins/nonprod/iam-role-secret --query Parameters[0].Value --with-decryption | sed \'s/"//g\')'
ACCESS_KEY_ID = '$(aws ssm get-parameters --region $REGION --names /jenkins/nonprod/iam-role-key --query Parameters[0].Value --with-decryption | sed \'s/"//g\')'
}
stages {
stage ('Create VPC & Packerize') {
steps {
dir('terraform'){
sh """
export AWS_SECRET_ACCESS_KEY=${env.SECRET_ACCESS_KEY}
export AWS_ACCESS_KEY_ID=${env.ACCESS_KEY_ID}
export AWS_DEFAULT_REGION=${REGION}
/opt/bin/terraform --version
/opt/bin/terraform init
/opt/bin/terraform plan --out=plan.out
export VPC_ID=$(terraform output vpc_id)
export VPC_PUBLIC_SUBNET_1=$(terraform output vpc_public_subnet_1)
export SG_WEB_DMZ=$(terraform output sg_web_dmz)
/opt/bin/packer build ../packer-cis.json
"""
}
}
}
stage ('Delete VPC') {
steps {
dir ('terraform') {
sh """
export AWS_SECRET_ACCESS_KEY=${env.SECRET_ACCESS_KEY}
export AWS_ACCESS_KEY_ID=${env.ACCESS_KEY_ID}
export AWS_DEFAULT_REGION=${REGION}
/opt/bin/terraform destroy --force
"""
}
}
}
stage ('Test') {
steps {
sh 'echo "Add test scripts for AMI and VPC deletion here."'
}
}
}
}