Last active
December 17, 2018 16:31
-
-
Save GuyBarros/4ce89506368ce3b8edeb8ca2fafa7713 to your computer and use it in GitHub Desktop.
Jenkins TFE integration via remote backend example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pipeline { | |
agent any | |
environment { | |
GIT_REPO = "https://github.com/GuyBarros/terraform-aws-demostack/" | |
TFE_URL = "https://app.terraform.io" | |
TFE_ORGANIZATION = "emea-se-playground" | |
TFE_API_URL = "${TFE_URL}/api/v2" | |
TFE_API_TOKEN = credentials("tfe_api_token") | |
} | |
stages { | |
stage('Preparation') { | |
steps { | |
git "${GIT_REPO}" | |
sh "ls" | |
sh ''' | |
curl -o tf.zip https://releases.hashicorp.com/terraform/0.11.11/terraform_0.11.11_linux_amd64.zip ; yes | unzip tf.zip | |
./terraform version | |
''' | |
} | |
} | |
stage('TFE Workstation list ') { | |
steps { | |
sh ''' | |
curl \ | |
--silent --show-error --fail \ | |
--header "Authorization: Bearer $TFE_API_TOKEN" \ | |
--header "Content-Type: application/vnd.api+json" \ | |
${TFE_API_URL}/organizations/${TFE_ORGANIZATION}/workspaces \ | |
| jq -r \'.data[] | .attributes.name\' | |
''' | |
} | |
} | |
stage('Terraform Init') { | |
steps { | |
sh "echo ${TFE_API_TOKEN}" | |
sh "sed -i 's/TFE_API_TOKEN/${TFE_API_TOKEN}/' main.tf" | |
sh "cat main.tf" | |
sh "./terraform init" | |
} | |
} | |
stage('Terraform Plan') { | |
steps { | |
sh "./terraform plan" | |
} | |
} | |
stage('Terraform Apply') { | |
steps { | |
sh "./terraform apply -auto-approve" | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment