Skip to content

Commit

Permalink
new: added policy ecc-aws-548-ebs_volumes_are_of_type_gp3_instead_of_gp2
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladyslav Yevsiukov authored and Vladyslav Yevsiukov committed Aug 9, 2023
1 parent 05cdc84 commit b876852
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (c) 2023 EPAM Systems, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.


policies:
- name: ecc-aws-548-ebs_volumes_are_of_type_gp3_instead_of_gp2
resource: aws.ebs
description: |
EBS volumes are type of gp2 insted of gp3
filters:
- type: value
key: VolumeType
value: gp2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resource "aws_ebs_volume" "this" {
availability_zone = data.aws_availability_zones.this.names[0]
size = 8
}

data "aws_availability_zones" "this" {
state = "available"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4"
}
}
}

provider "aws" {
profile = var.profile
region = var.default-region

default_tags {
tags = {
CustodianRule = "ecc-aws-548-ebs_volumes_are_of_type_gp3_instead_of_gp2"
ComplianceStatus = "Green"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
profile = "c7n"
default-region = "us-east-1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
variable "default-region" {
type = string
description = "Default region for resources will be created"
}

variable "profile" {
type = string
description = "Profile name configured before running apply"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:DescribeVolumes"
],
"Resource": "*"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "aws_ebs_volume" "this" {
availability_zone = data.aws_availability_zones.this.names[0]
size = 8
type = "gp3"
}

data "aws_availability_zones" "this" {
state = "available"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4"
}
}
}

provider "aws" {
profile = var.profile
region = var.default-region

default_tags {
tags = {
CustodianRule = "ecc-aws-548-ebs_volumes_are_of_type_gp3_instead_of_gp2"
ComplianceStatus = "Red"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
profile = "c7n"
default-region = "us-east-1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
variable "default-region" {
type = string
description = "Default region for resources will be created"
}

variable "profile" {
type = string
description = "Profile name configured before running apply"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"status_code": 200,
"data": {
"Volumes": [
{
"Attachments": [],
"AvailabilityZone": "us-east-1a",
"CreateTime": {
"__class__": "datetime",
"year": 2023,
"month": 8,
"day": 7,
"hour": 10,
"minute": 21,
"second": 26,
"microsecond": 451000
},
"Encrypted": false,
"Size": 8,
"SnapshotId": "",
"State": "available",
"VolumeId": "vol-0fb6c7480bfce553c",
"Iops": 100,
"Tags": [
{
"Key": "CustodianRule",
"Value": "ecc-aws-548-ebs_volumes_are_of_type_gp3_instead_of_gp2"
},
{
"Key": "ComplianceStatus",
"Value": "Green"
}
],
"VolumeType": "gp3",
"MultiAttachEnabled": false
}
],
"ResponseMetadata": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"status_code": 200,
"data": {
"Volumes": [
{
"Attachments": [],
"AvailabilityZone": "us-east-1a",
"CreateTime": {
"__class__": "datetime",
"year": 2023,
"month": 8,
"day": 7,
"hour": 10,
"minute": 20,
"second": 53,
"microsecond": 24000
},
"Encrypted": false,
"Size": 8,
"SnapshotId": "",
"State": "available",
"VolumeId": "vol-02e08791159817fa1",
"Iops": 3000,
"Tags": [
{
"Key": "CustodianRule",
"Value": "ecc-aws-548-ebs_volumes_are_of_type_gp3_instead_of_gp2"
},
{
"Key": "ComplianceStatus",
"Value": "Red"
}
],
"VolumeType": "gp2",
"MultiAttachEnabled": false,
"Throughput": 125
}
],
"ResponseMetadata": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class PolicyTest(object):

def test_resources(self, base_test, resources):
base_test.assertEqual(len(resources), 1)
base_test.assertEqual(resources[0]['VolumeType'], "gp2")

0 comments on commit b876852

Please sign in to comment.