Skip to content

Commit

Permalink
Add "ElastiCache Nodes Not Created Across Multi AZ" query for CloudFo…
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-mimoso authored Mar 30, 2021
1 parent e5e9c55 commit 85784c0
Show file tree
Hide file tree
Showing 16 changed files with 183 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "cfdef2e5-1fe4-4ef4-bea8-c56e08963150",
"queryName": "ElastiCache Nodes Not Created Across Multi AZ",
"severity": "MEDIUM",
"category": "Availability",
"descriptionText": "Check if ElastiCache nodes are not being created across multi AZ",
"descriptionUrl": "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticache-cache-cluster.html",
"platform": "CloudFormation"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package Cx

CxPolicy[result] {
resource := input.document[i].Resources[name]
resource.Type == "AWS::ElastiCache::CacheCluster"
properties := resource.Properties
properties.Engine == "memcached"
to_number(properties.NumCacheNodes) > 1

properties.AZMode != "cross-az"

result := {
"documentId": input.document[i].id,
"searchKey": sprintf("Resources.%s.Properties.AZMode", [name]),
"issueType": "IncorrectValue",
"keyExpectedValue": sprintf("Resources.%s.Properties.AZMode is 'cross-az'", [name]),
"keyActualValue": sprintf("Resources.%s.Properties.AZMode is 'single-az", [name]),
}
}

CxPolicy[result] {
resource := input.document[i].Resources[name]
resource.Type == "AWS::ElastiCache::CacheCluster"
properties := resource.Properties
properties.Engine == "memcached"
to_number(properties.NumCacheNodes) > 1
object.get(properties, "AZMode", "undefined") == "undefined"

result := {
"documentId": input.document[i].id,
"searchKey": sprintf("Resources.%s.Properties", [name]),
"issueType": "MissingAttribute",
"keyExpectedValue": sprintf("Resources.%s.Properties.AZMode is defined and is 'cross-az'", [name]),
"keyActualValue": sprintf("Resources.%s.Properties.AZMode is not defined, default value is 'single-az'", [name]),
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
AWSTemplateFormatVersion: "2010-09-09"
Resources:
myCacheCluster:
Type: 'AWS::ElastiCache::CacheCluster'
Properties:
AZMode: cross-az
CacheNodeType: cache.m3.medium
Engine: memcached
NumCacheNodes: '3'
PreferredAvailabilityZones:
- us-west-2a
- us-west-2a
- us-west-2b
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"Resources": {
"myCacheCluster2": {
"Type": "AWS::ElastiCache::CacheCluster",
"Properties": {
"AZMode": "cross-az",
"CacheNodeType": "cache.m3.medium",
"Engine": "memcached",
"NumCacheNodes": "3",
"PreferredAvailabilityZones": [
"us-west-2a",
"us-west-2a",
"us-west-2b"
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
AWSTemplateFormatVersion: "2010-09-09"
Resources:
myCacheCluster3:
Type: 'AWS::ElastiCache::CacheCluster'
Properties:
AZMode: single-az
CacheNodeType: cache.m3.medium
Engine: memcached
NumCacheNodes: '3'
PreferredAvailabilityZones:
- us-west-2a
- us-west-2a
- us-west-2b
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
AWSTemplateFormatVersion: "2010-09-09"
Resources:
myCacheCluster4:
Type: 'AWS::ElastiCache::CacheCluster'
Properties:
CacheNodeType: cache.m3.medium
Engine: memcached
NumCacheNodes: '3'
PreferredAvailabilityZones:
- us-west-2a
- us-west-2a
- us-west-2b
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"Resources": {
"myCacheCluster5": {
"Type": "AWS::ElastiCache::CacheCluster",
"Properties": {
"AZMode": "single-az",
"CacheNodeType": "cache.m3.medium",
"Engine": "memcached",
"NumCacheNodes": "3",
"PreferredAvailabilityZones": [
"us-west-2a",
"us-west-2a",
"us-west-2b"
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"Resources": {
"myCacheCluster6": {
"Type": "AWS::ElastiCache::CacheCluster",
"Properties": {
"CacheNodeType": "cache.m3.medium",
"Engine": "memcached",
"NumCacheNodes": "3",
"PreferredAvailabilityZones": [
"us-west-2a",
"us-west-2a",
"us-west-2b"
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"line": 6,
"fileName": "positive1.yaml",
"queryName": "ElastiCache Nodes Not Created Across Multi AZ",
"severity": "MEDIUM"
},
{
"fileName": "positive3.json",
"queryName": "ElastiCache Nodes Not Created Across Multi AZ",
"severity": "MEDIUM",
"line": 6
},
{
"queryName": "ElastiCache Nodes Not Created Across Multi AZ",
"severity": "MEDIUM",
"line": 5,
"fileName": "positive2.yaml"
},
{
"queryName": "ElastiCache Nodes Not Created Across Multi AZ",
"severity": "MEDIUM",
"line": 5,
"fileName": "positive4.json"
}
]

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "6db03a91-f933-4f13-ab38-a8b87a7de54d",
"queryName": "ElastiCache Nodes Not Created Across Multi AZ",
"severity": "MEDIUM",
"category": "Availability",
"descriptionText": "Check if ElastiCache nodes are not being created across multi AZ",
"descriptionUrl": "https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_cluster",
"platform": "Terraform"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"queryName": "ElastiCache Nodes Not Created Across Multi AZ",
"severity": "MEDIUM",
"line": 1
},
{
"queryName": "ElastiCache Nodes Not Created Across Multi AZ",
"severity": "MEDIUM",
"line": 12
}
]

0 comments on commit 85784c0

Please sign in to comment.