Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded module to support Terraform 0.12 #36

Merged
merged 6 commits into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .chglog/CHANGELOG.tpl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{ if .Versions -}}
<a name="unreleased"></a>
## [Unreleased]
{{ if .Unreleased.CommitGroups -}}
{{ range .Unreleased.CommitGroups -}}
### {{ .Title }}
{{ range .Commits -}}
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
{{ end }}
{{ end -}}
{{ else }}
{{ range .Unreleased.Commits -}}
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
{{ end }}
{{ end -}}
{{ end -}}

{{ range .Versions }}
<a name="{{ .Tag.Name }}"></a>
## {{ if .Tag.Previous }}[{{ .Tag.Name }}]{{ else }}{{ .Tag.Name }}{{ end }} - {{ datetime "2006-01-02" .Tag.Date }}
{{ if .CommitGroups -}}
{{ range .CommitGroups -}}
### {{ .Title }}
{{ range .Commits -}}
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
{{ end }}
{{ end -}}
{{ else }}
{{ range .Commits -}}
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
{{ end }}
{{ end -}}

{{- if .NoteGroups -}}
{{ range .NoteGroups -}}
### {{ .Title }}
{{ range .Notes }}
{{ .Body }}
{{ end }}
{{ end -}}
{{ end -}}
{{ end -}}

{{- if .Versions }}
[Unreleased]: {{ .Info.RepositoryURL }}/compare/{{ $latest := index .Versions 0 }}{{ $latest.Tag.Name }}...HEAD
{{ range .Versions -}}
{{ if .Tag.Previous -}}
[{{ .Tag.Name }}]: {{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }}
{{ end -}}
{{ end -}}
{{ end -}}
10 changes: 10 additions & 0 deletions .chglog/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
style: github
template: CHANGELOG.tpl.md
info:
title: CHANGELOG
repository_url: https://github.com/terraform-aws-modules/terraform-aws-notify-slack
options:
header:
pattern: "^(.*)$"
pattern_maps:
- Subject
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
repos:
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.7.3
rev: v1.12.0
hooks:
- id: terraform_fmt
- id: terraform_docs
# - id: terraform_docs
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v1.3.0
rev: v2.2.3
hooks:
- id: check-merge-conflict
143 changes: 143 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<a name="unreleased"></a>
## [Unreleased]



<a name="v2.0.0"></a>
## [v2.0.0] - 2019-06-02

- fixed logic when determining whether to add kms policy statement
- path ref was not behaving the same in 0.12 but did not seem to need to be this complicated anyway
- Ran upgrade, manually tweaked some gaps and did basic testing


<a name="v1.13.0"></a>
## [v1.13.0] - 2019-02-22

