├── .gitignore ├── Jenkinsfile ├── LICENSE.md ├── README.md ├── main.tf ├── terraformw └── version.tf /.gitignore: -------------------------------------------------------------------------------- 1 | install.sh 2 | .bin/ -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent { label 'linux'} 3 | options { 4 | skipDefaultCheckout(true) 5 | } 6 | stages{ 7 | stage('clean workspace') { 8 | steps { 9 | cleanWs() 10 | } 11 | } 12 | stage('checkout') { 13 | steps { 14 | checkout scm 15 | } 16 | } 17 | stage('terraform') { 18 | steps { 19 | sh './terraformw apply -auto-approve -no-color' 20 | } 21 | } 22 | } 23 | post { 24 | always { 25 | cleanWs() 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Darin Pope 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jenkins-example-terraform -------------------------------------------------------------------------------- /main.tf: -------------------------------------------------------------------------------- 1 | output "jenkins_terraform" { 2 | value = "running Terraform from Jenkins" 3 | } -------------------------------------------------------------------------------- /terraformw: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # based on https://tfswitch.warrensbox.com/Continuous-Integration/ 4 | 5 | echo "Installing tfswitch locally" 6 | 7 | # Get the installer on to your machine 8 | wget -N -c https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh 9 | 10 | # Make installer executable 11 | chmod 755 install.sh 12 | 13 | # Install tfswitch in a location you have permission 14 | ./install.sh -b $(pwd)/.bin 15 | 16 | # set custom bin path 17 | CUSTOMBIN=$(pwd)/.bin 18 | 19 | #Add custom bin path to PATH environment 20 | export PATH=$CUSTOMBIN:$PATH 21 | 22 | $CUSTOMBIN/tfswitch -b $CUSTOMBIN/terraform 23 | 24 | terraform $* -------------------------------------------------------------------------------- /version.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = "1.0.0" 3 | } --------------------------------------------------------------------------------