From 127fa60ff42022a35cdf77e369d7b6ce90a1cada Mon Sep 17 00:00:00 2001 From: Robert Peteuil Date: Sun, 9 Aug 2020 15:40:23 -0700 Subject: [PATCH] update for tf 0.13 --- CHANGELOG.md | 16 +++++++++++++++- README.md | 15 +++++++++------ main.tf | 22 +++++++++++----------- outputs.tf | 2 +- variables.tf | 5 ----- 5 files changed, 36 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4052f0..937fc01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/README.md b/README.md index 145a9c4..907e67c 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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" @@ -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 | diff --git a/main.tf b/main.tf index fea92f0..bf45acd 100644 --- a/main.tf +++ b/main.tf @@ -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" + } } # ----------------------------------------------------------------- @@ -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 } diff --git a/outputs.tf b/outputs.tf index 40ad9ac..415cde5 100644 --- a/outputs.tf +++ b/outputs.tf @@ -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 : "" } diff --git a/variables.tf b/variables.tf index 2472469..f7be6e2 100644 --- a/variables.tf +++ b/variables.tf @@ -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."