You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are also some functions that can be used with the AWS and Azure providers in [aws-functions](./aws/aws-functions) and [azure-functions](./azure/azure-functions).
36
+
There are also some functions that can be used with the AWS and Azure providers in [aws-functions](./aws/aws-functions) and [azure-functions](./azure/azure-functions) and some functions that can be used when talking to module registries in [registry-functions](./cloud-agnostic/http-examples/registry-functions).
37
37
38
38
Unlike the second-generation common functions that were each defined in a separate file, all of the common functions that use any of the 4 Terraform Sentinel imports (tfplan/v2, tfstate/v2, tfconfig/v2, and tfrun) are defined in a single file. This makes it easier to import all of the functions that use one of those imports into the Sentinel CLI test cases and Terraform Cloud policy sets, since those only need a single stanza such as this one for each module:
39
39
```
@@ -57,8 +57,9 @@ import "tfconfig-functions" as config
57
57
import "tfrun-functions" as run
58
58
import "aws-functions" as aws
59
59
import "azure-functions" as azure
60
+
import "registry-functions" as registry
60
61
```
61
-
In this case, we are using `plan`, `state`, `config`, `run`, `aws`, and `azure` as aliases for the six imports to keep lines that use their functions shorter. Of course, you only need to import the modules that contain functions that your policy actually calls.
62
+
In this case, we are using `plan`, `state`, `config`, `run`, `aws`, `azure`, and `registry` as aliases for the seven imports to keep lines that use their functions shorter. Of course, you only need to import the modules that contain functions that your policy actually calls.
62
63
63
64
### The Functions of the tfplan-functions and tfstate-functions Modules
64
65
We discuss these two modules together because they are essentially identical except for their use of the tfplan/v2 and tfstate/v2 imports.
@@ -109,7 +110,7 @@ Documentation for each individual function can be found in this directory:
The `aws-functions` module (which is located under in the aws/aws-functions directory) has the following functions:
113
+
The `aws-functions` module (which is located in the aws/aws-functions directory) has the following functions:
113
114
* The `find_resources_with_standard_tags` function finds all AWS resources of specified types that should have tags in the current plan that are not being permanently deleted.
114
115
* The `determine_role_arn` function determines the ARN of a role set in the `role_arn` parameter of an AWS provider. It can only determine the role_arn if it is set to either a hard-coded value or to a reference to a single Terraform variable. It sets the role to "complex" if it finds a single non-variable reference or if it finds multiple references. It sets the role to "none" if no role arn is found.
115
116
* The `get_assumed_roles` function gets all roles assumed by AWS providers in the current Terraform configuration. It calls the `determine_role_arn` function.
@@ -120,12 +121,22 @@ Documentation for each individual function can be found in this directory:
120
121
*[aws-functions](./aws/aws-functions/docs)
121
122
122
123
### The Functions of the azure-functions Module
123
-
The `azure-functions` module (which is located under in the azure/azure-functions directory) has the following functions:
124
+
The `azure-functions` module (which is located in the azure/azure-functions directory) has the following functions:
124
125
* The `find_resources_with_standard_tags` function finds all Azure resources of specified types that should have tags in the current plan that are not being permanently deleted.
125
126
126
127
Documentation for each individual function can be found in this directory:
127
128
*[azure-functions](./azure/azure-functions/docs)
128
129
130
+
### The Functions of the registry-functions Module
131
+
The `registry-functions` module (which is located in the cloud-agnostic/http-examples/registry-functions directory) has the following functions:
132
+
* The `get_recent_module_versions` function finds recent versions for private or public modules from a private module registry (PMR).
133
+
* The `get_recent_module_versions_by_page` function finds recent versions for private or public modules from a private module registry (PMR) one page at a time. It is called by the `get_recent_module_versions` function. Having a separate function that deals with pagination keeps the interface for the `get_recent_module_versions` function cleaner.
134
+
* The `find_most_recent_version` function finds the most recent versing string from a map of version strings.
135
+
* The `is_module_in_public_registry` function determines if a module is in the public module registry.
136
+
137
+
Documentation for each individual function can be found in this directory:
Sentinel [mock files](https://www.terraform.io/docs/enterprise/sentinel/mock.html) and [test cases](https://docs.hashicorp.com/sentinel/commands/config#test-cases) have been provided under the test directory of each cloud so that all the policies can be tested with the [Sentinel CLI](https://docs.hashicorp.com/sentinel/commands). The mocks were generated from actual Terraform 0.12 plans run against Terraform code that provisioned resources in these clouds. The pass and fail mock files were edited to respectively pass and fail the associated Sentinel policies. Some policies, including those that have multiple rules, have multiple fail mock files with names that indicate which condition or conditions they fail.
0 commit comments