diff --git a/.changes/unreleased/v0.14.0.md b/.changes/v0.14.0.md similarity index 54% rename from .changes/unreleased/v0.14.0.md rename to .changes/v0.14.0.md index 647e508..cae8ec2 100644 --- a/.changes/unreleased/v0.14.0.md +++ b/.changes/v0.14.0.md @@ -3,6 +3,8 @@ ENHANCEMENTS: * Upgrade to Go 1.23.0 ([#66](https://github.com/hashicorp/terraform-provider-assert/issues/66)) +* Added descriptions to each function in the documentation ([#69](https://github.com/hashicorp/terraform-provider-assert/issues/69)) +* Consolidated the IP Address and CIDR Function sections into a single Network Functions category in the registry. ([#69](https://github.com/hashicorp/terraform-provider-assert/issues/69)) BUG FIXES: diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29..532391d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1,18 @@ +## v0.15.0 (September 25, 2024) + +## v0.14.0 (September 25, 2024) + +ENHANCEMENTS: + +* Upgrade to Go 1.23.0 ([#66](https://github.com/hashicorp/terraform-provider-assert/issues/66)) +* Added descriptions to each function in the documentation ([#69](https://github.com/hashicorp/terraform-provider-assert/issues/69)) +* Consolidated the IP Address and CIDR Function sections into a single Network Functions category in the registry. ([#69](https://github.com/hashicorp/terraform-provider-assert/issues/69)) + +BUG FIXES: + +* Correct test regex pattern ([#66](https://github.com/hashicorp/terraform-provider-assert/issues/66)) + +FEATURES: + +* Added changie for changelog ([#67](https://github.com/hashicorp/terraform-provider-assert/issues/67)) + diff --git a/README.md b/README.md index f271a76..956a2c0 100644 --- a/README.md +++ b/README.md @@ -40,9 +40,7 @@ Test assertions in your Terraform configuration should be simple and easy to rea ```hcl run "ebs_volume_size" { - command = plan - assert { condition = provider::assert::between(1, 100, aws_ebs_volume.example.size) error_message = "EBS volume size must be between 1 and 100 GiB" diff --git a/docs/functions/between.md b/docs/functions/between.md index 57ae510..d77192a 100644 --- a/docs/functions/between.md +++ b/docs/functions/between.md @@ -9,13 +9,13 @@ description: |- +The numeric function `between` returns `true` if the given value is between the two provided values, inclusive of the lower the upper bound. Otherwise, it returns `false`. + ## Terraform Test Example ```terraform run "ebs_volume_size" { - command = plan - assert { condition = provider::assert::between(1, 100, aws_ebs_volume.example.size) error_message = "EBS volume size must be between 1 and 100 GiB" diff --git a/docs/functions/cidr.md b/docs/functions/cidr.md index bc4eafc..048dd7e 100644 --- a/docs/functions/cidr.md +++ b/docs/functions/cidr.md @@ -1,6 +1,6 @@ --- page_title: "cidr function - terraform-provider-assert" -subcategory: "CIDR Address Functions" +subcategory: "Network Functions" description: |- Checks whether a string is a valid CIDR notation (IPv4 or IPv6) --- @@ -9,13 +9,17 @@ description: |- +The network function `cidr` returns `true` if the provided CIDR range is a valid CIDR notation, regardless of whether it’s IPv4 or IPv6; otherwise, it returns `false`. + +It parses the `prefix` as a CIDR notation IP address and prefix length, such as “192.0.2.0/24” or “2001:db8::/32,” as defined in RFC 4632 and RFC 4291. + +To validate a CIDR range for a specific IP version, use the `cidrv4` or `cidrv6` functions. + ## Terraform Test Example ```terraform run "check_valid_ip_aws_subnet" { - command = plan - assert { condition = provider::assert::cidr(aws_subnet.example.cidr_block) error_message = "Subnet is not in valid CIDR notation" diff --git a/docs/functions/cidrv4.md b/docs/functions/cidrv4.md index bb00ab3..d17952b 100644 --- a/docs/functions/cidrv4.md +++ b/docs/functions/cidrv4.md @@ -1,6 +1,6 @@ --- page_title: "cidrv4 function - terraform-provider-assert" -subcategory: "CIDR Address Functions" +subcategory: "Network Functions" description: |- Checks whether a string is a valid CIDR notation (IPv4) --- @@ -9,13 +9,17 @@ description: |- +The network function `cidrv4` returns true if the provided CIDR range is a valid IPv4 CIDR notation. Otherwise, it returns `false`. + +It parses the `prefix` as a CIDR notation IP address and prefix length, such as “192.0.2.0/24” as defined in RFC 4632. + +To validate a CIDR range regardless of the IP version, use the `cidr` function. + ## Terraform Test Example ```terraform run "check_valid_ipv4_aws_subnet" { - command = plan - assert { condition = provider::assert::cidrv4(aws_subnet.example.cidr_block) error_message = "Subnet is not in valid IPv4 CIDR notation" diff --git a/docs/functions/cidrv6.md b/docs/functions/cidrv6.md index e59ee9e..97e0abe 100644 --- a/docs/functions/cidrv6.md +++ b/docs/functions/cidrv6.md @@ -1,6 +1,6 @@ --- page_title: "cidrv6 function - terraform-provider-assert" -subcategory: "CIDR Address Functions" +subcategory: "Network Functions" description: |- Checks whether a string is a valid CIDR notation (IPv6) --- @@ -9,13 +9,17 @@ description: |- +The network function `cidrv6` returns true if the provided CIDR range is a valid IPv6 CIDR notation. Otherwise, it returns `false`. + +It parses the `prefix` as a CIDR notation IP address and prefix length, such as “2001:db8::/32,” as defined in RFC 4291. + +To validate a CIDR range regardless of the IP version, use the `cidr` function. + ## Terraform Test Example ```terraform run "check_valid_ipv6_aws_subnet" { - command = plan - assert { condition = provider::assert::cidrv6(aws_subnet.example.ipv6_cidr_block) error_message = "Subnet is not in valid IPv6 CIDR notation" diff --git a/docs/functions/contains.md b/docs/functions/contains.md index 57c38cf..27f7764 100644 --- a/docs/functions/contains.md +++ b/docs/functions/contains.md @@ -9,13 +9,13 @@ description: |- +The list function `contains` returns `true` if the given value is in the provided list. Otherwise, it returns `false`. + ## Terraform Test Example ```terraform run "check_example_subnet_cidr_block" { - command = plan - assert { condition = provider::assert::contains(cidrsubnets("10.1.0.0/16", 4, 4, 8, 4), aws_subnet.example.cidr_block) error_message = "CIDR block is not in the list of allowed subnets" diff --git a/docs/functions/empty.md b/docs/functions/empty.md index a68be3a..6fb0cae 100644 --- a/docs/functions/empty.md +++ b/docs/functions/empty.md @@ -9,13 +9,15 @@ description: |- +The string function `empty` returns `true` if the given string is empty. Otherwise, it returns `false`. + +A string is considered empty if it is initialized as an empty string and is not null; strings that contain only whitespace characters are not considered empty. + ## Terraform Test Example ```terraform run "check_cloudwatch_log_subscription_match_all" { - command = plan - assert { condition = provider::assert::empty(aws_cloudwatch_log_subscription_filter.example.filter_pattern) error_message = "CloudWatch log subscription filter pattern must be empty, as it is a match all." @@ -23,19 +25,6 @@ run "check_cloudwatch_log_subscription_match_all" { } ``` -## Variable Validation Example - -```terraform -variable "example" { - type = string - - validation { - condition = provider::assert::empty(var.example) - error_message = "Variable 'example' must be empty." - } -} -``` - ## Signature diff --git a/docs/functions/ends_with.md b/docs/functions/ends_with.md index 42c5adb..978e730 100644 --- a/docs/functions/ends_with.md +++ b/docs/functions/ends_with.md @@ -9,13 +9,13 @@ description: |- +The string function `ends_with` returns true if the given string ends with the provided suffix. Otherwise, it returns `false`. + ## Terraform Test Example ```terraform run "check_events_path_google_pubsub_subscription_push_endpoint" { - command = plan - assert { condition = provider::assert::ends_with("/events", google_pubsub_subscription.example.push_config.push_endpoint) error_message = "Push endpoint must end with /events" diff --git a/docs/functions/equal.md b/docs/functions/equal.md index dec6b82..249d311 100644 --- a/docs/functions/equal.md +++ b/docs/functions/equal.md @@ -9,13 +9,13 @@ description: |- +The numeric function `equal` returns `true` if the given values are equal. Otherwise, it returns `false`. + ## Terraform Test Example ```terraform run "number_of_glue_job_workers_is_5" { - command = plan - assert { condition = provider::assert::equal(5, aws_glue_job.example.number_of_workers) error_message = "Number of Glue job workers must be 5" diff --git a/docs/functions/expired.md b/docs/functions/expired.md index dec9f43..b6cda34 100644 --- a/docs/functions/expired.md +++ b/docs/functions/expired.md @@ -9,6 +9,8 @@ description: |- +The time function `expired` checks whether a given timestamp, provided in RFC3339 format, has passed. It returns `true` if the timestamp represents a time that is earlier than the current time. Otherwise, it returns `false`. + ## Continuous Validation Example (AWS) ```terraform diff --git a/docs/functions/false.md b/docs/functions/false.md index 96a1fa6..d25c74a 100644 --- a/docs/functions/false.md +++ b/docs/functions/false.md @@ -9,13 +9,13 @@ description: |- +The boolean function `false` returns `true` if the specified value or expression evaluates to `false`; otherwise, it returns `false`. + ## Terraform Test Example ```terraform run "check_rds_global_cluster_deletion_protection" { - command = plan - assert { condition = provider::assert::false(aws_rds_global_cluster.example.deletion_protection) error_message = "Cluster deletion protection must be false, this is a dev environment" diff --git a/docs/functions/greater.md b/docs/functions/greater.md index a59e8bc..2ca32d8 100644 --- a/docs/functions/greater.md +++ b/docs/functions/greater.md @@ -9,13 +9,13 @@ description: |- +The numeric function `greater` returns `true` if the second value is greater than the first value. Otherwise, it returns `false`. + ## Terraform Test Example ```terraform run "check_aws_db_instance_size" { - command = plan - assert { condition = provider::assert::greater(100, aws_db_instance.example.instance_class) error_message = "DB instance size must be greater than 100" diff --git a/docs/functions/greater_or_equal.md b/docs/functions/greater_or_equal.md index f51fb2b..62c8f45 100644 --- a/docs/functions/greater_or_equal.md +++ b/docs/functions/greater_or_equal.md @@ -9,13 +9,13 @@ description: |- +The numeric function `greater_or_equal` returns `true` if the second value is greater than or equal to the first value. Otherwise, it returns `false`. + ## Terraform Test Example ```terraform run "check_aws_db_instance_size" { - command = plan - assert { condition = provider::assert::greater_or_equal(100, aws_db_instance.example.instance_class) error_message = "DB instance size must be greater than or equal to 100" diff --git a/docs/functions/http_client_error.md b/docs/functions/http_client_error.md index 88d8792..f0e3bad 100644 --- a/docs/functions/http_client_error.md +++ b/docs/functions/http_client_error.md @@ -9,13 +9,15 @@ description: |- +The HTTP status code function `http_client_error` returns `true` if the given HTTP status code is a client error status code (4xx). Otherwise, it returns `false`. + +This function checks against the HTTP status codes defined in the Go standard library [net/http](https://golang.org/pkg/net/http/) package. For details, refer to [src/net/http/status.go](https://cs.opensource.google/go/go/+/refs/tags/go1.23.1:src/net/http/status.go;l=9). + ## Terraform Test Example ```terraform run "check_http_client_error" { - command = plan - assert { condition = provider::assert::http_client_error(data.http.secured.status_code) error_message = "My secure website must return an HTTP client error status code" diff --git a/docs/functions/http_redirect.md b/docs/functions/http_redirect.md index 92850fc..1b2073c 100644 --- a/docs/functions/http_redirect.md +++ b/docs/functions/http_redirect.md @@ -9,13 +9,15 @@ description: |- +The HTTP status code function `http_redirect` returns `true` if the given HTTP status code is a redirect status code (3xx). Otherwise, it returns `false`. + +This function checks against the HTTP status codes defined in the Go standard library [net/http](https://golang.org/pkg/net/http/) package. For details, refer to [src/net/http/status.go](https://cs.opensource.google/go/go/+/refs/tags/go1.23.1:src/net/http/status.go;l=9). + ## Terraform Test Example ```terraform run "check_http_redirect" { - command = plan - assert { condition = provider::assert::http_redirect(data.http.hashicorp.status_code) error_message = "HashiCorp's website must return a 3xx status code, when using HTTP instead of HTTPS" diff --git a/docs/functions/http_server_error.md b/docs/functions/http_server_error.md index 1942607..6f70a30 100644 --- a/docs/functions/http_server_error.md +++ b/docs/functions/http_server_error.md @@ -9,13 +9,15 @@ description: |- +The HTTP status code function `http_server_error` returns `true` if the given HTTP status code is a server error status code (5xx). Otherwise, it returns `false`. + +This function checks against the HTTP status codes defined in the Go standard library [net/http](https://golang.org/pkg/net/http/) package. For details, refer to [src/net/http/status.go](https://cs.opensource.google/go/go/+/refs/tags/go1.23.1:src/net/http/status.go;l=9). + ## Terraform Test Example ```terraform run "check_http_server_error" { - command = plan - assert { condition = provider::assert::http_client_error(data.http.down.status_code) error_message = "My down website must return an HTTP server error status code" diff --git a/docs/functions/http_success.md b/docs/functions/http_success.md index 8bfd4fc..1d040a0 100644 --- a/docs/functions/http_success.md +++ b/docs/functions/http_success.md @@ -9,13 +9,15 @@ description: |- +The HTTP status code function `http_success` returns `true` if the given HTTP status code is a success status code (2xx). Otherwise, it returns `false`. + +This function checks against the HTTP status codes defined in the Go standard library [net/http](https://golang.org/pkg/net/http/) package. For details, refer to [src/net/http/status.go](https://cs.opensource.google/go/go/+/refs/tags/go1.23.1:src/net/http/status.go;l=9). + ## Terraform Test Example ```terraform run "check_http_success" { - command = plan - assert { condition = provider::assert::http_success(data.http.hashicorp.status_code) error_message = "HashiCorp's website must return a 2xx status code" diff --git a/docs/functions/ip.md b/docs/functions/ip.md index 4b270be..a9fb6e1 100644 --- a/docs/functions/ip.md +++ b/docs/functions/ip.md @@ -1,6 +1,6 @@ --- page_title: "ip function - terraform-provider-assert" -subcategory: "IP Address Functions" +subcategory: "Network Functions" description: |- Checks whether a string is a valid IP address (IPv4 or IPv6) --- @@ -9,13 +9,15 @@ description: |- +The network function `ip` returns `true` if the given string is a valid IP address (either IPv4 or IPv6); otherwise, it returns `false`. + +A valid `ip_address` must be represented in one of the following formats: IPv4 dotted decimal (e.g., “192.0.2.1”), standard IPv6 notation (e.g., “2001:db8::68”), or IPv4-mapped IPv6 format (e.g., “::ffff:192.0.2.1”). + ## Terraform Test Example ```terraform run "check_valid_ip_google_compute_address" { - command = plan - assert { condition = provider::assert::ip(google_compute_address.example.address) error_message = "Address is not a valid IP address" diff --git a/docs/functions/ipv4.md b/docs/functions/ipv4.md index 7152477..4125fa3 100644 --- a/docs/functions/ipv4.md +++ b/docs/functions/ipv4.md @@ -1,6 +1,6 @@ --- page_title: "ipv4 function - terraform-provider-assert" -subcategory: "IP Address Functions" +subcategory: "Network Functions" description: |- Checks whether a string is a valid IPv4 address --- @@ -9,13 +9,17 @@ description: |- +The network function `ipv4` returns `true` if the given string is a valid IPv4 address. Otherwise, it returns `false`. + +A valid `ip_address` must be represented in the following format: IPv4 dotted decimal (e.g., “192.0.2.1”). + +To validate an IP address regardless of the IP version, use the `ip` function. + ## Terraform Test Example ```terraform run "check_valid_ipv4_google_compute_address" { - command = plan - assert { condition = provider::assert::ipv4(google_compute_address.example.address) error_message = "Address is not a valid IPv4 address" diff --git a/docs/functions/ipv6.md b/docs/functions/ipv6.md index 1c81eba..63858d9 100644 --- a/docs/functions/ipv6.md +++ b/docs/functions/ipv6.md @@ -1,6 +1,6 @@ --- page_title: "ipv6 function - terraform-provider-assert" -subcategory: "IP Address Functions" +subcategory: "Network Functions" description: |- Checks whether a string is a valid IPv6 address --- @@ -9,13 +9,17 @@ description: |- +The network function `ipv6` returns `true` if the given string is a valid IPv6 address. Otherwise, it returns `false`. + +A valid `ip_address` must be represented in the following format: standard IPv6 notation (e.g., “2001:db8::68”) or IPv4-mapped IPv6 format (e.g., “::ffff:192.0.2.1”). + +To validate an IP address regardless of the IP version, use the `ip` function. + ## Terraform Test Example ```terraform run "check_valid_ipv6_google_compute_address" { - command = plan - assert { condition = provider::assert::ipv6(google_compute_address.example.address) error_message = "Address is not a valid IPv6 address" diff --git a/docs/functions/key.md b/docs/functions/key.md index eafb9ba..daa5deb 100644 --- a/docs/functions/key.md +++ b/docs/functions/key.md @@ -9,12 +9,13 @@ description: |- +The map function `key` returns `true` if the given key is in the provided map. Otherwise, it returns `false`. + ## Terraform Test Example ```terraform run "check_if_lambda_function_tags_has_key" { command = plan - assert { condition = provider::assert::key("key1", aws_lambda_function.example.tags) error_message = "The tags map must contain the key 'key1'" diff --git a/docs/functions/less.md b/docs/functions/less.md index 6441cb5..758f207 100644 --- a/docs/functions/less.md +++ b/docs/functions/less.md @@ -9,13 +9,13 @@ description: |- +The numeric function `less` returns `true` if the second value is less than the first value. Otherwise, it returns `false`. + ## Terraform Test Example ```terraform run "check_aws_db_instance_size" { - command = plan - assert { condition = provider::assert::less(1000, aws_db_instance.example.instance_class) error_message = "DB instance size must be less than 1000" diff --git a/docs/functions/less_or_equal.md b/docs/functions/less_or_equal.md index a96c8fd..d061f7e 100644 --- a/docs/functions/less_or_equal.md +++ b/docs/functions/less_or_equal.md @@ -9,13 +9,13 @@ description: |- +The numeric function `less_or_equal` returns `true` if the second value is less than or equal to the first value. Otherwise, it returns `false`. + ## Terraform Test Example ```terraform run "check_aws_db_instance_size" { - command = plan - assert { condition = provider::assert::less_or_equal(1000, aws_db_instance.example.instance_class) error_message = "DB instance size must be less than or equal to 1000" diff --git a/docs/functions/lowercased.md b/docs/functions/lowercased.md index 8981b3a..ceacb5f 100644 --- a/docs/functions/lowercased.md +++ b/docs/functions/lowercased.md @@ -9,6 +9,8 @@ description: |- +The string function `lowercased` returns `true` if the given string is in lowercase. Otherwise, it returns `false`. + ## Variable Validation Example ```terraform diff --git a/docs/functions/negative.md b/docs/functions/negative.md index 079377d..eb82b8c 100644 --- a/docs/functions/negative.md +++ b/docs/functions/negative.md @@ -9,6 +9,8 @@ description: |- +The numeric function `positive` returns `true` if the given value is positive. Otherwise, it returns `false`. + ## Variable Validation Example ```terraform diff --git a/docs/functions/not_empty.md b/docs/functions/not_empty.md index 41ab079..d3a0ca5 100644 --- a/docs/functions/not_empty.md +++ b/docs/functions/not_empty.md @@ -9,13 +9,15 @@ description: |- +The string function `not_empty` returns `true` if the given string is not empty. Otherwise, it returns `false`. + +A string is considered empty if it is initialized, not null, and has a length of zero characters. + ## Terraform Test Example ```terraform run "check_security_group_description" { - command = plan - assert { condition = provider::assert::not_empty(aws_security_group.example.description) error_message = "Security group description must not be empty." diff --git a/docs/functions/not_equal.md b/docs/functions/not_equal.md index 0c098b3..593fc6e 100644 --- a/docs/functions/not_equal.md +++ b/docs/functions/not_equal.md @@ -9,13 +9,13 @@ description: |- +The numeric function `not_equal` returns `true` if the given values are not equal. Otherwise, it returns `false`. + ## Terraform Test Example ```terraform run "check_rds_global_cluster_deletion_protection" { - command = plan - assert { condition = provider::assert::not_equal(var.rds_global_cluster_deletion_protection, false) error_message = "Make sure that deletion protection is not set to false" diff --git a/docs/functions/not_null.md b/docs/functions/not_null.md index 796c54f..68b91b3 100644 --- a/docs/functions/not_null.md +++ b/docs/functions/not_null.md @@ -9,13 +9,15 @@ description: |- +The `not_null` function returns `true` if the given value is not a null value. Otherwise, it returns `false`. + +In Terraform, the null value type represents the absence or omission of a value. You can explicitly set a resource argument to `null` to indicate that no value is provided. + ## Terraform Test Example ```terraform run "check_if_range_key_is_not_null" { - command = plan - assert { condition = provider::assert::not_null(aws_dynamodb_table.example.range_key) error_message = "DynamoDB table range key must not be null" diff --git a/docs/functions/null.md b/docs/functions/null.md index b41ea75..c3ab7af 100644 --- a/docs/functions/null.md +++ b/docs/functions/null.md @@ -9,6 +9,10 @@ description: |- +The null function `null` returns `true` if the given value is a null value. Otherwise, it returns `false`. + +In Terraform, the null value type represents the absence or omission of a value. You can explicitly set a resource argument to `null` to indicate that no value is provided. + ## Variable Validation Example diff --git a/docs/functions/positive.md b/docs/functions/positive.md index 8011558..be5ac01 100644 --- a/docs/functions/positive.md +++ b/docs/functions/positive.md @@ -9,6 +9,8 @@ description: |- +This numeric function `positive` returns `true` if the given value is positive. Otherwise, it returns `false`. + ## Variable Validation Example ```terraform diff --git a/docs/functions/regex.md b/docs/functions/regex.md index 90447d2..6e0357b 100644 --- a/docs/functions/regex.md +++ b/docs/functions/regex.md @@ -9,6 +9,10 @@ description: |- +The string function regex returns true if the given string matches the regular expression pattern; otherwise, it returns false. To perform a substring match, use the regular expression without anchoring the pattern. + +Learn more about regular expressions in the [Terraform documentation](https://www.terraform.io/docs/language/functions/regex.html). + ## Variable Validation Example diff --git a/docs/functions/starts_with.md b/docs/functions/starts_with.md index 1d11ef2..143d918 100644 --- a/docs/functions/starts_with.md +++ b/docs/functions/starts_with.md @@ -9,13 +9,13 @@ description: |- +The string function `starts_with` returns true if the given string starts with the provided prefix. Otherwise, it returns `false`. + ## Terraform Test Example ```terraform run "check_https_google_pubsub_subscription_push_endpoint" { - command = plan - assert { condition = provider::assert::starts_with("https://", google_pubsub_subscription.example.push_config.push_endpoint) error_message = "Push endpoint must start with https://" diff --git a/docs/functions/true.md b/docs/functions/true.md index 12e52c3..b24dcf4 100644 --- a/docs/functions/true.md +++ b/docs/functions/true.md @@ -9,13 +9,13 @@ description: |- +The boolean function `true` returns `true` if the specified value or expression evaluates to `true`; otherwise, it returns `false`. + ## Terraform Test Example ```terraform run "check_rds_global_cluster_deletion_protection" { - command = plan - assert { condition = provider::assert::true(aws_rds_global_cluster.example.deletion_protection) error_message = "Cluster deletion protection must be enabled, because this is a prod environment" diff --git a/docs/functions/uppercased.md b/docs/functions/uppercased.md index 48308d4..38a0365 100644 --- a/docs/functions/uppercased.md +++ b/docs/functions/uppercased.md @@ -9,6 +9,8 @@ description: |- +The string function `uppercsaed` returns `true` if the given string is in uppercase. Otherwise, it returns `false`. + ## Variable Validation Example ```terraform diff --git a/docs/functions/valid_json.md b/docs/functions/valid_json.md index cb667ef..0375bcc 100644 --- a/docs/functions/valid_json.md +++ b/docs/functions/valid_json.md @@ -9,13 +9,13 @@ description: |- +The data validation function `valid_json` returns `true` if the given string is a valid JSON. Otherwise, it returns `false`. + ## Terraform Test Example ```terraform run "check_config" { - command = plan - assert { condition = provider::assert::valid_json(data.local_file.config.content) error_message = "Config is not a valid JSON" diff --git a/docs/functions/valid_yaml.md b/docs/functions/valid_yaml.md index ba97d90..f929453 100644 --- a/docs/functions/valid_yaml.md +++ b/docs/functions/valid_yaml.md @@ -9,13 +9,13 @@ description: |- +The data validation function `valid_yaml` returns `true` if the given string is a valid YAML. Otherwise, it returns `false`. + ## Terraform Test Example ```terraform run "check_config" { - command = plan - assert { condition = provider::assert::valid_yaml(data.local_file.config.content) error_message = "Config is not a valid YAML" diff --git a/docs/functions/value.md b/docs/functions/value.md index 3857cd7..c4f8de5 100644 --- a/docs/functions/value.md +++ b/docs/functions/value.md @@ -9,12 +9,13 @@ description: |- +The map function `value` returns `true` if the given value is present in the map. Otherwise, it returns `false`. + ## Terraform Test Example ```terraform run "check_if_lambda_function_tags_has_value" { command = plan - assert { condition = provider::assert::value("value1", aws_lambda_function.example.tags) error_message = "The tags map must contain the value 'value1'" diff --git a/docs/index.md b/docs/index.md index a0cddcb..f7cb414 100644 --- a/docs/index.md +++ b/docs/index.md @@ -6,10 +6,9 @@ description: |- # Assert Provider -The Assert provider is a utility provider that helps practitioners -to simplify the way they write assertions in their Terraform configurations. +The Assert provider for Terraform is a utility provider that offers a comprehensive set of assertion capabilities through provider-defined functions such as [http_success](https://registry.terraform.io/providers/hashicorp/assert/latest/docs/functions/http_success), [expired](https://registry.terraform.io/providers/hashicorp/assert/latest/docs/functions/expired), and [between](https://registry.terraform.io/providers/hashicorp/assert/latest/docs/functions/between). These assertion functions simplify your Terraform configurations, making variable validation, continuous validation, and testing easier. -This provider is typically used in Terraform test assertions or variable validation. +The Assert provider functions complement Terraform’s [built-in](https://developer.hashicorp.com/terraform/language/functions) functions rather than replacing them. If Terraform’s built-in functions better fit your requirements, they should be your choice. This provider does not manage any infrastructure, but instead provides a set of provider-defined functions that can be used to assert that values in Terraform configurations. @@ -20,7 +19,7 @@ Use the navigation to the left to read about the available resources. As of Terraform 1.8 and later, providers can implement functions that you can call from the Terraform configuration. -Define the provider as a `required_provider` to use its functions +To use the Assert provider, declare it as a `required_provider` in the `terraform {}` block: ```terraform terraform { @@ -32,5 +31,8 @@ terraform { } ``` -## Limitations +## Function Syntax +You use the functions with a special syntax: `provider::assert::`. + +For instance, to check if an HTTP status code falls within the success range, use the `http_success` function and call it using `provider::assert::http_success(data.http.example.status_code)`. diff --git a/examples/functions/between/function.tf b/examples/functions/between/function.tf index 30ef535..d348620 100644 --- a/examples/functions/between/function.tf +++ b/examples/functions/between/function.tf @@ -1,7 +1,5 @@ run "ebs_volume_size" { - command = plan - assert { condition = provider::assert::between(1, 100, aws_ebs_volume.example.size) error_message = "EBS volume size must be between 1 and 100 GiB" diff --git a/examples/functions/cidr/function.tf b/examples/functions/cidr/function.tf index 9adf37f..e95e417 100644 --- a/examples/functions/cidr/function.tf +++ b/examples/functions/cidr/function.tf @@ -1,7 +1,5 @@ run "check_valid_ip_aws_subnet" { - command = plan - assert { condition = provider::assert::cidr(aws_subnet.example.cidr_block) error_message = "Subnet is not in valid CIDR notation" diff --git a/examples/functions/cidrv4/function.tf b/examples/functions/cidrv4/function.tf index 7cc65bb..948b428 100644 --- a/examples/functions/cidrv4/function.tf +++ b/examples/functions/cidrv4/function.tf @@ -1,7 +1,5 @@ run "check_valid_ipv4_aws_subnet" { - command = plan - assert { condition = provider::assert::cidrv4(aws_subnet.example.cidr_block) error_message = "Subnet is not in valid IPv4 CIDR notation" diff --git a/examples/functions/cidrv6/function.tf b/examples/functions/cidrv6/function.tf index baa5064..d87656b 100644 --- a/examples/functions/cidrv6/function.tf +++ b/examples/functions/cidrv6/function.tf @@ -1,7 +1,5 @@ run "check_valid_ipv6_aws_subnet" { - command = plan - assert { condition = provider::assert::cidrv6(aws_subnet.example.ipv6_cidr_block) error_message = "Subnet is not in valid IPv6 CIDR notation" diff --git a/examples/functions/contains/function.tf b/examples/functions/contains/function.tf index 8c43d24..73cb5d3 100644 --- a/examples/functions/contains/function.tf +++ b/examples/functions/contains/function.tf @@ -1,7 +1,5 @@ run "check_example_subnet_cidr_block" { - command = plan - assert { condition = provider::assert::contains(cidrsubnets("10.1.0.0/16", 4, 4, 8, 4), aws_subnet.example.cidr_block) error_message = "CIDR block is not in the list of allowed subnets" diff --git a/examples/functions/empty/function.tf b/examples/functions/empty/function.tf index 8b997fb..6ddbb6b 100644 --- a/examples/functions/empty/function.tf +++ b/examples/functions/empty/function.tf @@ -1,7 +1,5 @@ run "check_cloudwatch_log_subscription_match_all" { - command = plan - assert { condition = provider::assert::empty(aws_cloudwatch_log_subscription_filter.example.filter_pattern) error_message = "CloudWatch log subscription filter pattern must be empty, as it is a match all." diff --git a/examples/functions/ends_with/function.tf b/examples/functions/ends_with/function.tf index 0ba6688..6ecf54e 100644 --- a/examples/functions/ends_with/function.tf +++ b/examples/functions/ends_with/function.tf @@ -1,7 +1,5 @@ run "check_events_path_google_pubsub_subscription_push_endpoint" { - command = plan - assert { condition = provider::assert::ends_with("/events", google_pubsub_subscription.example.push_config.push_endpoint) error_message = "Push endpoint must end with /events" diff --git a/examples/functions/equal/function.tf b/examples/functions/equal/function.tf index 8de0629..a186ccf 100644 --- a/examples/functions/equal/function.tf +++ b/examples/functions/equal/function.tf @@ -1,7 +1,5 @@ run "number_of_glue_job_workers_is_5" { - command = plan - assert { condition = provider::assert::equal(5, aws_glue_job.example.number_of_workers) error_message = "Number of Glue job workers must be 5" diff --git a/examples/functions/false/function.tf b/examples/functions/false/function.tf index 4d050f8..2bda0ea 100644 --- a/examples/functions/false/function.tf +++ b/examples/functions/false/function.tf @@ -1,7 +1,5 @@ run "check_rds_global_cluster_deletion_protection" { - command = plan - assert { condition = provider::assert::false(aws_rds_global_cluster.example.deletion_protection) error_message = "Cluster deletion protection must be false, this is a dev environment" diff --git a/examples/functions/greater/function.tf b/examples/functions/greater/function.tf index aa79946..1217ab3 100644 --- a/examples/functions/greater/function.tf +++ b/examples/functions/greater/function.tf @@ -1,7 +1,5 @@ run "check_aws_db_instance_size" { - command = plan - assert { condition = provider::assert::greater(100, aws_db_instance.example.instance_class) error_message = "DB instance size must be greater than 100" diff --git a/examples/functions/greater_or_equal/function.tf b/examples/functions/greater_or_equal/function.tf index 97cd640..17e9bcf 100644 --- a/examples/functions/greater_or_equal/function.tf +++ b/examples/functions/greater_or_equal/function.tf @@ -1,7 +1,5 @@ run "check_aws_db_instance_size" { - command = plan - assert { condition = provider::assert::greater_or_equal(100, aws_db_instance.example.instance_class) error_message = "DB instance size must be greater than or equal to 100" diff --git a/examples/functions/http_client_error/function.tf b/examples/functions/http_client_error/function.tf index b277afc..b779938 100644 --- a/examples/functions/http_client_error/function.tf +++ b/examples/functions/http_client_error/function.tf @@ -1,7 +1,5 @@ run "check_http_client_error" { - command = plan - assert { condition = provider::assert::http_client_error(data.http.secured.status_code) error_message = "My secure website must return an HTTP client error status code" diff --git a/examples/functions/http_redirect/function.tf b/examples/functions/http_redirect/function.tf index 070ffbe..b4f9d69 100644 --- a/examples/functions/http_redirect/function.tf +++ b/examples/functions/http_redirect/function.tf @@ -1,7 +1,5 @@ run "check_http_redirect" { - command = plan - assert { condition = provider::assert::http_redirect(data.http.hashicorp.status_code) error_message = "HashiCorp's website must return a 3xx status code, when using HTTP instead of HTTPS" diff --git a/examples/functions/http_server_error/function.tf b/examples/functions/http_server_error/function.tf index 6b1a75c..7f623d6 100644 --- a/examples/functions/http_server_error/function.tf +++ b/examples/functions/http_server_error/function.tf @@ -1,7 +1,5 @@ run "check_http_server_error" { - command = plan - assert { condition = provider::assert::http_client_error(data.http.down.status_code) error_message = "My down website must return an HTTP server error status code" diff --git a/examples/functions/http_success/function.tf b/examples/functions/http_success/function.tf index 25e14d3..8a9af36 100644 --- a/examples/functions/http_success/function.tf +++ b/examples/functions/http_success/function.tf @@ -1,7 +1,5 @@ run "check_http_success" { - command = plan - assert { condition = provider::assert::http_success(data.http.hashicorp.status_code) error_message = "HashiCorp's website must return a 2xx status code" diff --git a/examples/functions/ip/function.tf b/examples/functions/ip/function.tf index bdc84af..b2e547e 100644 --- a/examples/functions/ip/function.tf +++ b/examples/functions/ip/function.tf @@ -1,7 +1,5 @@ run "check_valid_ip_google_compute_address" { - command = plan - assert { condition = provider::assert::ip(google_compute_address.example.address) error_message = "Address is not a valid IP address" diff --git a/examples/functions/ipv4/function.tf b/examples/functions/ipv4/function.tf index 2999dd3..bd32773 100644 --- a/examples/functions/ipv4/function.tf +++ b/examples/functions/ipv4/function.tf @@ -1,7 +1,5 @@ run "check_valid_ipv4_google_compute_address" { - command = plan - assert { condition = provider::assert::ipv4(google_compute_address.example.address) error_message = "Address is not a valid IPv4 address" diff --git a/examples/functions/ipv6/function.tf b/examples/functions/ipv6/function.tf index 9340e65..f68742f 100644 --- a/examples/functions/ipv6/function.tf +++ b/examples/functions/ipv6/function.tf @@ -1,7 +1,5 @@ run "check_valid_ipv6_google_compute_address" { - command = plan - assert { condition = provider::assert::ipv6(google_compute_address.example.address) error_message = "Address is not a valid IPv6 address" diff --git a/examples/functions/key/function.tf b/examples/functions/key/function.tf index 4dd8c35..6e3d4e8 100644 --- a/examples/functions/key/function.tf +++ b/examples/functions/key/function.tf @@ -1,6 +1,5 @@ run "check_if_lambda_function_tags_has_key" { command = plan - assert { condition = provider::assert::key("key1", aws_lambda_function.example.tags) error_message = "The tags map must contain the key 'key1'" diff --git a/examples/functions/less/function.tf b/examples/functions/less/function.tf index 41d5ffa..9a56615 100644 --- a/examples/functions/less/function.tf +++ b/examples/functions/less/function.tf @@ -1,7 +1,5 @@ run "check_aws_db_instance_size" { - command = plan - assert { condition = provider::assert::less(1000, aws_db_instance.example.instance_class) error_message = "DB instance size must be less than 1000" diff --git a/examples/functions/less_or_equal/function.tf b/examples/functions/less_or_equal/function.tf index 3c34442..c13b0ed 100644 --- a/examples/functions/less_or_equal/function.tf +++ b/examples/functions/less_or_equal/function.tf @@ -1,7 +1,5 @@ run "check_aws_db_instance_size" { - command = plan - assert { condition = provider::assert::less_or_equal(1000, aws_db_instance.example.instance_class) error_message = "DB instance size must be less than or equal to 1000" diff --git a/examples/functions/not_empty/function.tf b/examples/functions/not_empty/function.tf index 95f904a..6f29de5 100644 --- a/examples/functions/not_empty/function.tf +++ b/examples/functions/not_empty/function.tf @@ -1,7 +1,5 @@ run "check_security_group_description" { - command = plan - assert { condition = provider::assert::not_empty(aws_security_group.example.description) error_message = "Security group description must not be empty." diff --git a/examples/functions/not_equal/function.tf b/examples/functions/not_equal/function.tf index 45d6fe9..ccd97d7 100644 --- a/examples/functions/not_equal/function.tf +++ b/examples/functions/not_equal/function.tf @@ -1,7 +1,5 @@ run "check_rds_global_cluster_deletion_protection" { - command = plan - assert { condition = provider::assert::not_equal(var.rds_global_cluster_deletion_protection, false) error_message = "Make sure that deletion protection is not set to false" diff --git a/examples/functions/not_null/function.tf b/examples/functions/not_null/function.tf index fb6d30b..3c7d1cc 100644 --- a/examples/functions/not_null/function.tf +++ b/examples/functions/not_null/function.tf @@ -1,7 +1,5 @@ run "check_if_range_key_is_not_null" { - command = plan - assert { condition = provider::assert::not_null(aws_dynamodb_table.example.range_key) error_message = "DynamoDB table range key must not be null" diff --git a/examples/functions/starts_with/function.tf b/examples/functions/starts_with/function.tf index b894b02..a39d4fb 100644 --- a/examples/functions/starts_with/function.tf +++ b/examples/functions/starts_with/function.tf @@ -1,7 +1,5 @@ run "check_https_google_pubsub_subscription_push_endpoint" { - command = plan - assert { condition = provider::assert::starts_with("https://", google_pubsub_subscription.example.push_config.push_endpoint) error_message = "Push endpoint must start with https://" diff --git a/examples/functions/true/function.tf b/examples/functions/true/function.tf index ad8f27c..f6a14be 100644 --- a/examples/functions/true/function.tf +++ b/examples/functions/true/function.tf @@ -1,7 +1,5 @@ run "check_rds_global_cluster_deletion_protection" { - command = plan - assert { condition = provider::assert::true(aws_rds_global_cluster.example.deletion_protection) error_message = "Cluster deletion protection must be enabled, because this is a prod environment" diff --git a/examples/functions/valid_json/function.tf b/examples/functions/valid_json/function.tf index 39c6b4e..c63fef5 100644 --- a/examples/functions/valid_json/function.tf +++ b/examples/functions/valid_json/function.tf @@ -1,7 +1,5 @@ run "check_config" { - command = plan - assert { condition = provider::assert::valid_json(data.local_file.config.content) error_message = "Config is not a valid JSON" diff --git a/examples/functions/valid_yaml/function.tf b/examples/functions/valid_yaml/function.tf index 8b4b695..82b71c1 100644 --- a/examples/functions/valid_yaml/function.tf +++ b/examples/functions/valid_yaml/function.tf @@ -1,7 +1,5 @@ run "check_config" { - command = plan - assert { condition = provider::assert::valid_yaml(data.local_file.config.content) error_message = "Config is not a valid YAML" diff --git a/examples/functions/value/function.tf b/examples/functions/value/function.tf index 7186b88..6a5147a 100644 --- a/examples/functions/value/function.tf +++ b/examples/functions/value/function.tf @@ -1,6 +1,5 @@ run "check_if_lambda_function_tags_has_value" { command = plan - assert { condition = provider::assert::value("value1", aws_lambda_function.example.tags) error_message = "The tags map must contain the value 'value1'" diff --git a/internal/provider/between_function_test.go b/internal/provider/between_function_test.go index 786fc31..70e556a 100644 --- a/internal/provider/between_function_test.go +++ b/internal/provider/between_function_test.go @@ -121,6 +121,38 @@ output "test" { }) } +func TestBetweenFunction_inclusiveBounds(t *testing.T) { + t.Parallel() + resource.UnitTest(t, resource.TestCase{ + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBelow(version.Must(version.NewVersion(MinimalRequiredTerraformVersion))), + }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: ` +output "test" { + value = provider::assert::between(1, 5, 1) +} + `, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckOutput("test", "true"), + ), + }, + { + Config: ` +output "test" { + value = provider::assert::between(1, 5, 5) +} + `, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckOutput("test", "true"), + ), + }, + }, + }) +} + func TestBetweenFunction_falseCases(t *testing.T) { t.Parallel() resource.UnitTest(t, resource.TestCase{ diff --git a/internal/provider/regex.go b/internal/provider/regex.go index e830f51..1dcb121 100644 --- a/internal/provider/regex.go +++ b/internal/provider/regex.go @@ -5,8 +5,9 @@ package provider import ( "context" - "github.com/hashicorp/terraform-plugin-framework/function" "regexp" + + "github.com/hashicorp/terraform-plugin-framework/function" ) var ( diff --git a/templates/functions/between.md.tmpl b/templates/functions/between.md.tmpl index 16f543b..a27fec1 100644 --- a/templates/functions/between.md.tmpl +++ b/templates/functions/between.md.tmpl @@ -9,6 +9,8 @@ description: |- {{ .Description | trimspace }} +The numeric function `between` returns `true` if the given value is between the two provided values, inclusive of the lower the upper bound. Otherwise, it returns `false`. + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/cidr.md.tmpl b/templates/functions/cidr.md.tmpl index 995fe4a..4f8a37d 100644 --- a/templates/functions/cidr.md.tmpl +++ b/templates/functions/cidr.md.tmpl @@ -1,6 +1,6 @@ --- page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" -subcategory: "CIDR Address Functions" +subcategory: "Network Functions" description: |- {{ .Summary | plainmarkdown | trimspace | prefixlines " " }} --- @@ -9,6 +9,12 @@ description: |- {{ .Description | trimspace }} +The network function `cidr` returns `true` if the provided CIDR range is a valid CIDR notation, regardless of whether it’s IPv4 or IPv6; otherwise, it returns `false`. + +It parses the `prefix` as a CIDR notation IP address and prefix length, such as “192.0.2.0/24” or “2001:db8::/32,” as defined in RFC 4632 and RFC 4291. + +To validate a CIDR range for a specific IP version, use the `cidrv4` or `cidrv6` functions. + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/cidrv4.md.tmpl b/templates/functions/cidrv4.md.tmpl index 995fe4a..cba1922 100644 --- a/templates/functions/cidrv4.md.tmpl +++ b/templates/functions/cidrv4.md.tmpl @@ -1,6 +1,6 @@ --- page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" -subcategory: "CIDR Address Functions" +subcategory: "Network Functions" description: |- {{ .Summary | plainmarkdown | trimspace | prefixlines " " }} --- @@ -9,6 +9,12 @@ description: |- {{ .Description | trimspace }} +The network function `cidrv4` returns true if the provided CIDR range is a valid IPv4 CIDR notation. Otherwise, it returns `false`. + +It parses the `prefix` as a CIDR notation IP address and prefix length, such as “192.0.2.0/24” as defined in RFC 4632. + +To validate a CIDR range regardless of the IP version, use the `cidr` function. + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/cidrv6.md.tmpl b/templates/functions/cidrv6.md.tmpl index 995fe4a..394b56f 100644 --- a/templates/functions/cidrv6.md.tmpl +++ b/templates/functions/cidrv6.md.tmpl @@ -1,6 +1,6 @@ --- page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" -subcategory: "CIDR Address Functions" +subcategory: "Network Functions" description: |- {{ .Summary | plainmarkdown | trimspace | prefixlines " " }} --- @@ -9,6 +9,12 @@ description: |- {{ .Description | trimspace }} +The network function `cidrv6` returns true if the provided CIDR range is a valid IPv6 CIDR notation. Otherwise, it returns `false`. + +It parses the `prefix` as a CIDR notation IP address and prefix length, such as “2001:db8::/32,” as defined in RFC 4291. + +To validate a CIDR range regardless of the IP version, use the `cidr` function. + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/contains.md.tmpl b/templates/functions/contains.md.tmpl index 77f4af6..c7b7cc7 100644 --- a/templates/functions/contains.md.tmpl +++ b/templates/functions/contains.md.tmpl @@ -9,6 +9,8 @@ description: |- {{ .Description | trimspace }} +The list function `contains` returns `true` if the given value is in the provided list. Otherwise, it returns `false`. + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/empty.md.tmpl b/templates/functions/empty.md.tmpl index 5649efe..6a37c11 100644 --- a/templates/functions/empty.md.tmpl +++ b/templates/functions/empty.md.tmpl @@ -9,16 +9,16 @@ description: |- {{ .Description | trimspace }} +The string function `empty` returns `true` if the given string is empty. Otherwise, it returns `false`. + +A string is considered empty if it is initialized as an empty string and is not null; strings that contain only whitespace characters are not considered empty. + {{ if .HasExample -}} ## Terraform Test Example {{tffile .ExampleFile }} {{- end }} -## Variable Validation Example - -{{ tffile (printf "examples/functions/%s/variable.tf" .Name)}} - ## Signature {{ .FunctionSignatureMarkdown }} diff --git a/templates/functions/ends_with.md.tmpl b/templates/functions/ends_with.md.tmpl index 5649efe..c1ec8f1 100644 --- a/templates/functions/ends_with.md.tmpl +++ b/templates/functions/ends_with.md.tmpl @@ -9,6 +9,8 @@ description: |- {{ .Description | trimspace }} +The string function `ends_with` returns true if the given string ends with the provided suffix. Otherwise, it returns `false`. + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/equal.md.tmpl b/templates/functions/equal.md.tmpl index 16f543b..3ac02f4 100644 --- a/templates/functions/equal.md.tmpl +++ b/templates/functions/equal.md.tmpl @@ -9,6 +9,8 @@ description: |- {{ .Description | trimspace }} +The numeric function `equal` returns `true` if the given values are equal. Otherwise, it returns `false`. + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/expired.md.tmpl b/templates/functions/expired.md.tmpl index fc76c21..bffdd49 100644 --- a/templates/functions/expired.md.tmpl +++ b/templates/functions/expired.md.tmpl @@ -9,6 +9,8 @@ description: |- {{ .Description | trimspace }} +The time function `expired` checks whether a given timestamp, provided in RFC3339 format, has passed. It returns `true` if the timestamp represents a time that is earlier than the current time. Otherwise, it returns `false`. + ## Continuous Validation Example (AWS) {{ tffile (printf "examples/functions/%s/check_aws.tf" .Name)}} diff --git a/templates/functions/false.md.tmpl b/templates/functions/false.md.tmpl index 4e4cbaf..ca5fd8c 100644 --- a/templates/functions/false.md.tmpl +++ b/templates/functions/false.md.tmpl @@ -9,6 +9,8 @@ description: |- {{ .Description | trimspace }} +The boolean function `false` returns `true` if the specified value or expression evaluates to `false`; otherwise, it returns `false`. + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/greater.md.tmpl b/templates/functions/greater.md.tmpl index 16f543b..bd1c687 100644 --- a/templates/functions/greater.md.tmpl +++ b/templates/functions/greater.md.tmpl @@ -9,6 +9,8 @@ description: |- {{ .Description | trimspace }} +The numeric function `greater` returns `true` if the second value is greater than the first value. Otherwise, it returns `false`. + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/greater_or_equal.md.tmpl b/templates/functions/greater_or_equal.md.tmpl index 16f543b..01c3e11 100644 --- a/templates/functions/greater_or_equal.md.tmpl +++ b/templates/functions/greater_or_equal.md.tmpl @@ -9,6 +9,8 @@ description: |- {{ .Description | trimspace }} +The numeric function `greater_or_equal` returns `true` if the second value is greater than or equal to the first value. Otherwise, it returns `false`. + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/http_client_error.md.tmpl b/templates/functions/http_client_error.md.tmpl index 6a289e6..07ebf60 100644 --- a/templates/functions/http_client_error.md.tmpl +++ b/templates/functions/http_client_error.md.tmpl @@ -9,6 +9,10 @@ description: |- {{ .Description | trimspace }} +The HTTP status code function `http_client_error` returns `true` if the given HTTP status code is a client error status code (4xx). Otherwise, it returns `false`. + +This function checks against the HTTP status codes defined in the Go standard library [net/http](https://golang.org/pkg/net/http/) package. For details, refer to [src/net/http/status.go](https://cs.opensource.google/go/go/+/refs/tags/go1.23.1:src/net/http/status.go;l=9). + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/http_redirect.md.tmpl b/templates/functions/http_redirect.md.tmpl index 6a289e6..9234900 100644 --- a/templates/functions/http_redirect.md.tmpl +++ b/templates/functions/http_redirect.md.tmpl @@ -9,6 +9,10 @@ description: |- {{ .Description | trimspace }} +The HTTP status code function `http_redirect` returns `true` if the given HTTP status code is a redirect status code (3xx). Otherwise, it returns `false`. + +This function checks against the HTTP status codes defined in the Go standard library [net/http](https://golang.org/pkg/net/http/) package. For details, refer to [src/net/http/status.go](https://cs.opensource.google/go/go/+/refs/tags/go1.23.1:src/net/http/status.go;l=9). + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/http_server_error.md.tmpl b/templates/functions/http_server_error.md.tmpl index 6a289e6..dfcea4c 100644 --- a/templates/functions/http_server_error.md.tmpl +++ b/templates/functions/http_server_error.md.tmpl @@ -9,6 +9,10 @@ description: |- {{ .Description | trimspace }} +The HTTP status code function `http_server_error` returns `true` if the given HTTP status code is a server error status code (5xx). Otherwise, it returns `false`. + +This function checks against the HTTP status codes defined in the Go standard library [net/http](https://golang.org/pkg/net/http/) package. For details, refer to [src/net/http/status.go](https://cs.opensource.google/go/go/+/refs/tags/go1.23.1:src/net/http/status.go;l=9). + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/http_success.md.tmpl b/templates/functions/http_success.md.tmpl index 6a289e6..f096079 100644 --- a/templates/functions/http_success.md.tmpl +++ b/templates/functions/http_success.md.tmpl @@ -9,6 +9,10 @@ description: |- {{ .Description | trimspace }} +The HTTP status code function `http_success` returns `true` if the given HTTP status code is a success status code (2xx). Otherwise, it returns `false`. + +This function checks against the HTTP status codes defined in the Go standard library [net/http](https://golang.org/pkg/net/http/) package. For details, refer to [src/net/http/status.go](https://cs.opensource.google/go/go/+/refs/tags/go1.23.1:src/net/http/status.go;l=9). + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/ip.md.tmpl b/templates/functions/ip.md.tmpl index 337fa57..2fc4bff 100644 --- a/templates/functions/ip.md.tmpl +++ b/templates/functions/ip.md.tmpl @@ -1,6 +1,6 @@ --- page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" -subcategory: "IP Address Functions" +subcategory: "Network Functions" description: |- {{ .Summary | plainmarkdown | trimspace | prefixlines " " }} --- @@ -9,6 +9,10 @@ description: |- {{ .Description | trimspace }} +The network function `ip` returns `true` if the given string is a valid IP address (either IPv4 or IPv6); otherwise, it returns `false`. + +A valid `ip_address` must be represented in one of the following formats: IPv4 dotted decimal (e.g., “192.0.2.1”), standard IPv6 notation (e.g., “2001:db8::68”), or IPv4-mapped IPv6 format (e.g., “::ffff:192.0.2.1”). + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/ipv4.md.tmpl b/templates/functions/ipv4.md.tmpl index 337fa57..aa157fb 100644 --- a/templates/functions/ipv4.md.tmpl +++ b/templates/functions/ipv4.md.tmpl @@ -1,6 +1,6 @@ --- page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" -subcategory: "IP Address Functions" +subcategory: "Network Functions" description: |- {{ .Summary | plainmarkdown | trimspace | prefixlines " " }} --- @@ -9,6 +9,12 @@ description: |- {{ .Description | trimspace }} +The network function `ipv4` returns `true` if the given string is a valid IPv4 address. Otherwise, it returns `false`. + +A valid `ip_address` must be represented in the following format: IPv4 dotted decimal (e.g., “192.0.2.1”). + +To validate an IP address regardless of the IP version, use the `ip` function. + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/ipv6.md.tmpl b/templates/functions/ipv6.md.tmpl index 337fa57..a3e795e 100644 --- a/templates/functions/ipv6.md.tmpl +++ b/templates/functions/ipv6.md.tmpl @@ -1,6 +1,6 @@ --- page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" -subcategory: "IP Address Functions" +subcategory: "Network Functions" description: |- {{ .Summary | plainmarkdown | trimspace | prefixlines " " }} --- @@ -9,6 +9,12 @@ description: |- {{ .Description | trimspace }} +The network function `ipv6` returns `true` if the given string is a valid IPv6 address. Otherwise, it returns `false`. + +A valid `ip_address` must be represented in the following format: standard IPv6 notation (e.g., “2001:db8::68”) or IPv4-mapped IPv6 format (e.g., “::ffff:192.0.2.1”). + +To validate an IP address regardless of the IP version, use the `ip` function. + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/key.md.tmpl b/templates/functions/key.md.tmpl index 6fa33ed..db48266 100644 --- a/templates/functions/key.md.tmpl +++ b/templates/functions/key.md.tmpl @@ -9,6 +9,8 @@ description: |- {{ .Description | trimspace }} +The map function `key` returns `true` if the given key is in the provided map. Otherwise, it returns `false`. + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/less.md.tmpl b/templates/functions/less.md.tmpl index 16f543b..1a8fdf2 100644 --- a/templates/functions/less.md.tmpl +++ b/templates/functions/less.md.tmpl @@ -9,6 +9,8 @@ description: |- {{ .Description | trimspace }} +The numeric function `less` returns `true` if the second value is less than the first value. Otherwise, it returns `false`. + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/less_or_equal.md.tmpl b/templates/functions/less_or_equal.md.tmpl index 16f543b..9740fa6 100644 --- a/templates/functions/less_or_equal.md.tmpl +++ b/templates/functions/less_or_equal.md.tmpl @@ -9,6 +9,8 @@ description: |- {{ .Description | trimspace }} +The numeric function `less_or_equal` returns `true` if the second value is less than or equal to the first value. Otherwise, it returns `false`. + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/lowercased.md.tmpl b/templates/functions/lowercased.md.tmpl index b2bdd41..a11b8fd 100644 --- a/templates/functions/lowercased.md.tmpl +++ b/templates/functions/lowercased.md.tmpl @@ -9,6 +9,8 @@ description: |- {{ .Description | trimspace }} +The string function `lowercased` returns `true` if the given string is in lowercase. Otherwise, it returns `false`. + ## Variable Validation Example {{ tffile (printf "examples/functions/%s/variable.tf" .Name)}} diff --git a/templates/functions/negative.md.tmpl b/templates/functions/negative.md.tmpl index 7b0b6d9..a729db2 100644 --- a/templates/functions/negative.md.tmpl +++ b/templates/functions/negative.md.tmpl @@ -9,6 +9,8 @@ description: |- {{ .Description | trimspace }} +The numeric function `positive` returns `true` if the given value is positive. Otherwise, it returns `false`. + ## Variable Validation Example {{ tffile (printf "examples/functions/%s/variable.tf" .Name)}} diff --git a/templates/functions/not_empty.md.tmpl b/templates/functions/not_empty.md.tmpl index 5649efe..1513d70 100644 --- a/templates/functions/not_empty.md.tmpl +++ b/templates/functions/not_empty.md.tmpl @@ -9,6 +9,10 @@ description: |- {{ .Description | trimspace }} +The string function `not_empty` returns `true` if the given string is not empty. Otherwise, it returns `false`. + +A string is considered empty if it is initialized, not null, and has a length of zero characters. + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/not_equal.md.tmpl b/templates/functions/not_equal.md.tmpl index 16f543b..b1cbf84 100644 --- a/templates/functions/not_equal.md.tmpl +++ b/templates/functions/not_equal.md.tmpl @@ -9,6 +9,8 @@ description: |- {{ .Description | trimspace }} +The numeric function `not_equal` returns `true` if the given values are not equal. Otherwise, it returns `false`. + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/not_null.md.tmpl b/templates/functions/not_null.md.tmpl index 192de73..98b5ba4 100644 --- a/templates/functions/not_null.md.tmpl +++ b/templates/functions/not_null.md.tmpl @@ -9,6 +9,10 @@ description: |- {{ .Description | trimspace }} +The `not_null` function returns `true` if the given value is not a null value. Otherwise, it returns `false`. + +In Terraform, the null value type represents the absence or omission of a value. You can explicitly set a resource argument to `null` to indicate that no value is provided. + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/null.md.tmpl b/templates/functions/null.md.tmpl index 192de73..5516681 100644 --- a/templates/functions/null.md.tmpl +++ b/templates/functions/null.md.tmpl @@ -9,6 +9,10 @@ description: |- {{ .Description | trimspace }} +The null function `null` returns `true` if the given value is a null value. Otherwise, it returns `false`. + +In Terraform, the null value type represents the absence or omission of a value. You can explicitly set a resource argument to `null` to indicate that no value is provided. + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/positive.md.tmpl b/templates/functions/positive.md.tmpl index 7b0b6d9..4185748 100644 --- a/templates/functions/positive.md.tmpl +++ b/templates/functions/positive.md.tmpl @@ -9,6 +9,8 @@ description: |- {{ .Description | trimspace }} +This numeric function `positive` returns `true` if the given value is positive. Otherwise, it returns `false`. + ## Variable Validation Example {{ tffile (printf "examples/functions/%s/variable.tf" .Name)}} diff --git a/templates/functions/regex.md.tmpl b/templates/functions/regex.md.tmpl index 5649efe..f043c6b 100644 --- a/templates/functions/regex.md.tmpl +++ b/templates/functions/regex.md.tmpl @@ -9,6 +9,10 @@ description: |- {{ .Description | trimspace }} +The string function regex returns true if the given string matches the regular expression pattern; otherwise, it returns false. To perform a substring match, use the regular expression without anchoring the pattern. + +Learn more about regular expressions in the [Terraform documentation](https://www.terraform.io/docs/language/functions/regex.html). + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/starts_with.md.tmpl b/templates/functions/starts_with.md.tmpl index 5649efe..0e5dbb9 100644 --- a/templates/functions/starts_with.md.tmpl +++ b/templates/functions/starts_with.md.tmpl @@ -9,6 +9,8 @@ description: |- {{ .Description | trimspace }} +The string function `starts_with` returns true if the given string starts with the provided prefix. Otherwise, it returns `false`. + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/true.md.tmpl b/templates/functions/true.md.tmpl index 4e4cbaf..c33e9d8 100644 --- a/templates/functions/true.md.tmpl +++ b/templates/functions/true.md.tmpl @@ -9,6 +9,8 @@ description: |- {{ .Description | trimspace }} +The boolean function `true` returns `true` if the specified value or expression evaluates to `true`; otherwise, it returns `false`. + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/uppercased.md.tmpl b/templates/functions/uppercased.md.tmpl index b2bdd41..29dd6f9 100644 --- a/templates/functions/uppercased.md.tmpl +++ b/templates/functions/uppercased.md.tmpl @@ -9,6 +9,8 @@ description: |- {{ .Description | trimspace }} +The string function `uppercsaed` returns `true` if the given string is in uppercase. Otherwise, it returns `false`. + ## Variable Validation Example {{ tffile (printf "examples/functions/%s/variable.tf" .Name)}} diff --git a/templates/functions/valid_json.md.tmpl b/templates/functions/valid_json.md.tmpl index 44c395a..ecd3a6e 100644 --- a/templates/functions/valid_json.md.tmpl +++ b/templates/functions/valid_json.md.tmpl @@ -9,6 +9,8 @@ description: |- {{ .Description | trimspace }} +The data validation function `valid_json` returns `true` if the given string is a valid JSON. Otherwise, it returns `false`. + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/valid_yaml.md.tmpl b/templates/functions/valid_yaml.md.tmpl index 44c395a..1eab87d 100644 --- a/templates/functions/valid_yaml.md.tmpl +++ b/templates/functions/valid_yaml.md.tmpl @@ -9,6 +9,8 @@ description: |- {{ .Description | trimspace }} +The data validation function `valid_yaml` returns `true` if the given string is a valid YAML. Otherwise, it returns `false`. + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/functions/value.md.tmpl b/templates/functions/value.md.tmpl index 6fa33ed..7d090c7 100644 --- a/templates/functions/value.md.tmpl +++ b/templates/functions/value.md.tmpl @@ -9,6 +9,8 @@ description: |- {{ .Description | trimspace }} +The map function `value` returns `true` if the given value is present in the map. Otherwise, it returns `false`. + {{ if .HasExample -}} ## Terraform Test Example diff --git a/templates/index.md.tmpl b/templates/index.md.tmpl index d5c2553..a660ab4 100644 --- a/templates/index.md.tmpl +++ b/templates/index.md.tmpl @@ -6,10 +6,9 @@ description: |- # Assert Provider -The Assert provider is a utility provider that helps practitioners -to simplify the way they write assertions in their Terraform configurations. +The Assert provider for Terraform is a utility provider that offers a comprehensive set of assertion capabilities through provider-defined functions such as [http_success](https://registry.terraform.io/providers/hashicorp/assert/latest/docs/functions/http_success), [expired](https://registry.terraform.io/providers/hashicorp/assert/latest/docs/functions/expired), and [between](https://registry.terraform.io/providers/hashicorp/assert/latest/docs/functions/between). These assertion functions simplify your Terraform configurations, making variable validation, continuous validation, and testing easier. -This provider is typically used in Terraform test assertions or variable validation. +The Assert provider functions complement Terraform’s [built-in](https://developer.hashicorp.com/terraform/language/functions) functions rather than replacing them. If Terraform’s built-in functions better fit your requirements, they should be your choice. This provider does not manage any infrastructure, but instead provides a set of provider-defined functions that can be used to assert that values in Terraform configurations. @@ -20,9 +19,12 @@ Use the navigation to the left to read about the available resources. As of Terraform 1.8 and later, providers can implement functions that you can call from the Terraform configuration. -Define the provider as a `required_provider` to use its functions +To use the Assert provider, declare it as a `required_provider` in the `terraform {}` block: {{ tffile "examples/provider/provider.tf" }} -## Limitations +## Function Syntax +You use the functions with a special syntax: `provider::assert::`. + +For instance, to check if an HTTP status code falls within the success range, use the `http_success` function and call it using `provider::assert::http_success(data.http.example.status_code)`.