Link Search Menu Expand Document

WHEN

WHEN used to define the condition that you are searching for. It could be either a filtering condition or you might be looking for a specific property on a resource, or any property on any entity that has been transferred via GIVEN directive. WHEN must come after GIVEN directive.

WHEN steps does not fail any scenario. It sets the condition for the further steps.

WHEN can be used multiple times, either with using WHEN or AND

Few examples can be ;

When I count them
When its name is my-bucket
When it contains server_side_encryption

Using WHEN is optional. You might have some use cases that only a GIVEN and some THEN directives could be enough for you.

You can use AND with WHEN.

Depending on use a Scenario Outline instead of a Scenario, it can also be a variable like ;

When it contains <some_property>

In case a WHEN step fails to complete, then the step and further steps will be SKIPPED. Skipped steps won’t fail terraform-compliance. It means the definition criteria (not the testing criteria) defined in your Scenario does not met with the infrastructure plan.

Reference

When it contains something

will be deprecated soon

Possible sentences :

When it contain something

When it contains something

key Description Examples
something any property within Terraform resource/provider/etc access_key ingress "something with spaces"

When it has something

1.2.+

This is a filtering function where the resources from previous step will be filtered based on the “something” key exist in the resource properties.

Possible sentences :

When it has something

When they have something

key Description Examples
something any property within Terraform resource/provider/etc access_key ingress "something with spaces"

When it does not have something

1.2.+

This is a filtering function where the resources from previous step will be filtered based on the “something” key not existing in the resource properties.

Possible sentences :

When it does not contain something

When it doesnt contain something

When it does not have something

When it doesnt have something

When they do not have something

When they dont have something

key Description Examples
something any property within Terraform source/provider/etc access_key ingress "something with spaces"

When its property has something

This is a filtering function. Thus, found resources from previous step will be filtered based on these values.

Possible sentences :

When its property is something

When its property has something

When its property includes something

When its property consists something

When its property is “ some string with spaces

When its property has “ some string with spaces

When its property includes “ some string with spaces

When its property consists “ some string with spaces

When its dictionary includes an entry where “ key “ is “ value

key Description Examples
property any property that resources have. Using type will give the Terraform resource type; address is the name you have given it address name size
dictionary a dictionary property that resource has. tags
something any string or numeric value that the property has. s3_my_bucket my-bucket 50G "something with spaces"
some string with spaces any string (allows spaces). my dictionary key
key any dictionary key (allows spaces). my dictionary key
value any dictionary value (allows spaces). my dictionary value

When its property reference has something

This is a filtering function, specific for resource referencing. The resource references will be checked based on the property property defined within the step.

Possible sentences :

When its property reference is something

When its property reference has something

When its property reference includes something

When its property reference consists something

When its property reference is “ some string with spaces

When its property reference has “ some string with spaces

When its property reference includes “ some string with spaces

When its property reference consists “ some string with spaces

key Description Examples
property any property that is used for referencing another resource. security_group_id aws_instance "something with spaces"
something any string or numeric value that the property has. s3_my_bucket my-bucket 50G "something with spaces"
some string with spaces any string (allows spaces). my dictionary key

When its property has not something

This is a filtering function. Thus, found resources from previous step will be filtered based on these values.

Possible sentences :

When its property is not something

When its property has not something

When its property does not include something

When its property does not consist something

When its property is not “ some string with spaces

When its property has not “ some string with spaces

When its property does not include “ some string with spaces

When its property does not consist “ some string with spaces

When its dictionary does not include an entry where “ key “ is “ value

key Description Examples
property any property that resources have. Using type will give the Terraform resource type; address is the name you have given it address name size
dictionary a dictionary property that resource has. tags
something any string or numeric value that the property has. s3_my_bucket my-bucket 50G "something with spaces"
some string with spaces any string (allows spaces). my dictionary key
key any dictionary key (allows spaces). my dictionary key
value any dictionary value (allows spaces). my dictionary value

When its property reference has something

This is a filtering function, specific for resource referencing. The resource references will be checked based on the property property defined within the step. This is the negative version (ref. not usage within the step) of the filtering step.

Possible sentences :

When its property reference is not something

When its property reference has not something

When its property reference does not include something

When its property reference does not consist something

When its property reference is not “ some string with spaces

When its property reference has not “ some string with spaces

When its property reference does not include “ some string with spaces

When its property reference does not consist “ some string with spaces

key Description Examples
property any property that is used for referencing another resource. security_group_id aws_instance "something with spaces"
something any string or numeric value that the property has. s3_my_bucket my-bucket 50G "something with spaces"
some string with spaces any string (allows spaces). my dictionary key

When I action them

This step is for mathematical operations. Currently it is only supported for count

Possible sentences :

When I action them

When I action it

When I action the value

key Description Examples
action mathematical operation currently only supports for count

terraform-compliance made with . Distributed by an MIT license.