https://github.com/rhythmictech/terraform-terraform-errorcheck
Use the `external` module to implement custom error checking at plan time
https://github.com/rhythmictech/terraform-terraform-errorcheck
Last synced: 3 months ago
JSON representation
Use the `external` module to implement custom error checking at plan time
- Host: GitHub
- URL: https://github.com/rhythmictech/terraform-terraform-errorcheck
- Owner: rhythmictech
- License: mit
- Created: 2020-09-22T15:59:46.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-06-10T16:21:12.000Z (over 3 years ago)
- Last Synced: 2025-02-25T22:46:16.527Z (12 months ago)
- Language: HCL
- Size: 36.1 KB
- Stars: 8
- Watchers: 4
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# terraform-terraform-errorcheck
A Terraform module that throws an error at plan time if an arbitrary assertion fails.
[](https://github.com/rhythmictech/terraform-terraform-errorcheck/actions/workflows/test.yaml)
[](https://github.com/rhythmictech/terraform-terraform-errorcheck/actions?query=workflow%3Atflint+event%3Apush+branch%3Amaster)
[](https://github.com/rhythmictech/terraform-terraform-errorcheck/actions?query=workflow%3Atfsec+event%3Apush+branch%3Amaster)
[](https://github.com/rhythmictech/terraform-terraform-errorcheck/actions?query=workflow%3Ayamllint+event%3Apush+branch%3Amaster)
[](https://github.com/rhythmictech/terraform-terraform-errorcheck/actions?query=workflow%3Amisspell+event%3Apush+branch%3Amaster)
[](https://github.com/rhythmictech/terraform-terraform-errorcheck/actions?query=workflow%3Apre-commit-check+event%3Apush+branch%3Amaster)

## Example
Here's what using the module will look like
The `errorcheck_valid` module will pass, but the `errorcheck_invalid` module will fail, aborting the plan.
```hcl
locals {
compare = "success"
testSuccess = "success"
testFail = "fail"
}
module "errorcheck_valid" {
source = "rhythmictech/errorcheck/terraform"
version = "~> 1.0.0"
assert = local.compare == local.testSuccess
error_message = "Your assertion is not valid"
}
module "errorcheck_invalid" {
source = "rhythmictech/errorcheck/terraform"
version = "~> 1.0.0"
assert = local.compare == local.testFail
error_message = "Your assertion is not valid"
}
```
Output:
```bash
Error: failed to execute "/bin/sh": jq: error (at :0): Your assertion is not valid
on main.tf line 1, in data "external" "this":
1: data "external" "this" {
```
## About
This module exists because Terraform's native ability to throw errors at plan time is extremely limited if your provider doesn't do plan-time validation. Using this module you can use any arbitrary assertion to do plan-time validation. Our particular use-case was making sure the targeted environment matches the workspace.
## Requirements
| Name | Version |
|------|---------|
| [terraform](#requirement\_terraform) | >= 0.12.28 |
| [external](#requirement\_external) | >= 2.2.0 |
## Providers
| Name | Version |
|------|---------|
| [external](#provider\_external) | 2.2.2 |
## Modules
No modules.
## Resources
| Name | Type |
|------|------|
| [external_external.this](https://registry.terraform.io/providers/hashicorp/external/latest/docs/data-sources/external) | data source |
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| [assert](#input\_assert) | Make your assertion here so that it resolves to a boolean value. If this value is false, the module will throw an error. | `bool` | n/a | yes |
| [error\_message](#input\_error\_message) | Error message to return if the assertion fails | `string` | `"Assertion failed"` | no |
| [python\_program](#input\_python\_program) | Python executable to call errorcheck with | `string` | `"python"` | no |
| [use\_jq](#input\_use\_jq) | Use jq to check for truthiness. Defaults to python | `bool` | `false` | no |
## Outputs
| Name | Description |
|------|-------------|
| [asset](#output\_asset) | Make your assertion here so that it resolves to a boolean value. If this value is false, the module will throw an error. |
| [error\_message](#output\_error\_message) | Error message to return if the assertion fails |
| [result](#output\_result) | Result of data source |
| [use\_jq](#output\_use\_jq) | Use jq to check for truthiness. Defaults to python |
## The Giants Underneath this Module
- [pre-commit.com](pre-commit.com)
- [terraform.io](terraform.io)
- [github.com/tfutils/tfenv](github.com/tfutils/tfenv)
- [github.com/segmentio/terraform-docs](github.com/segmentio/terraform-docs)