generated from dxw/terraform-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* This creates an SNS topic in the default region, and us-east-1, to allow CloudWatch to send alerts to Opsgenie. * The SNS endpoint must first be configured in Opsgenie (https://support.atlassian.com/opsgenie/docs/integrate-opsgenie-with-incoming-amazon-sns/) and provided in the variable `cloudwatch_opsgenie_alerts_sns_endpoint`
- Loading branch information
Showing
7 changed files
with
170 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 |
---|---|---|
|
@@ -12,3 +12,4 @@ jobs: | |
uses: aquasecurity/[email protected] | ||
with: | ||
github_token: ${{ github.token }} | ||
working_directory: '' |
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
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,116 @@ | ||
resource "aws_kms_key" "cloudwatch_opsgenie_alerts_sns" { | ||
count = local.cloudwatch_opsgenie_alerts_sns_kms_encryption ? 1 : 0 | ||
|
||
description = "This key is used to encrypt data in SNS for the CloudWatch Opsgenie Alerts (${local.project_name})" | ||
deletion_window_in_days = 10 | ||
enable_key_rotation = true | ||
|
||
policy = templatefile( | ||
"${path.module}/policies/kms-key-policy-sns-topic.json.tpl", | ||
{ | ||
services = jsonencode(["cloudwatch.amazonaws.com"]), | ||
sns_topic_arn = "arn:aws:sns:${local.aws_region}:${local.aws_account_id}:${local.project_name}-cloudwatch-opsgenie-alerts" | ||
} | ||
) | ||
} | ||
|
||
resource "aws_kms_alias" "cloudwatch_opsgenie_alerts_sns" { | ||
count = local.cloudwatch_opsgenie_alerts_sns_kms_encryption ? 1 : 0 | ||
|
||
name = "alias/${local.project_name}-cloudwatch-opsgenie-alerts-sns" | ||
target_key_id = aws_kms_key.cloudwatch_opsgenie_alerts_sns[0].key_id | ||
} | ||
|
||
resource "aws_sns_topic" "cloudwatch_opsgenie_alerts" { | ||
count = local.enable_cloudwatch_opsgenie_alerts ? 1 : 0 | ||
|
||
name = "${local.project_name}-cloudwatch-opsgenie-alerts" | ||
kms_master_key_id = local.cloudwatch_opsgenie_alerts_sns_kms_encryption ? aws_kms_alias.cloudwatch_opsgenie_alerts_sns[0].name : null | ||
} | ||
|
||
resource "aws_kms_key" "cloudwatch_opsgenie_alerts_sns_us_east_1" { | ||
count = local.cloudwatch_opsgenie_alerts_sns_kms_encryption ? 1 : 0 | ||
|
||
provider = aws.useast1 | ||
|
||
description = "This key is used to encrypt data in SNS for the CloudWatch Opsgenie Alerts (${local.project_name})" | ||
deletion_window_in_days = 10 | ||
enable_key_rotation = true | ||
|
||
policy = templatefile( | ||
"${path.module}/policies/kms-key-policy-sns-topic.json.tpl", | ||
{ | ||
services = jsonencode(["cloudwatch.amazonaws.com"]), | ||
sns_topic_arn = "arn:aws:sns:us-east-1:${local.aws_account_id}:${local.project_name}-cloudwatch-opsgenie-alerts" | ||
} | ||
) | ||
} | ||
|
||
resource "aws_kms_alias" "cloudwatch_opsgenie_alerts_sns_us_east_1" { | ||
count = local.cloudwatch_opsgenie_alerts_sns_kms_encryption ? 1 : 0 | ||
|
||
provider = aws.useast1 | ||
|
||
name = "alias/${local.project_name}-cloudwatch-opsgenie-alerts-sns" | ||
target_key_id = aws_kms_key.cloudwatch_opsgenie_alerts_sns_us_east_1[0].key_id | ||
} | ||
|
||
|
||
resource "aws_sns_topic" "cloudwatch_opsgenie_alerts_us_east_1" { | ||
count = local.enable_cloudwatch_opsgenie_alerts ? 1 : 0 | ||
|
||
provider = aws.useast1 | ||
|
||
name = "${local.project_name}-cloudwatch-opsgenie-alerts" | ||
kms_master_key_id = local.cloudwatch_opsgenie_alerts_sns_kms_encryption ? aws_kms_alias.cloudwatch_opsgenie_alerts_sns_us_east_1[0].name : null | ||
} | ||
|
||
resource "aws_sns_topic_policy" "sns_cloudwatch_opsgenie_alerts" { | ||
count = local.enable_cloudwatch_opsgenie_alerts ? 1 : 0 | ||
|
||
arn = aws_sns_topic.cloudwatch_opsgenie_alerts[0].arn | ||
policy = templatefile( | ||
"${path.root}/policies/sns-events-policy.json.tpl", | ||
{ | ||
sns_arn = aws_sns_topic.cloudwatch_opsgenie_alerts[0].arn | ||
aws_account_id = local.aws_account_id | ||
} | ||
) | ||
} | ||
|
||
resource "aws_sns_topic_policy" "sns_cloudwatch_opsgenie_alerts_us_east_1" { | ||
count = local.enable_cloudwatch_opsgenie_alerts ? 1 : 0 | ||
|
||
provider = aws.useast1 | ||
|
||
arn = aws_sns_topic.cloudwatch_opsgenie_alerts_us_east_1[0].arn | ||
policy = templatefile( | ||
"${path.root}/policies/sns-events-policy.json.tpl", | ||
{ | ||
sns_arn = aws_sns_topic.cloudwatch_opsgenie_alerts_us_east_1[0].arn | ||
aws_account_id = local.aws_account_id | ||
} | ||
) | ||
} | ||
|
||
resource "aws_sns_topic_subscription" "cloudwatch_opsgenie_alerts_subscription" { | ||
count = local.enable_cloudwatch_opsgenie_alerts ? 1 : 0 | ||
|
||
topic_arn = aws_sns_topic.cloudwatch_opsgenie_alerts[0].arn | ||
protocol = "https" | ||
endpoint = local.cloudwatch_opsgenie_alerts_sns_endpoint | ||
endpoint_auto_confirms = true | ||
confirmation_timeout_in_minutes = 10 | ||
} | ||
|
||
resource "aws_sns_topic_subscription" "cloudwatch_opsgenie_alerts_subscription_us_east_1" { | ||
count = local.enable_cloudwatch_opsgenie_alerts ? 1 : 0 | ||
|
||
provider = aws.useast1 | ||
|
||
topic_arn = aws_sns_topic.cloudwatch_opsgenie_alerts_us_east_1[0].arn | ||
protocol = "https" | ||
endpoint = local.cloudwatch_opsgenie_alerts_sns_endpoint | ||
endpoint_auto_confirms = true | ||
confirmation_timeout_in_minutes = 10 | ||
} |
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
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,16 @@ | ||
{ | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": ${services} | ||
}, | ||
"Action": [ | ||
"kms:Decrypt", | ||
"kms:GenerateDataKey" | ||
], | ||
"Resource": "*", | ||
"Condition": { | ||
"StringEquals": { | ||
"kms:EncryptionContext:aws:sns:topicArn": "${sns_topic_arn}" | ||
} | ||
} | ||
} |
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
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