What functions can we use to process port ranges in a list?

There was a similar question raised at GCP Policy gcp-cis-3.6-networking-ssh-is-restricted-from-internet.sentinel does not detect port in range · Issue #49 · hashicorp/terraform-foundational-policies-library · GitHub

Objective is to detect ports 22 and port 3389 in the list below

ports = [“80”, “20-30”, “3000-4000”, “8080”]

I’m not able to find any ready functions we could use.

Suggestions are appreciated.


We don’t have any out-of-box functions for working with port ranges but the following example may help get you started.

Thank you for the input.
I’m aware of the standard functions and 3rd generation policies in Github with common functions. Where can I find out the source code (Github URL ?) to read more on import “ports”, import “strings” etc…?

As I mentioned in my original post, we do not have a module for working with ports.

I created the ports module for you on the fly as a means of helping you get started. You can copy the source code from the example mock I have provided and create your own module that you can reuse in your policies.

We welcome contributions so if you would like to give back to the community, please raise a PR on the terraform-sentinel-policies repository.

Regarding the strings import, you can read more about the Sentinel standard import library in the Sentinel imports documentation


There’s a related separate question and we’ll address it on another discussion.

Thank you!