Skip to content

Commit

Permalink
add present operator, update test data
Browse files Browse the repository at this point in the history
  • Loading branch information
lhitchon committed Mar 7, 2018
1 parent ef7550e commit 67e7a17
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func unquoted(s string) string {
func isValid(searchResult, op, value, severity string) string {
// TODO see Cloud Custodian for ideas
// ADD gt, ge, lt, le
// absent, present, not-null, empty
// absent, not-null, empty
// and, or, not, intersect
// glob
switch op {
Expand All @@ -138,6 +138,10 @@ func isValid(searchResult, op, value, severity string) string {
}
}
return "OK"
case "present":
if searchResult != "null" {
return "OK"
}
case "regex":
if regexp.MustCompile(value).MatchString(unquoted(searchResult)) {
return "OK"
Expand Down
4 changes: 4 additions & 0 deletions files/terraform.hcl
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
resource "aws_instance" "first" {
ami = "ami-f2d3638a"
instance_type = "t2.micro"
tags {
"CostCenter" = "1001"
}
}
resource "aws_instance" "second" {
ami = "ami-f2d3638a"
instance_type = "m3.medium"
tags {
Department = "Operations"
CostCenter = "2001"
}
}
resource "aws_instance" "third" {
Expand Down
8 changes: 8 additions & 0 deletions rules/terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@ Rules:
op: regex
value: ".com$"
severity: WARNING
- id: R6
message: CostCenter tag is missing
resource: aws_instance
filters:
- type: value
key: "tags[].CostCenter | [0]"
op: present
severity: FAILURE

0 comments on commit 67e7a17

Please sign in to comment.