A Bitbucket Pipe to generate markdown summaries of Terraform plan files from your CI pipeline.
Add the following step to your bitbucket-pipelines.yml
:
- pipe: space48/bitbucket-pipe-summarise-tf-plan:latest
variables:
INPUT_FILES: "*.tfplan.json"
OUTPUT_FILE: "terraform-summary.md"
Variable | Required | Description |
---|---|---|
INPUT_FILES | Yes | Glob pattern to match Terraform plan JSON files |
OUTPUT_FILE | Yes | Path to output markdown file containing the summary |
TEMPLATE | No | A Markdown template string to inject the plan summaries into. Use a {{PLAN_SUMMARY}} keyword where the summaries should be injected. |
Generate a summary of all Terraform plan files in the current directory:
- pipe: space48/bitbucket-pipe-summarise-tf-plan:latest
variables:
INPUT_FILES: "*.tfplan.json"
OUTPUT_FILE: "terraform-summary.md"
Process multiple plan files from different directories and generate a comprehensive summary using a template:
- pipe: space48/bitbucket-pipe-summarise-tf-plan:latest
variables:
INPUT_FILES: "**/*.tfplan.json"
OUTPUT_FILE: "infra-changes.md"
TEMPLATE: |
# Build preview
This is a summary of infrastructure changes Terraform will make on the affected stacks:
---
{{PLAN_SUMMARY}}
---
See the [build log](https://example.com/path/to/build) for more details.
Combine with the PR comment pipe to post Terraform summaries directly to pull requests:
- pipe: space48/bitbucket-pipe-summarise-tf-plan:latest
variables:
INPUT_FILES: "*.tfplan.json"
OUTPUT_FILE: "terraform-summary.md"
- pipe: space48/bitbucket-pipe-pr-comment:latest
variables:
BITBUCKET_USERNAME: $BITBUCKET_USERNAME
BITBUCKET_APP_PASSWORD: $BITBUCKET_APP_PASSWORD
CONTENT_FILE: "terraform-summary.md"
COMMENT_IDENTIFIER: terraform-plan-summary
The pipe generates markdown summaries with the following structure:
## Summary of plan.tfplan.json
**Terraform plan: 2 to create, 1 to update, 0 to delete**
### Resources to create:
aws_instance.web_server
aws_security_group.web_sg
### Resources to update:
aws_s3_bucket.storage
Terraform plan files must be in JSON format. Generate JSON plan files using:
terraform plan -out=plan.tfplan && terraform show -json plan.tfplan > plan.tfplan.json
MIT licensed, see LICENSE.txt for more details.
For more information, see the pipe.yml metadata file and the Bitbucket Pipes documentation.