82 lines
1.7 KiB
Groovy
82 lines
1.7 KiB
Groovy
pipeline {
|
|
agent any
|
|
|
|
environment {
|
|
AWS_ACCESS_KEY_ID = credentials('aws-access-key-id') // JenkinsのCredentialで設定したキー
|
|
AWS_SECRET_ACCESS_KEY = credentials('aws-secret-access-key') // 同じくCredentialで設定したシークレットキー
|
|
}
|
|
|
|
options {
|
|
skipDefaultCheckout(true)
|
|
}
|
|
tools {
|
|
terraform "Terraform-1.9.5"
|
|
}
|
|
stages{
|
|
stage("checkout") {
|
|
when {
|
|
expression {
|
|
return stats.toBoolean()
|
|
}
|
|
}
|
|
steps {
|
|
// Iacコードを取得
|
|
checkout scm
|
|
}
|
|
}
|
|
stage("terraform init") {
|
|
when {
|
|
expression {
|
|
return stats.toBoolean()
|
|
}
|
|
}
|
|
steps {
|
|
// 初期化
|
|
dir('demo2'){
|
|
sh "terraform init -no-color"
|
|
}
|
|
}
|
|
}
|
|
stage("terraform plan") {
|
|
when {
|
|
expression {
|
|
return stats.toBoolean()
|
|
}
|
|
}
|
|
steps {
|
|
// 実行計画
|
|
dir('demo2'){
|
|
sh "terraform plan -no-color -out=plan.out"
|
|
}
|
|
}
|
|
}
|
|
stage("terraform apply") {
|
|
when {
|
|
expression {
|
|
return stats.toBoolean()
|
|
}
|
|
}
|
|
steps {
|
|
// 実行
|
|
dir('demo2'){
|
|
sh "terraform apply plan.out -no-color"
|
|
}
|
|
}
|
|
}
|
|
stage("terraform destroy") {
|
|
when {
|
|
expression {
|
|
return !stats.toBoolean()
|
|
}
|
|
}
|
|
steps {
|
|
// 実行
|
|
dir('demo2'){
|
|
sh "terraform destroy -auto-approve -no-color"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|