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.removed_blocks
function (#87)
- Loading branch information
Showing
10 changed files
with
294 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
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,7 @@ | ||
removed { | ||
from = aws_instance.example | ||
|
||
lifecycle { | ||
destroy = false | ||
} | ||
} |
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_removed_blocks[issue] { | ||
moved := terraform.removed_blocks({}, {}) | ||
count(moved) > 0 | ||
|
||
issue := tflint.issue("removed blocks are not allowed", moved[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,25 @@ | ||
package tflint | ||
import future.keywords | ||
|
||
mock_removed_blocks(schema, options) := terraform.mock_removed_blocks(schema, options, {"main.tf": ` | ||
removed { | ||
from = aws_instance.example | ||
lifecycle { | ||
destroy = false | ||
} | ||
}`}) | ||
|
||
test_deny_removed_blocks_passed if { | ||
issues := deny_removed_blocks with terraform.removed_blocks as mock_removed_blocks | ||
|
||
count(issues) == 1 | ||
issue := issues[_] | ||
issue.msg == "removed blocks are not allowed" | ||
} | ||
|
||
test_deny_removed_blocks_failed if { | ||
issues := deny_removed_blocks with terraform.removed_blocks as mock_removed_blocks | ||
|
||
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_removed_blocks", | ||
"severity": "error", | ||
"link": "policies/main.rego:3" | ||
}, | ||
"message": "removed blocks are not allowed", | ||
"range": { | ||
"filename": "main.tf", | ||
"start": { | ||
"line": 1, | ||
"column": 1 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 8 | ||
} | ||
}, | ||
"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_removed_blocks_failed", | ||
"severity": "error", | ||
"link": "policies/main_test.rego:21" | ||
}, | ||
"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
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