Skip to content

Commit 268e9e4

Browse files
authored
Merge pull request #27 from aws-samples/sns
added sns notifications
2 parents 70bce02 + 19185fd commit 268e9e4

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ module "pipeline" {
7979
subnets = ["subnet-011aabbcc2233d4ef"],
8080
security_group_ids = ["sg-001abcd2233ee4455"],
8181
}
82+
83+
notifications = {
84+
sns_topic = aws_sns_topic.this.arn
85+
detail_type = "BASIC"
86+
events = [
87+
"codepipeline-pipeline-pipeline-execution-failed",
88+
"codepipeline-pipeline-pipeline-execution-succeeded"
89+
]
90+
}
8291
8392
tags = join(",", [
8493
"Environment[Dev,Prod]",

codepipeline.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ resource "aws_codepipeline" "this" {
7676

7777
configuration = {
7878
CustomData = "This action will approve the deployment of resources in ${var.pipeline_name}. Please review the plan action before approving."
79+
7980
}
8081
}
8182
}
@@ -172,3 +173,15 @@ data "aws_iam_policy_document" "codepipeline" {
172173
]
173174
}
174175
}
176+
177+
resource "aws_codestarnotifications_notification_rule" "this" {
178+
count = var.notifications != null ? 1 : 0
179+
name = var.pipeline_name
180+
detail_type = var.notifications["detail_type"]
181+
event_type_ids = var.notifications["events"]
182+
resource = aws_codepipeline.this.arn
183+
184+
target {
185+
address = var.notifications["sns_topic"]
186+
}
187+
}

docs/optional_inputs.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
`vpc` configures the CodeBuild projects to [run in a VPC](https://docs.aws.amazon.com/codebuild/latest/userguide/vpc-support.html).
2828

29+
`notifications` creates a [CodeStar notification](https://docs.aws.amazon.com/dtconsole/latest/userguide/welcome.html) for the pipeline. `sns_topic` is the SNS topic arn. `events` are the [notification events](https://docs.aws.amazon.com/dtconsole/latest/userguide/concepts.html#events-ref-pipeline). `detail_type` is either BASIC or FULL. The SNS topic must allow [codestar-notifications.amazonaws.com to publush to the topic](https://docs.aws.amazon.com/dtconsole/latest/userguide/notification-target-create.html).
30+
2931
`tags` enables tag validation with [tag-nag](https://github.com/jakebark/tag-nag). Input a list of tag keys and/or tag keys and values to enforce. Input must be passed as a string, see [commands](https://github.com/jakebark/tag-nag?tab=readme-ov-file#commands).
3032

3133
`tagnag_version` controls the [tag-nag](https://github.com/jakebark/tag-nag) version. It defaults to 0.5.8.

variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ variable "log_retention" {
7171
default = 90
7272
}
7373

74+
variable "notifications" {
75+
description = "SNS notification configuration"
76+
type = object({
77+
sns_topic = string
78+
events = list(string)
79+
detail_type = string
80+
})
81+
default = null
82+
}
83+
7484
variable "mode" {
7585
description = "pipeline execution mode"
7686
type = string

0 commit comments

Comments
 (0)