{"id":13500404,"url":"https://github.com/xchapter7x/clarity","last_synced_at":"2026-01-26T21:26:31.490Z","repository":{"id":48858168,"uuid":"171977858","full_name":"xchapter7x/clarity","owner":"xchapter7x","description":"A declaritive test framework for Terraform","archived":false,"fork":false,"pushed_at":"2021-07-08T10:59:48.000Z","size":195,"stargazers_count":141,"open_issues_count":3,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-14T22:41:15.303Z","etag":null,"topics":["hcl","hcl2","terraform","terraform-tests","unit-test","unittest"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xchapter7x.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-22T02:08:53.000Z","updated_at":"2025-07-04T03:54:23.000Z","dependencies_parsed_at":"2022-09-03T14:22:18.596Z","dependency_job_id":null,"html_url":"https://github.com/xchapter7x/clarity","commit_stats":null,"previous_names":[],"tags_count":66,"template":false,"template_full_name":null,"purl":"pkg:github/xchapter7x/clarity","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xchapter7x%2Fclarity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xchapter7x%2Fclarity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xchapter7x%2Fclarity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xchapter7x%2Fclarity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xchapter7x","download_url":"https://codeload.github.com/xchapter7x/clarity/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xchapter7x%2Fclarity/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28788370,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T21:13:08.818Z","status":"ssl_error","status_checked_at":"2026-01-26T21:13:08.448Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hcl","hcl2","terraform","terraform-tests","unit-test","unittest"],"created_at":"2024-07-31T22:00:58.963Z","updated_at":"2026-01-26T21:26:31.455Z","avatar_url":"https://github.com/xchapter7x.png","language":"Go","funding_links":[],"categories":["Go","Testing"],"sub_categories":["Community providers"],"readme":"# Clarity\n[![CircleCI](https://circleci.com/gh/xchapter7x/clarity.svg?style=svg)](https://circleci.com/gh/xchapter7x/clarity)\n\n## A declaritive test framework for Terraform\n- reason: B/c unit testing terraform needs to be a thing\n\n## Info:\n- its a single binary, thats it. no need to write steps or go code. just write a declarative feature file.\n- good for writing fitness function tests on your HCL\n- its gherkin bdd inspired\n- provides its own matchers and hcl parser\n- must be run from the directory where your terraform files live\n- its a wrapper on [godog](https://github.com/DATA-DOG/godog), which provides built in terraform specific steps\n\n## Install\n\n```bash\n$ export OS=\"osx\" #(osx | unix)\n$ curl -sL https://github.com/xchapter7x/clarity/releases/latest/download/clarity_${OS} -o /usr/local/bin/clarity \u0026\u0026 chmod +x /usr/local/bin/clarity\n```\n\n### Download Binaries\n[HERE](https://github.com/xchapter7x/clarity/releases/latest)\n\n### CLI Options\n\n```\n-\u003e % clarity --help\nUsage:\n  godog [options] [\u003cfeatures\u003e]\n\nBuilds a test package and runs given feature files.\nCommand should be run from the directory of tested package and contain buildable go source.\n\nArguments:\n  features             Optional feature(s) to run. Can be:\n                           - dir (features/)\n                           - feature (*.feature)\n                           - scenario at specific line (*.feature:10)\n                       If no feature paths are listed, suite tries features path by default.\n\nOptions:\n  -c, --concurrency=1  Run the test suite with concurrency level:\n                           - = 1: supports all types of formats.\n                           - \u003e= 2: only supports progress. Note, that\n                           your context needs to support parallel execution.\n  -d, --definitions    Print all available step definitions.\n  -f, --format=pretty  How to format tests output. Built-in formats:\n                           - events: Produces JSON event stream, based on spec: 0.1.0.\n                           - junit: Prints junit compatible xml to stdout\n                           - pretty: Prints every feature with runtime statuses.\n                           - progress: Prints a character per step.\n                           - cucumber: Produces cucumber JSON format output.\n  --no-colors          Disable ansi colors.\n  --random[=SEED]      Randomly shuffle the scenario execution order.\n                       Specify SEED to reproduce the shuffling from a previous run.\n                           e.g. --random or --random=5738\n  --stop-on-failure    Stop processing on first failed scenario.\n  --strict             Fail suite when there are pending or undefined steps.\n  -t, --tags=          Filter scenarios by tags. Expression can be:\n                           - \"@wip\": run all scenarios with wip tag\n                           - \"~@wip\": exclude all scenarios with wip tag\n                           - \"@wip \u0026\u0026 ~@new\": run wip scenarios, but exclude new\n                           - \"@wip,@undone\": run wip or undone scenarios\n```\n\n### Writting your terraform tests\n\nSimply put a .feature file in the directory where the terraform you wish to test resides\n```gherkin\n$ ls\ncontrol_plane.feature dns.tf                lb.tf                 network.tf            outputs.tf            variables.tf\n\n$ cat terraform/modules/control_plane.feature\n\nFeature: We should have a LB for our control plane and its components and as\n  such we should configure the proper security groups and listeners\n\n  Scenario: we are using a single LB to route to all control plane components\n    Given Terraform\n    And a \"aws_lb\" of type \"resource\"\n    Then attribute \"load_balancer_type\" equals \"network\"\n    And it occurs exactly 1 times\n\n  Scenario Outline: Every component of the control plane which needs a LB\n    should be properly configured to have one\n\n    Given Terraform\n    And a \"aws_security_group\" of type \"resource\"\n    And \"our component is \u003ccomponent\u003e\"\n    When attribute \"ingress\" exists\n    Then attribute \"ingress\" matches regex \"from_port.*\u003cport\u003e\"\n    And attribute \"ingress\" matches regex \"to_port.*\u003cport\u003e\"\n\n    Given Terraform\n    And a \"aws_lb_listener\" of type \"resource\"\n    And \"our component is \u003ccomponent\u003e\"\n    Then attribute \"port\" equals \u003cport\u003e\n\n    Given Terraform\n    And  a \"aws_lb_target_group\" of type \"resource\"\n    And \"our component is \u003ccomponent\u003e\"\n    Then attribute \"port\" equals \u003cport\u003e\n\n    Examples:\n    | port | component |\n    | 443  | ATC       |\n    | 80   | ATC       |\n    | 8443 | UAA       |\n    | 2222 | TSA       |\n    | 8844 | CredHub   |\n```\n\n### Running your terraform tests\n\nUse the clarity cli to run any feature files you wish\n```bash\n-\u003e % clarity control_plane.feature\nFeature: We should have a LB for our control plane and its components and as\n  such we should configure the proper security groups and listeners\n\n  Scenario: we are using a single LB to route to all control plane components # control_plane.feature:4\n    Given Terraform                                                           # clarity_test.go:15 -\u003e *Match\n    And a \"aws_lb\" of type \"resource\"                                         # clarity_test.go:16 -\u003e *Match\n    Then attribute \"load_balancer_type\" equals \"network\"                      # clarity_test.go:19 -\u003e *Match\n    And it occurs exactly 1 times                                             # clarity_test.go:24 -\u003e *Match\n\n  Scenario Outline: Every component of the control plane which needs a LB # control_plane.feature:10\n    Given Terraform                                                       # clarity_test.go:15 -\u003e *Match\n    And a \"aws_security_group\" of type \"resource\"                         # clarity_test.go:16 -\u003e *Match\n    And \"our component is \u003ccomponent\u003e\"                                    # clarity_test.go:9 -\u003e noopComment\n    When attribute \"ingress\" exists                                       # clarity_test.go:21 -\u003e *Match\n    Then attribute \"ingress\" matches regex \"from_port.*\u003cport\u003e\"            # clarity_test.go:25 -\u003e *Match\n    And attribute \"ingress\" matches regex \"to_port.*\u003cport\u003e\"               # clarity_test.go:25 -\u003e *Match\n    Given Terraform                                                       # clarity_test.go:15 -\u003e *Match\n    And a \"aws_lb_listener\" of type \"resource\"                            # clarity_test.go:16 -\u003e *Match\n    And \"our component is \u003ccomponent\u003e\"                                    # clarity_test.go:9 -\u003e noopComment\n    Then attribute \"port\" equals \u003cport\u003e                                   # clarity_test.go:17 -\u003e *Match\n    Given Terraform                                                       # clarity_test.go:15 -\u003e *Match\n    And a \"aws_lb_target_group\" of type \"resource\"                        # clarity_test.go:16 -\u003e *Match\n    And \"our component is \u003ccomponent\u003e\"                                    # clarity_test.go:9 -\u003e noopComment\n    Then attribute \"port\" equals \u003cport\u003e                                   # clarity_test.go:17 -\u003e *Match\n\n    Examples:\n      | port | component |\n      | 443  | ATC       |\n      | 80   | ATC       |\n      | 8443 | UAA       |\n      | 2222 | TSA       |\n      | 8844 | CredHub   |\n\n6 scenarios (6 passed)\n74 steps (74 passed)\n35.093777ms\n```\n\n### gherkin step matchers available\n\t| '([^\"]*)'                                       \t\t| noop to insert context into behavior def                     |\n\t| 'HCL2'                                         \t\t| parses the hcl2 from your local dir                     |\n\t| 'Terraform'                                     \t\t| parses the terraform \u003c=.11 from your local dir                     |\n\t| 'pending \"([^\"]*)\"$'                            \t\t| mark pending and skip all following steps in the scenario    |\n\t| 'a \"([^\"]*)\" of type \"([^\"]*)\"'                 \t\t| matches on types such as resource,data and the resource name |\n\t| 'a \"([^\"]*)\" of type \"([^\"]*)\" named \"([^\"]*)\"' \t\t| matches on types, resource names and instance names          |\n\t| 'the value of \"([^\"]*)\" always equals (\\d+)'          \t| matches on the value given and the value of the attribute    |\n\t| 'the value of \"([^\"]*)\" never equals (\\d+)'      \t\t| inverse match on attr value and given value                  |\n\t| 'the value of \"([^\"]*)\" always equals \"([^\"]*)\"'      \t| matches on the value given and the value of the attribute    |\n\t| 'the value of \"([^\"]*)\" never equals \"([^\"]*)\"'  \t\t| inverse match on attr value and given value                  |\n\t| 'the value of \"([^\"]*)\" always matches regex \"([^\"]*)\"'   \t| matches the attributes value on the given regex              |\n\t| 'the value of \"([^\"]*)\" is always greater than (\\d+)'     \t| matches on gt against the given value and attr value         |\n\t| 'the value of \"([^\"]*)\" is always less than (\\d+)'        \t| matches on lt against the given value and attr value         |\n\t| 'attribute \"([^\"]*)\" always equals (\\d+)'              \t| matches on the value given and the value of the attribute    |\n\t| 'attribute \"([^\"]*)\" never equals (\\d+)'      \t\t| inverse match on attr value and given value                  |\n\t| 'attribute \"([^\"]*)\" always equals \"([^\"]*)\"'          \t| matches on the value given and the value of the attribute    |\n\t| 'attribute \"([^\"]*)\" never equals \"([^\"]*)\"'  \t\t| inverse match on attr value and given value                  |\n\t| 'attribute \"([^\"]*)\" always matches regex \"([^\"]*)\"'   \t| matches the attributes value on the given regex              |\n\t| 'attribute \"([^\"]*)\" is always greater than (\\d+)'     \t| matches on gt against the given value and attr value         |\n\t| 'attribute \"([^\"]*)\" is always less than (\\d+)'        \t| matches on lt against the given value and attr value         |\n\t| 'the value of \"([^\"]*)\" equals (\\d+)'              \t\t| matches on the value given and the value of the attribute    |\n\t| 'the value of \"([^\"]*)\" does not equal (\\d+)'      \t\t| inverse match on attr value and given value                  |\n\t| 'the value of \"([^\"]*)\" equals \"([^\"]*)\"'          \t\t| matches on the value given and the value of the attribute    |\n\t| 'the value of \"([^\"]*)\" does not equal \"([^\"]*)\"'  \t\t| inverse match on attr value and given value                  |\n\t| 'the value of \"([^\"]*)\" matches regex \"([^\"]*)\"'   \t\t| matches the attributes value on the given regex              |\n\t| 'the value of \"([^\"]*)\" is greater than (\\d+)'     \t\t| matches on gt against the given value and attr value         |\n\t| 'the value of \"([^\"]*)\" is less than (\\d+)'        \t\t| matches on lt against the given value and attr value         |\n\t| 'attribute \"([^\"]*)\" equals (\\d+)'              \t\t| matches on the value given and the value of the attribute    |\n\t| 'attribute \"([^\"]*)\" does not equal (\\d+)'      \t\t| inverse match on attr value and given value                  |\n\t| 'attribute \"([^\"]*)\" equals \"([^\"]*)\"'          \t\t| matches on the value given and the value of the attribute    |\n\t| 'attribute \"([^\"]*)\" does not equal \"([^\"]*)\"'  \t\t| inverse match on attr value and given value                  |\n\t| 'attribute \"([^\"]*)\" matches regex \"([^\"]*)\"'   \t\t| matches the attributes value on the given regex              |\n\t| 'attribute \"([^\"]*)\" is greater than (\\d+)'     \t\t| matches on gt against the given value and attr value         |\n\t| 'attribute \"([^\"]*)\" is less than (\\d+)'        \t\t| matches on lt against the given value and attr value         |\n\t| 'attribute \"([^\"]*)\" exists'                    \t\t| if the given attribute exists in the matching objects        |\n\t| 'it occurs at least (\\d+) times'                \t\t| if the match set contains at least the given number          |\n\t| 'it occurs at most (\\d+) times'                 \t\t| if the match set contains at most the given number           |\n\t| 'it occurs exactly (\\d+) times'                 \t\t| if the match set continas exactly the given number           |\n\n## Development \u0026 Contributions:\n- all issues and PRs welcome.\n\n\n### Run the Tests\n```bash\n$ make unit\n```\n\n### Build the binary\n```bash\n$ make build\n```\n\n\n\n\n## For more complete testing support using OPA policies check out:\nhttps://github.com/instrumenta/conftest\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxchapter7x%2Fclarity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxchapter7x%2Fclarity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxchapter7x%2Fclarity/lists"}