From 81eb6d72e48c22cf0ab9c88344e88faf978c7477 Mon Sep 17 00:00:00 2001 From: Kyle Kotowick Date: Fri, 30 Jul 2021 12:21:59 -0400 Subject: [PATCH] Switch method to not use external data source --- README.md | 4 ++-- main.tf | 7 ++----- outputs.tf | 3 +-- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d333bce..3864de3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Terraform Assertion A simple module that asserts that a condition is true. The assertion is checked during planning, unless the condition depends on a value that will only be known during apply. -The module forces Terraform to fail if the condition is false by attempting to call a non-existant external command. It uses the error message in the command name so that the resulting Terraform failure message is descriptive (although it is slightly confusing in the format; see the example below). +The module forces Terraform to fail if the condition is false by providing an invalid input to a Terraform function. It uses the error message in the invalid input so that the resulting Terraform failure message is descriptive (although it is slightly confusing in the format; see the example below). ## Usage ``` @@ -24,5 +24,5 @@ No changes. Your infrastructure matches the configuration. Output on Windows machines: ``` -Error: can't find external program "ERROR: This Terraform configuration can only be run on Unix-based machines." +Invalid value for "number" parameter: cannot parse "ERROR: This Terraform configuration can only be run on Unix-based machines." as a base 2 integer. ``` diff --git a/main.tf b/main.tf index 1298a95..c769a5a 100644 --- a/main.tf +++ b/main.tf @@ -2,9 +2,6 @@ terraform { required_version = ">= 0.13.0" } -// Terraform has no built-in customizable error system, so instead we try to run a non-existant program with the error message in the name. -// It's not pretty, but it works. -data "external" "assertion" { - count = var.condition ? 0 : 1 - program = ["ERROR: ${var.error_message}"] +locals { + content = var.condition ? "" : parseint("ERROR: ${var.error_message}", 2) } diff --git a/outputs.tf b/outputs.tf index 3027681..013c901 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,5 +1,4 @@ output "checked" { description = "Whether the condition has been checked (used for assertion dependencies)." - depends_on = [data.external.assertion] - value = true + value = local.content == "" ? true : true }