Last active
December 8, 2022 14:15
-
-
Save GuyBarros/c0e7f618ff7c0434b11f8ad3ac627926 to your computer and use it in GitHub Desktop.
Jenkins pipeline config for TFE Demos
This file contains hidden or 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-azurerm-demostack" | |
TFE_NAME = "app.terraform.io" | |
TFE_URL = "https://app.terraform.io" | |
TFE_ORGANIZATION = "emea-se-playground-2019" | |
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('TFE Set-up') { | |
steps{ | |
sh ''' | |
tee ~/.terraformrc > /dev/null <<EOF | |
credentials "${TFE_NAME}" { | |
token = "${TFE_API_TOKEN}" | |
} | |
EOF | |
''' | |
} | |
} | |
stage('Terraform Init') { | |
steps { | |
sh "cat ~/.terraformrc" | |
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