A Terraform module that throws an error at plan time if an arbitrary assertion fails.
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.
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:
Error: failed to execute "/bin/sh": jq: error (at <stdin>:0): Your assertion is not valid
on main.tf line 1, in data "external" "this":
1: data "external" "this" {
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.
Name | Version |
---|---|
terraform | >= 0.12.28 |
external | >= 2.2.0 |
Name | Version |
---|---|
external | 2.2.2 |
No modules.
Name | Type |
---|---|
external_external.this | data source |
Name | Description | Type | Default | Required |
---|---|---|---|---|
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 | Error message to return if the assertion fails | string |
"Assertion failed" |
no |
python_program | Python executable to call errorcheck with | string |
"python" |
no |
use_jq | Use jq to check for truthiness. Defaults to python | bool |
false |
no |
Name | Description |
---|---|
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 | Error message to return if the assertion fails |
result | Result of data source |
use_jq | Use jq to check for truthiness. Defaults to python |