Skip to content

Commit

Permalink
update for tf 0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
robertpeteuil committed Aug 9, 2020
1 parent fe354fc commit 127fa60
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [3.0.0] - 2020-08-08

- fix errors that could occur if `create_warmer_event` set to `false`

Breaking Change

- remove `provider` block from `main.tf` as this improves Terraform 0.13 compatibility
- removed `var.aws_region`, since is no longer needed without provider block
- add `required_providers` to set min version of aws provider

## [2.0.1] - 2019-06-19

- add Terraform 0.11/0.12 version compatibility info to README.md

## [2.0.0] - 2019-05-27

- update for HCL2 in Terraform versions > 0.12
Expand All @@ -12,7 +26,7 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
## [1.0.1] - 2019-04-12

- constrain AWS provider to versions >= 2.0
- necessary due to [attribute values swap](https://www.terraform.io/docs/providers/aws/guides/version-2-upgrade.html#arn-and-layer_arn-attribute-value-swap) in versiions >= 2.0
- necessary due to [attribute values swap](https://www.terraform.io/docs/providers/aws/guides/version-2-upgrade.html#arn-and-layer_arn-attribute-value-swap) in versions >= 2.0

## [1.0.0] - 2019-03-30

Expand Down
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

`terraform-aws-sns-to-cloudwatch-logs-lambda` is a Terraform module to provision a Lambda Function which routes SNS messages to CloudWatch Logs

- For Terraform versions > = 0.12, use module `version >= "2.0.0"`
- for Terraform versions < 0.12, use module `version = "1.0.1"`
- Terraform versions >= 0.12, use module `version >= "3.0.0"`
- If using `var.aws_region` to specify deployment region use `version = "2.0.1"` or switch to provider aliases and explicit provider passing
- Terraform versions <= 0.11, use module `version = "1.0.1"`

## Terraform Module Features

Expand All @@ -21,6 +22,8 @@ This Module allows simple and rapid deployment
- Optionally create custom Lambda Layer zip using [build-lambda-layer-python](https://github.com/robertpeteuil/build-lambda-layer-python)
- Enables adding/changing dependencies
- Enables compiling for different version of Python
- New behavior in `3.0.0` - inherits `region` from calling module's AWS Provider for resource creation/discovery.
- Deploy to alternate regions via provider aliases and [expicit provider passing](https://www.terraform.io/docs/configuration/modules.html#passing-providers-explicitly)

## SNS to CloudWatch Logs Features

Expand All @@ -38,10 +41,11 @@ This Lambda Function forwards subject & body of SNS messages to CloudWatch Log G
``` ruby
module "sns_logger" {
source = "robertpeteuil/sns-to-cloudwatch-logs-lambda/aws"
version = "2.0.0" # HCL2 support for Terraform >= 0.12
# version = "1.0.1" # Latest version for Terraform < 0.12
version = "3.0.0" # Use with Terraform >= 0.13
# version = "2.0.1" # Use with Terraform ~ 0.12.x
# last version with var.aws_region and provider in module
# version = "1.0.1" # Latest version for Terraform <= 0.11

aws_region = "us-west-2"
sns_topic_name = "projectx-logging"
log_group_name = "projectx"
log_stream_name = "script-logs"
Expand All @@ -54,7 +58,6 @@ module "sns_logger" {

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| aws_region | Region where AWS resources are located | string | - | yes |
| sns_topic_name | Name of SNS Topic to be logged by Gateway | string | - | yes |
| log_group_name | Name of CloudWatch Log Group | string | - | yes |
| log_stream_name | Name of CloudWatch Log Stream | string | - | yes |
Expand Down
22 changes: 11 additions & 11 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
# -----------------------------------------------------------------

terraform {
required_version = ">= 0.12"
}

provider "aws" {
region = var.aws_region
version = ">= 2.12"
required_version = ">= 0.12.4"
required_providers {
aws = ">= 2.12"
}
}

# -----------------------------------------------------------------
Expand Down Expand Up @@ -217,10 +215,12 @@ JSON
# -----------------------------------------------------------------

resource "aws_lambda_permission" "warmer_multi" {
statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
count = var.create_warmer_event ? 1 : 0

statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.sns_cloudwatchlog.function_name
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.warmer[0].arn
qualifier = var.lambda_publish_func ? aws_lambda_function.sns_cloudwatchlog.version : null
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.warmer[0].arn
qualifier = var.lambda_publish_func ? aws_lambda_function.sns_cloudwatchlog.version : null
}
2 changes: 1 addition & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ output "log_stream_arn" {

output "cloudwatch_event_rule_arn" {
description = "ARN of CloudWatch Trigger Event created to prevent hibernation."
value = aws_cloudwatch_event_rule.warmer[0].arn
value = var.create_warmer_event ? aws_cloudwatch_event_rule.warmer[0].arn : ""
}

5 changes: 0 additions & 5 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
# REQUIRED VARIABLES WITHOUT DEFAULT VALUES
# -----------------------------------------------------------------

variable "aws_region" {
type = string
description = "Region where AWS resources will be created."
}

variable "sns_topic_name" {
type = string
description = "Name of SNS Topic logging to CloudWatch Log."
Expand Down

0 comments on commit 127fa60

Please sign in to comment.