Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding 2 policies to check workspace versions are greater than or equ… #39

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Many policies contain arrays of values that are checked against resources. The a
| [management/workspace_name.rego](https://github.com/Scalr/sample-tf-opa-policies/blob/master/management/workspace_name.rego) | Simple example of using `tfrun` data and validating a workspace name. |
| [management/workspace_destroy.rego](https://github.com/Scalr/sample-tf-opa-policies/blob/master/management/workspace_destroy.rego) | Checks workspace has an active state and denies its destroy, if active state is present. |
| [management/workspace_tags.rego](https://github.com/Scalr/sample-tf-opa-policies/blob/master/management/workspace_tags.rego) | Checks workspace is tagged with provider name. |
| [management/terraform_min_version.rego](https://github.com/Scalr/sample-tf-opa-policies/blob/master/management/terraform_min_version.rego) | Checks the workspace is not using an older version of Terraform. |
| [management/terraform_min_version.rego](https://github.com/Scalr/sample-tf-opa-policies/blob/master/management/terraform_min_version.rego) | Suggests when a workspace is should be using a newer version of Terraform |
petroprotsakh marked this conversation as resolved.
Show resolved Hide resolved
| [modules/pin_module_version.rego](https://github.com/Scalr/sample-tf-opa-policies/blob/master/modules/pin_module_version.rego) | Enforces use of specific module versions. |
| [modules/required_modules.rego](https://github.com/Scalr/sample-tf-opa-policies/blob/master/modules/required_modules.rego) | Checks resources are only be created via specific modules. |
| [placement/cloud_location.rego](https://github.com/Scalr/sample-tf-opa-policies/blob/master/placement/cloud_location.rego) | Checks resources are deployed to specific regions in each cloud. |
Expand Down
13 changes: 13 additions & 0 deletions management/terraform_min_version.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package terraform

import input.tfplan as tfplan

min_version = "1.0.0"

# Matches that minimum version is met
deny[reason] {

semver.compare(tfplan.terraform_version, min_version) < 0

reason := sprintf("Terraform version %s is not allowed. Please pick a version equal to or greater than %s", [tfplan.terraform_version, min_version])
}
16 changes: 16 additions & 0 deletions management/terraform_min_version_mock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"mock":{
"not_allowed_version":{
"tfplan":{
"format_version":"0.1",
"terraform_version":"0.13.0"
}
},
"allowed_version":{
"tfplan":{
"format_version":"0.1",
"terraform_version":"1.3.5"
}
}
}
}
11 changes: 11 additions & 0 deletions management/terraform_min_version_test.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package terraform

test_not_allowed_versions {
result = deny with input as data.mock.not_allowed_version
count(result) == 1
}

test_allowed_versions {
result = deny with input as data.mock.allowed_version
count(result) == 0
}