This project contains some useful hooks for https://pre-commit.com.
The terraform_inputs_jenkins_pipeline_params
hook supports the definition of a Declarative Jenkins Pipeline's parameters from your Terraform Input Variables.
Note:
- Requires segmentio/terraform-docs >= v0.4.0.
- Requires terraform-docs12
repos:
- repo: git://github.com/getcloudnative/pre-commit-hooks
rev: v1.2.0
hooks:
- id: terraform_inputs_jenkins_pipeline_params
The terraform_inputs_jenkins_pipeline_params
hook places the Jenkins Pipeline parameters inside the following BEGINNING OF … HOOK
and END OF … HOOK
placeholders in your project's Jenkinsfile
:
pipeline {
agent any
parameters {
string(name: 'AWS_ACCESS_KEY_ID', description: 'The AWS Access Key ID to use.')
string(name: 'AWS_SECRET_ACCESS_KEY', description: 'The AWS Secret Access Key to use.')
string(name: 'AWS_DEFAULT_REGION', description: 'The AWS Region to use for deployment.')
// BEGINNING OF JENKINS-PIPELINE-PARAMS-FROM-TERRAFORM-INPUT-VARS PRE-COMMIT HOOK
// END OF JENKINS-PIPELINE-PARAMS-FROM-TERRAFORM-INPUT-VARS PRE-COMMIT HOOK
}
...
}
The terraform_inputs_jenkins_pipeline_params
hook supports the creation of a terraform.tfvars.json based on your Terraform Input Variables, with values provided by the Jenkins Pipeline parameters' arguments.
Note: Requires segmentio/terraform-docs >= v0.4.0.
repos:
- repo: git://github.com/getcloudnative/pre-commit-hooks
rev: v1.2.0
hooks:
- id: terraform_inputs_jenkins_pipeline_params
The terraform_inputs_jenkins_pipeline_params
hook places the Jenkins Pipeline parameters inside the following BEGINNING OF … HOOK
and END OF … HOOK
placeholders in your project's Jenkinsfile
:
pipeline {
agent any
parameters {
...
}
stages {
stage('Init') {
steps {
echo "Create the stack's terraform.tfvars.json."
script {
// BEGINNING OF JENKINS-PIPELINE-PARAMS-TO-TERRAFORM-TFVARS-JSON PRE-COMMIT HOOK
// END OF JENKINS-PIPELINE-PARAMS-TO-TERRAFORM-TFVARS-JSON PRE-COMMIT HOOK
}
}
}
}
}
You can test the behavior of the terraform_inputs_jenkins_pipeline_params
hook by executing the following commands, where TERRAFORM_MODULE_PATH
is either a path to a Terraform module directory, or contains a sequence of files containing Terraform variable
definitions. The results can then be seen in the project's Jenkinsfile
.
git clone https://github.com/getcloudnative/pre-commit-hooks-terraform.git
pre-commit try-repo ./pre-commit-hooks-terraform terraform_inputs_jenkins_pipeline_params --files $TERRAFORM_MODULE_PATH