terraform-compliance / cli

a lightweight, security focused, BDD test framework against terraform.
https://terraform-compliance.com
MIT License
1.34k stars 151 forks source link

Is there a better way to write this scenario in terms of clarity? #636

Closed j4t1nd3r closed 3 months ago

j4t1nd3r commented 2 years ago

I have the following reg ex which matches on multiple naming conventions:

    [a-z]{2}aip(dev|test|uat|prod)[a-z]{3}
    [a-z]{2,4}-aip-(dev|test|uat|prod)           
    [a-z]{2,4}-aip-([a-z]{2})-(dev|test|uat|prod)

I want to make sure every resource in the plan file adheres to one of these 3 naming conventions. I may add more conventions in the future. I got the following scenario that works:

Scenario: Ensure that resource names follow naming conventions
        Gives I have resources defined
        When it has name
        Then it must have name
        Then its value must match the "([a-z]{2}aip(dev|test|uat|prod)[a-z]{3})|([a-z]{2,4}-aip-(dev|test|uat|prod))|([a-z]{2,4}-aip-([a-z]{2})-(dev|test|uat|prod))" regex

However its not very readable. Is there a better way of writing this that potentially would involve an example table? It needs to match one of them. If a resource does not match any of these then the test should throw a fail.

j4t1nd3r commented 3 months ago

no longer relevant, closing.