-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
skip: Merge pull request #32 from epam/feature/ecc-aws-560-unused_sns…
…_topic new: added policy ecc-aws-560-unused_sns_topic
- Loading branch information
Showing
19 changed files
with
279 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# 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-560-unused_sns_topic | ||
comment: '010002142000' | ||
description: | | ||
Amazon SNS topics unused | ||
resource: aws.sns | ||
filters: | ||
- or: | ||
- type: value | ||
key: SubscriptionsConfirmed | ||
value: "0" | ||
- type: metrics | ||
name: NumberOfMessagesPublished | ||
statistics: Sum | ||
missing-value: 0 | ||
days: 30 | ||
value: 0 | ||
op: eq | ||
period: 2592000 |
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,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-560-unused_sns_topic" | ||
ComplianceStatus = "Green" | ||
} | ||
} | ||
} |
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,28 @@ | ||
resource "aws_sns_topic" "this" { | ||
name = "560-sns-green" | ||
} | ||
|
||
resource "aws_sqs_queue" "this" { | ||
name = "560-sqs-green" | ||
} | ||
|
||
resource "aws_sns_topic_subscription" "this" { | ||
topic_arn = aws_sns_topic.this.arn | ||
protocol = "sqs" | ||
endpoint = aws_sqs_queue.this.arn | ||
} | ||
|
||
resource "null_resource" "this" { | ||
provisioner "local-exec" { | ||
command = join(" ", [ | ||
"aws sns publish ", | ||
"--topic-arn ${aws_sns_topic.this.arn}", | ||
"--message 'Hello World!'", | ||
"--profile ${var.profile}", | ||
"--region ${var.default-region}" | ||
] | ||
) | ||
} | ||
|
||
depends_on = [aws_sns_topic_subscription.this] | ||
} |
2 changes: 2 additions & 0 deletions
2
terraform/ecc-aws-560-unused_sns_topic/green/terraform.tfvars
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,2 @@ | ||
profile = "c7n" | ||
default-region = "us-east-1" |
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 @@ | ||
variable "default-region" { | ||
type = string | ||
description = "Default region for resources will be created" | ||
} | ||
|
||
variable "profile" { | ||
type = string | ||
description = "Profile name configured before running apply" | ||
} |
15 changes: 15 additions & 0 deletions
15
terraform/ecc-aws-560-unused_sns_topic/iam/560-policy.json
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,15 @@ | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"sns:ListTopics", | ||
"sns:GetTopicAttributes", | ||
"tag:GetResources", | ||
"cloudwatch:GetMetricStatistics" | ||
], | ||
"Resource": "*" | ||
} | ||
] | ||
} |
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,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-560-unused_sns_topic" | ||
ComplianceStatus = "Red" | ||
} | ||
} | ||
} |
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,3 @@ | ||
resource "aws_sns_topic" "this" { | ||
name = "560-sns-red" | ||
} |
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,2 @@ | ||
profile = "c7n" | ||
default-region = "us-east-1" |
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 @@ | ||
variable "default-region" { | ||
type = string | ||
description = "Default region for resources will be created" | ||
} | ||
|
||
variable "profile" { | ||
type = string | ||
description = "Profile name configured before running apply" | ||
} |
23 changes: 23 additions & 0 deletions
23
tests/ecc-aws-560-unused_sns_topic/placebo-green/monitoring.GetMetricStatistics_1.json
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,23 @@ | ||
{ | ||
"status_code": 200, | ||
"data": { | ||
"Label": "NumberOfMessagesPublished", | ||
"Datapoints": [ | ||
{ | ||
"Timestamp": { | ||
"__class__": "datetime", | ||
"year": 2023, | ||
"month": 8, | ||
"day": 20, | ||
"hour": 18, | ||
"minute": 55, | ||
"second": 0, | ||
"microsecond": 0 | ||
}, | ||
"Sum": 1.0, | ||
"Unit": "Count" | ||
} | ||
], | ||
"ResponseMetadata": {} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/ecc-aws-560-unused_sns_topic/placebo-green/sns.GetTopicAttributes_1.json
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,21 @@ | ||
{ | ||
"status_code": 200, | ||
"data": { | ||
"Attributes": { | ||
"Policy": "{\"Version\":\"2008-10-17\",\"Id\":\"__default_policy_ID\",\"Statement\":[{\"Sid\":\"__default_statement_ID\",\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"*\"},\"Action\":[\"SNS:GetTopicAttributes\",\"SNS:SetTopicAttributes\",\"SNS:AddPermission\",\"SNS:RemovePermission\",\"SNS:DeleteTopic\",\"SNS:Subscribe\",\"SNS:ListSubscriptionsByTopic\",\"SNS:Publish\"],\"Resource\":\"arn:aws:sns:us-east-1:111111111111:560-sns-green\",\"Condition\":{\"StringEquals\":{\"AWS:SourceOwner\":\"111111111111\"}}}]}", | ||
"LambdaSuccessFeedbackSampleRate": "0", | ||
"Owner": "111111111111", | ||
"SubscriptionsPending": "0", | ||
"TopicArn": "arn:aws:sns:us-east-1:111111111111:560-sns-green", | ||
"EffectiveDeliveryPolicy": "{\"http\":{\"defaultHealthyRetryPolicy\":{\"minDelayTarget\":20,\"maxDelayTarget\":20,\"numRetries\":3,\"numMaxDelayRetries\":0,\"numNoDelayRetries\":0,\"numMinDelayRetries\":0,\"backoffFunction\":\"linear\"},\"disableSubscriptionOverrides\":false,\"defaultRequestPolicy\":{\"headerContentType\":\"text/plain; charset=UTF-8\"}}}", | ||
"FirehoseSuccessFeedbackSampleRate": "0", | ||
"SubscriptionsConfirmed": "1", | ||
"SQSSuccessFeedbackSampleRate": "0", | ||
"HTTPSuccessFeedbackSampleRate": "0", | ||
"ApplicationSuccessFeedbackSampleRate": "0", | ||
"DisplayName": "", | ||
"SubscriptionsDeleted": "0" | ||
}, | ||
"ResponseMetadata": {} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/ecc-aws-560-unused_sns_topic/placebo-green/sns.ListTopics_1.json
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,11 @@ | ||
{ | ||
"status_code": 200, | ||
"data": { | ||
"Topics": [ | ||
{ | ||
"TopicArn": "arn:aws:sns:us-east-1:111111111111:560-sns-green" | ||
} | ||
], | ||
"ResponseMetadata": {} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
tests/ecc-aws-560-unused_sns_topic/placebo-green/tagging.GetResources_1.json
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,22 @@ | ||
{ | ||
"status_code": 200, | ||
"data": { | ||
"PaginationToken": "", | ||
"ResourceTagMappingList": [ | ||
{ | ||
"ResourceARN": "arn:aws:sns:us-east-1:111111111111:560-sns-green", | ||
"Tags": [ | ||
{ | ||
"Key": "CustodianRule", | ||
"Value": "ecc-aws-560-unused_sns_topic" | ||
}, | ||
{ | ||
"Key": "ComplianceStatus", | ||
"Value": "Green" | ||
} | ||
] | ||
} | ||
], | ||
"ResponseMetadata": {} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
tests/ecc-aws-560-unused_sns_topic/placebo-red/monitoring.GetMetricStatistics_1.json
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 @@ | ||
{ | ||
"status_code": 200, | ||
"data": { | ||
"Label": "NumberOfMessagesPublished", | ||
"Datapoints": [], | ||
"ResponseMetadata": {} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/ecc-aws-560-unused_sns_topic/placebo-red/sns.GetTopicAttributes_1.json
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,21 @@ | ||
{ | ||
"status_code": 200, | ||
"data": { | ||
"Attributes": { | ||
"Policy": "{\"Version\":\"2008-10-17\",\"Id\":\"__default_policy_ID\",\"Statement\":[{\"Sid\":\"__default_statement_ID\",\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"*\"},\"Action\":[\"SNS:GetTopicAttributes\",\"SNS:SetTopicAttributes\",\"SNS:AddPermission\",\"SNS:RemovePermission\",\"SNS:DeleteTopic\",\"SNS:Subscribe\",\"SNS:ListSubscriptionsByTopic\",\"SNS:Publish\"],\"Resource\":\"arn:aws:sns:us-east-1:111111111111:560-sns-red\",\"Condition\":{\"StringEquals\":{\"AWS:SourceOwner\":\"111111111111\"}}}]}", | ||
"LambdaSuccessFeedbackSampleRate": "0", | ||
"Owner": "111111111111", | ||
"SubscriptionsPending": "0", | ||
"TopicArn": "arn:aws:sns:us-east-1:111111111111:560-sns-red", | ||
"EffectiveDeliveryPolicy": "{\"http\":{\"defaultHealthyRetryPolicy\":{\"minDelayTarget\":20,\"maxDelayTarget\":20,\"numRetries\":3,\"numMaxDelayRetries\":0,\"numNoDelayRetries\":0,\"numMinDelayRetries\":0,\"backoffFunction\":\"linear\"},\"disableSubscriptionOverrides\":false,\"defaultRequestPolicy\":{\"headerContentType\":\"text/plain; charset=UTF-8\"}}}", | ||
"FirehoseSuccessFeedbackSampleRate": "0", | ||
"SubscriptionsConfirmed": "0", | ||
"SQSSuccessFeedbackSampleRate": "0", | ||
"HTTPSuccessFeedbackSampleRate": "0", | ||
"ApplicationSuccessFeedbackSampleRate": "0", | ||
"DisplayName": "", | ||
"SubscriptionsDeleted": "0" | ||
}, | ||
"ResponseMetadata": {} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/ecc-aws-560-unused_sns_topic/placebo-red/sns.ListTopics_1.json
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,11 @@ | ||
{ | ||
"status_code": 200, | ||
"data": { | ||
"Topics": [ | ||
{ | ||
"TopicArn": "arn:aws:sns:us-east-1:111111111111:560-sns-red" | ||
} | ||
], | ||
"ResponseMetadata": {} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
tests/ecc-aws-560-unused_sns_topic/placebo-red/tagging.GetResources_1.json
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,22 @@ | ||
{ | ||
"status_code": 200, | ||
"data": { | ||
"PaginationToken": "", | ||
"ResourceTagMappingList": [ | ||
{ | ||
"ResourceARN": "arn:aws:sns:us-east-1:111111111111:560-sns-red", | ||
"Tags": [ | ||
{ | ||
"Key": "CustodianRule", | ||
"Value": "ecc-aws-560-unused_sns_topic" | ||
}, | ||
{ | ||
"Key": "ComplianceStatus", | ||
"Value": "Red" | ||
} | ||
] | ||
} | ||
], | ||
"ResponseMetadata": {} | ||
} | ||
} |
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,6 @@ | ||
class PolicyTest(object): | ||
|
||
def test_resources(self, base_test, resources): | ||
base_test.assertEqual(len(resources), 1) | ||
base_test.assertEqual(resources[0]["SubscriptionsConfirmed"], "0") | ||
base_test.assertEqual(resources[0]["c7n.metrics"]["AWS/SNS.NumberOfMessagesPublished.Sum.30"][0]["Sum"], 0) |