generated from terraform-linters/tflint-ruleset-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `terraform.imports` function * Add `terraform.checks` function
- Loading branch information
Showing
16 changed files
with
628 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
plugin "terraform" { | ||
enabled = false | ||
} | ||
|
||
plugin "opa" { | ||
enabled = true | ||
|
||
policy_dir = "policies" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
check "health_check" { | ||
data "http" "terraform_io" { | ||
url = "https://www.terraform.io" | ||
} | ||
|
||
assert { | ||
condition = data.http.terraform_io.status_code == 200 | ||
error_message = "${data.http.terraform_io.url} returned an unhealthy status code" | ||
} | ||
} | ||
|
||
check "deterministic" { | ||
assert { | ||
condition = 200 == 200 | ||
error_message = "condition should be true" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package tflint | ||
|
||
deny_deterministic_check_condition[issue] { | ||
checks := terraform.checks({"assert": {"condition": "bool"}}, {}) | ||
condition = checks[_].config.assert[_].config.condition | ||
condition.unknown == false | ||
|
||
issue := tflint.issue("deterministic check condtion is not allowed", condition.range) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package tflint | ||
import future.keywords | ||
|
||
mock_checks(schema, options) := terraform.mock_checks(schema, options, {"main.tf": ` | ||
check "deterministic" { | ||
assert { | ||
condition = 200 == 200 | ||
error_message = "condition should be true" | ||
} | ||
}`}) | ||
|
||
test_deny_deterministic_check_condition_passed if { | ||
issues := deny_deterministic_check_condition with terraform.checks as mock_checks | ||
|
||
count(issues) == 1 | ||
issue := issues[_] | ||
issue.msg == "deterministic check condtion is not allowed" | ||
} | ||
|
||
test_deny_deterministic_check_condition_failed if { | ||
issues := deny_deterministic_check_condition with terraform.checks as mock_checks | ||
|
||
count(issues) == 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"issues": [ | ||
{ | ||
"rule": { | ||
"name": "opa_deny_deterministic_check_condition", | ||
"severity": "error", | ||
"link": "policies/main.rego:3" | ||
}, | ||
"message": "deterministic check condtion is not allowed", | ||
"range": { | ||
"filename": "main.tf", | ||
"start": { | ||
"line": 14, | ||
"column": 17 | ||
}, | ||
"end": { | ||
"line": 14, | ||
"column": 27 | ||
} | ||
}, | ||
"callers": [] | ||
} | ||
], | ||
"errors": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"issues": [ | ||
{ | ||
"rule": { | ||
"name": "opa_test_deny_deterministic_check_condition_failed", | ||
"severity": "error", | ||
"link": "policies/main_test.rego:20" | ||
}, | ||
"message": "test failed", | ||
"range": { | ||
"filename": "", | ||
"start": { | ||
"line": 0, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 0, | ||
"column": 0 | ||
} | ||
}, | ||
"callers": [] | ||
} | ||
], | ||
"errors": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
plugin "terraform" { | ||
enabled = false | ||
} | ||
|
||
plugin "opa" { | ||
enabled = true | ||
|
||
policy_dir = "policies" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { | ||
to = aws_instance.example | ||
id = "i-abcd1234" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package tflint | ||
|
||
deny_import_blocks[issue] { | ||
imports := terraform.imports({}, {}) | ||
count(imports) > 0 | ||
|
||
issue := tflint.issue("import blocks are not allowed", imports[0].decl_range) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package tflint | ||
import future.keywords | ||
|
||
mock_imports(schema, options) := terraform.mock_imports(schema, options, {"main.tf": ` | ||
import { | ||
to = aws_instance.example | ||
id = "i-abcd1234" | ||
}`}) | ||
|
||
test_deny_import_blocks_passed if { | ||
issues := deny_import_blocks with terraform.imports as mock_imports | ||
|
||
count(issues) == 1 | ||
issue := issues[_] | ||
issue.msg == "import blocks are not allowed" | ||
} | ||
|
||
test_deny_import_blocks_failed if { | ||
issues := deny_import_blocks with terraform.imports as mock_imports | ||
|
||
count(issues) == 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"issues": [ | ||
{ | ||
"rule": { | ||
"name": "opa_deny_import_blocks", | ||
"severity": "error", | ||
"link": "policies/main.rego:3" | ||
}, | ||
"message": "import blocks are not allowed", | ||
"range": { | ||
"filename": "main.tf", | ||
"start": { | ||
"line": 1, | ||
"column": 1 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 7 | ||
} | ||
}, | ||
"callers": [] | ||
} | ||
], | ||
"errors": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"issues": [ | ||
{ | ||
"rule": { | ||
"name": "opa_test_deny_import_blocks_failed", | ||
"severity": "error", | ||
"link": "policies/main_test.rego:18" | ||
}, | ||
"message": "test failed", | ||
"range": { | ||
"filename": "", | ||
"start": { | ||
"line": 0, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 0, | ||
"column": 0 | ||
} | ||
}, | ||
"callers": [] | ||
} | ||
], | ||
"errors": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.