- need to convert from json string to dict when extracting message from event ([#30](https://github.com/terraform-aws-modules/terraform-aws-notify-slack/issues/30))


<a name="v1.12.0"></a>
## [v1.12.0] - 2019-02-21

- Pass the subject ot default_notification ([#29](https://github.com/terraform-aws-modules/terraform-aws-notify-slack/issues/29))


<a name="v1.11.0"></a>
## [v1.11.0] - 2018-12-28

- No longer parsing the SNS event as incoming JSON ([#23](https://github.com/terraform-aws-modules/terraform-aws-notify-slack/issues/23))


<a name="v1.10.0"></a>
## [v1.10.0] - 2018-08-20

- Fixed bug which causes apply failure when create = false ([#19](https://github.com/terraform-aws-modules/terraform-aws-notify-slack/issues/19))


<a name="v1.9.0"></a>
## [v1.9.0] - 2018-06-21

- Allow computed KMS key value (fixed [#10](https://github.com/terraform-aws-modules/terraform-aws-notify-slack/issues/10)) ([#18](https://github.com/terraform-aws-modules/terraform-aws-notify-slack/issues/18))


<a name="v1.8.0"></a>
## [v1.8.0] - 2018-06-20

- include short alarm name in slack notification text ([#14](https://github.com/terraform-aws-modules/terraform-aws-notify-slack/issues/14))


<a name="v1.7.0"></a>
## [v1.7.0] - 2018-06-20

- Renamed enable to create, minor fixes after [#15](https://github.com/terraform-aws-modules/terraform-aws-notify-slack/issues/15)
- Add flag to enable/disable creation of resources ([#15](https://github.com/terraform-aws-modules/terraform-aws-notify-slack/issues/15))


<a name="v1.6.0"></a>
## [v1.6.0] - 2018-06-19

- Fixed formatting
- Fix Lambda path in shared state ([#17](https://github.com/terraform-aws-modules/terraform-aws-notify-slack/issues/17))
- Fixed spelling a bit
- Cirumvent TF's path.module limitation for lambda filenames
- Cirumvent TF's path.module limitation for lambda filenames
- Cirumvent TF's path.module limitation for lambda filenames


<a name="v1.5.0"></a>
## [v1.5.0] - 2018-06-06

- Fixed formatting (ran 'pre-commit run -a')
- Add in slack emoji support ([#11](https://github.com/terraform-aws-modules/terraform-aws-notify-slack/issues/11))
- Update comments in examples/ about aws_kms_ciphertext ([#12](https://github.com/terraform-aws-modules/terraform-aws-notify-slack/issues/12))


<a name="v1.4.0"></a>
## [v1.4.0] - 2018-06-05

- Ignore `last_modified` timestamp deciding whether to do an update ([#9](https://github.com/terraform-aws-modules/terraform-aws-notify-slack/issues/9))
- Updated formatting in examples


<a name="v1.3.0"></a>
## [v1.3.0] - 2018-05-29

- Ignore changes in filename (fixed [#6](https://github.com/terraform-aws-modules/terraform-aws-notify-slack/issues/6))


<a name="v1.2.0"></a>
## [v1.2.0] - 2018-05-16

- Added pre-commit hook to autogenerate terraform-docs ([#7](https://github.com/terraform-aws-modules/terraform-aws-notify-slack/issues/7))


<a name="v1.1.0"></a>
## [v1.1.0] - 2018-03-22

- Feature/lambda function name variable ([#5](https://github.com/terraform-aws-modules/terraform-aws-notify-slack/issues/5))


<a name="v1.0.1"></a>
## [v1.0.1] - 2018-02-22

- Fix mismatch in alarm state labels and values ([#4](https://github.com/terraform-aws-modules/terraform-aws-notify-slack/issues/4))


<a name="v1.0.0"></a>
## [v1.0.0] - 2018-02-15

- Added better code, examples, docs ([#2](https://github.com/terraform-aws-modules/terraform-aws-notify-slack/issues/2))


<a name="v0.0.1"></a>
## v0.0.1 - 2018-02-12

- Merge pull request [#1](https://github.com/terraform-aws-modules/terraform-aws-notify-slack/issues/1) from nazartm/cloudwatch-event
- Add encrypted webhook URL example
- Fix decryption of webhook URL
- Update readme
- Add basic example
- Make KMS optional
- Add README description
- Add preliminary cloudwatch event handling lambda
- Initial commit


[Unreleased]: https://github.com/terraform-aws-modules/terraform-aws-notify-slack/compare/v2.0.0...HEAD
[v2.0.0]: https://github.com/terraform-aws-modules/terraform-aws-notify-slack/compare/v1.13.0...v2.0.0
[v1.13.0]: https://github.com/terraform-aws-modules/terraform-aws-notify-slack/compare/v1.12.0...v1.13.0
[v1.12.0]: https://github.com/terraform-aws-modules/terraform-aws-notify-slack/compare/v1.11.0...v1.12.0
[v1.11.0]: https://github.com/terraform-aws-modules/terraform-aws-notify-slack/compare/v1.10.0...v1.11.0
[v1.10.0]: https://github.com/terraform-aws-modules/terraform-aws-notify-slack/compare/v1.9.0...v1.10.0
[v1.9.0]: https://github.com/terraform-aws-modules/terraform-aws-notify-slack/compare/v1.8.0...v1.9.0
[v1.8.0]: https://github.com/terraform-aws-modules/terraform-aws-notify-slack/compare/v1.7.0...v1.8.0
[v1.7.0]: https://github.com/terraform-aws-modules/terraform-aws-notify-slack/compare/v1.6.0...v1.7.0
[v1.6.0]: https://github.com/terraform-aws-modules/terraform-aws-notify-slack/compare/v1.5.0...v1.6.0
[v1.5.0]: https://github.com/terraform-aws-modules/terraform-aws-notify-slack/compare/v1.4.0...v1.5.0
[v1.4.0]: https://github.com/terraform-aws-modules/terraform-aws-notify-slack/compare/v1.3.0...v1.4.0
[v1.3.0]: https://github.com/terraform-aws-modules/terraform-aws-notify-slack/compare/v1.2.0...v1.3.0
[v1.2.0]: https://github.com/terraform-aws-modules/terraform-aws-notify-slack/compare/v1.1.0...v1.2.0
[v1.1.0]: https://github.com/terraform-aws-modules/terraform-aws-notify-slack/compare/v1.0.1...v1.1.0
[v1.0.1]: https://github.com/terraform-aws-modules/terraform-aws-notify-slack/compare/v1.0.0...v1.0.1
[v1.0.0]: https://github.com/terraform-aws-modules/terraform-aws-notify-slack/compare/v0.0.1...v1.0.0
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.PHONY: changelog release

changelog:
git-chglog -o CHANGELOG.md --next-tag `semtag final -s minor -o`

release:
semtag final -s minor
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ This module creates SNS topic (or use existing one) and a AWS Lambda function wh

Start by setting up an [incoming webhook integration](https://my.slack.com/services/new/incoming-webhook/) in your Slack workspace.

## Terraform versions

Terraform 0.12. Pin module version to `~> v2.0`. Submit pull-requests to `master` branch.

Terraform 0.11. Pin module version to `~> v1.0`. Submit pull-requests to `terraform011` branch.

## Features

- [x] AWS Lambda runtime Python 3.6
Expand All @@ -18,7 +24,8 @@ Start by setting up an [incoming webhook integration](https://my.slack.com/servi

```hcl
module "notify_slack" {
source = "terraform-aws-modules/notify-slack/aws"
source = "terraform-aws-modules/notify-slack/aws"
version = "~> 2.0"
sns_topic_name = "slack-topic"
Expand All @@ -35,7 +42,6 @@ If you want to subscribe AWS Lambda Function created by this module to an existi
## Examples

* [notify-slack-simple](https://github.com/terraform-aws-modules/terraform-aws-notify-slack/tree/master/examples/notify-slack-simple) - Creates SNS topic which sends messages to Slack channel.
* [notify-slack-kms](https://github.com/terraform-aws-modules/terraform-aws-notify-slack/tree/master/examples/notify-slack-simple) - Creates SNS topic which sends messages to Slack channel (using KMS to encrypt Slack webhook URL).
* [cloudwatch-alerts-to-slack](https://github.com/terraform-aws-modules/terraform-aws-notify-slack/tree/master/examples/cloudwatch-alerts-to-slack) - End to end example which shows how to send AWS Cloudwatch alerts to Slack channel and use KMS to encrypt webhook URL.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Expand All @@ -46,7 +52,6 @@ If you want to subscribe AWS Lambda Function created by this module to an existi
|------|-------------|:----:|:-----:|:-----:|
| create | Whether to create all resources | string | `true` | no |
| create_sns_topic | Whether to create new SNS topic | string | `true` | no |
| create_with_kms_key | Whether to create resources with KMS encryption | string | `false` | no |
| kms_key_arn | ARN of the KMS key used for decrypting slack webhook url | string | `` | no |
| lambda_function_name | The name of the Lambda function to create | string | `notify_slack` | no |
| slack_channel | The name of the channel in Slack for notifications | string | - | yes |
Expand Down
17 changes: 4 additions & 13 deletions examples/cloudwatch-alerts-to-slack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ There are 3 ways to define KMS key which should be used by Lambda function:
1. Use [aws_kms_alias data-source](https://www.terraform.io/docs/providers/aws/d/kms_alias.html) to get an existing KMS key alias and put ARN of it as `kms_key_arn` argument to this module
1. Hard-code the ARN of KMS key

Note: Set `create_with_kms_key = true` when providing value of `kms_key_arn` to create required IAM policy which allows to decrypt using specified KMS key.

### Option 1:

```hcl
Expand All @@ -21,11 +19,10 @@ resource "aws_kms_key" "this" {
resource "aws_kms_alias" "this" {
name = "alias/kms-test-key"
target_key_id = "${aws_kms_key.this.id}"
target_key_id = aws_kms_key.this.id
}
// kms_key_arn = "${aws_kms_key.this.arn}"
// create_with_kms_key = true
// kms_key_arn = aws_kms_key.this.arn
```

### Option 2:
Expand All @@ -35,19 +32,13 @@ data "aws_kms_alias" "this" {
name = "alias/kms-test-key"
}
// kms_key_arn = "${data.aws_kms_alias.this.target_key_arn}"
// create_with_kms_key = true
// kms_key_arn = data.aws_kms_alias.this.target_key_arn
```

### Option 3:

```
variable "kms_key_arn" {
default = "arn:aws:kms:eu-west-1:835367859851:key/054b4846-95fe-4537-94f2-1dfd255238cf"
}
// kms_key_arn = "${var.kms_key_arn}"
// create_with_kms_key = true
// kms_key_arn = "arn:aws:kms:eu-west-1:835367859851:key/054b4846-95fe-4537-94f2-1dfd255238cf"
```

## Usage
Expand Down
33 changes: 7 additions & 26 deletions examples/cloudwatch-alerts-to-slack/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,27 @@ provider "aws" {
region = "eu-west-1"
}

variable "kms_key_arn" {
default = "arn:aws:kms:eu-west-1:000014191260:key/66db1c5d-d42b-4e28-8efb-07a9cf607a73"
}

resource "aws_kms_key" "this" {
description = "KMS key for notify-slack test"
}

resource "aws_kms_alias" "this" {
name = "alias/kms-test-key"
target_key_id = "${aws_kms_key.this.id}"
}

# Encrypt the URL, storing encryption here will show it in logs and in tfstate
# https://www.terraform.io/docs/state/sensitive-data.html
data "aws_kms_ciphertext" "slack_url" {
resource "aws_kms_ciphertext" "slack_url" {
plaintext = "https://hooks.slack.com/services/AAA/BBB/CCC"
key_id = "${aws_kms_key.this.arn}"
key_id = aws_kms_key.this.arn
}

module "notify_slack" {
source = "../../"

sns_topic_name = "slack-topic"

slack_webhook_url = "${data.aws_kms_ciphertext.slack_url.ciphertext_blob}"
slack_webhook_url = aws_kms_ciphertext.slack_url.ciphertext_blob
slack_channel = "aws-notification"
slack_username = "reporter"

# Option 1
kms_key_arn = "${aws_kms_key.this.arn}"

# Option 2
// kms_key_arn = "${data.aws_kms_alias.this.target_key_arn}"


# Option 3
// kms_key_arn = "${var.kms_key_arn}"

create_with_kms_key = true
kms_key_arn = aws_kms_key.this.arn
}

resource "aws_cloudwatch_metric_alarm" "LambdaDuration" {
Expand All @@ -55,9 +36,9 @@ resource "aws_cloudwatch_metric_alarm" "LambdaDuration" {
threshold = "5000"
alarm_description = "Duration of notifying slack exceeds threshold"

alarm_actions = ["${module.notify_slack.this_slack_topic_arn}"]
alarm_actions = [module.notify_slack.this_slack_topic_arn]

dimensions {
FunctionName = "${module.notify_slack.notify_slack_lambda_function_name}"
dimensions = {
FunctionName = module.notify_slack.notify_slack_lambda_function_name
}
}
Loading