Skip to content

Commit

Permalink
fix(query): fix terraform query for ingress/egress description
Browse files Browse the repository at this point in the history
Signed-off-by: Felipe Avelar <felipe.avelar@outlook.com>
  • Loading branch information
lipeavelar committed Jan 22, 2022
1 parent a143128 commit 84e17fc
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CxPolicy[result] {
resource := input.document[i].resource.aws_security_group[name]
types := {"ingress", "egress"}
resourceType := resource[types[y]]
not is_array(resourceType)
not common_lib.valid_key(resourceType, "description")

result := {
Expand All @@ -14,5 +15,24 @@ CxPolicy[result] {
"issueType": "MissingAttribute",
"keyExpectedValue": sprintf("aws_security_group[{{%s}}].%s description is defined and not null", [name, types[y]]),
"keyActualValue": sprintf("aws_security_group[{{%s}}].%s description is undefined or null", [name, types[y]]),
"searchLine": common_lib.build_search_line(["resource", "aws_security_group", name, types[y]], []),
}
}

CxPolicy[result] {
resource := input.document[i].resource.aws_security_group[name]
types := {"ingress", "egress"}
resourceType := resource[types[y]]
is_array(resourceType)
currentResource := resourceType[resourceIndex]
not common_lib.valid_key(currentResource, "description")

result := {
"documentId": input.document[i].id,
"searchKey": sprintf("aws_security_group[{{%s}}].%s", [name, types[y]]),
"issueType": "MissingAttribute",
"keyExpectedValue": sprintf("aws_security_group[{{%s}}].%s description is defined and not null", [name, types[y]]),
"keyActualValue": sprintf("aws_security_group[{{%s}}].%s description is undefined or null", [name, types[y]]),
"searchLine": common_lib.build_search_line(["resource", "aws_security_group", name, types[y], resourceIndex], []),
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
resource "aws_security_group" "negative2" {
count = min(var.haproxy_external_node_count + var.monitor_node_count, 1)

name = "${var.prefix}-external-http-https"
description = "Allow main HTTP / HTTPS"
vpc_id = local.vpc_id

ingress {
description = "Enable HTTP access for select VMs"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
description = "Enable HTTPS access for select VMs"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

tags = {
Name = "${var.prefix}-external-http-https"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
resource "aws_security_group" "positive2" {
count = min(var.haproxy_external_node_count + var.monitor_node_count, 1)

name = "${var.prefix}-external-http-https"
description = "Allow main HTTP / HTTPS"
vpc_id = local.vpc_id

ingress {
description = "Enable HTTP access for select VMs"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

tags = {
Name = "${var.prefix}-external-http-https"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@
"severity": "INFO",
"line": 14,
"filename": "positive1.tf"
},
{
"queryName": "Security Group Rules Without Description",
"severity": "INFO",
"line": 16,
"filename": "positive2.tf"
}
]

0 comments on commit 84e17fc

Please sign in to comment.