From 71c4d3188e3c4ec9516c4f5f430d23a8136381b1 Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Wed, 28 Aug 2024 12:17:26 -0400 Subject: [PATCH] Bugfix: Revert Breaking Change in v0.6.0 (#79) * revert changes * added outputs and tests for catch future breaking changes * added outputs and tests for catch future breaking changes * tflint and formatting * corrected output * set valid expected test result * use tabs --- examples/complete/main.tf | 6 +++--- examples/complete/outputs.tf | 15 +++++++++++++++ examples/complete/versions.tf | 4 ++++ main.tf | 5 ++++- outputs.tf | 5 +++++ test/src/examples_complete_test.go | 8 ++++++++ 6 files changed, 39 insertions(+), 4 deletions(-) diff --git a/examples/complete/main.tf b/examples/complete/main.tf index 481a0e8..b678c53 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -7,8 +7,8 @@ locals { policy_arn_prefix = format( "arn:%s:iam::%s:policy", - join("", data.aws_partition.current.*.partition), - join("", data.aws_caller_identity.current.*.account_id), + join("", data.aws_partition.current[*].partition), + join("", data.aws_caller_identity.current[*].account_id), ) policy_arn_inside = format("%s/%s", local.policy_arn_prefix, local.policy_name_inside) @@ -77,7 +77,7 @@ resource "aws_iam_role_policy_attachment" "outside" { module "lambda" { source = "../.." - filename = join("", data.archive_file.lambda_zip.*.output_path) + filename = join("", data.archive_file.lambda_zip[*].output_path) function_name = module.label.id handler = var.handler runtime = var.runtime diff --git a/examples/complete/outputs.tf b/examples/complete/outputs.tf index 493dd38..3071a25 100644 --- a/examples/complete/outputs.tf +++ b/examples/complete/outputs.tf @@ -2,3 +2,18 @@ output "arn" { description = "ARN of the lambda function" value = module.lambda.arn } + +output "function_name" { + description = "Lambda function name" + value = module.lambda.function_name +} + +output "role_name" { + description = "Lambda IAM role name" + value = module.lambda.role_name +} + +output "cloudwatch_log_group_name" { + description = "Name of Cloudwatch log group" + value = module.lambda.cloudwatch_log_group_name +} diff --git a/examples/complete/versions.tf b/examples/complete/versions.tf index b78d471..c6da977 100644 --- a/examples/complete/versions.tf +++ b/examples/complete/versions.tf @@ -6,5 +6,9 @@ terraform { source = "hashicorp/aws" version = ">= 3.0" } + archive = { + source = "hashicorp/archive" + version = ">= 2.0" + } } } diff --git a/main.tf b/main.tf index 057b495..b173da6 100644 --- a/main.tf +++ b/main.tf @@ -9,11 +9,14 @@ module "cloudwatch_log_group" { source = "cloudposse/cloudwatch-logs/aws" version = "0.6.6" + enabled = module.this.enabled + iam_role_enabled = false kms_key_arn = var.cloudwatch_logs_kms_key_arn retention_in_days = var.cloudwatch_logs_retention_in_days name = "/aws/lambda/${var.function_name}" - context = module.this.context + + tags = module.this.tags } resource "aws_lambda_function" "this" { diff --git a/outputs.tf b/outputs.tf index 73bd4be..ee60621 100644 --- a/outputs.tf +++ b/outputs.tf @@ -27,3 +27,8 @@ output "role_arn" { description = "Lambda IAM role ARN" value = local.enabled ? aws_iam_role.this[0].arn : null } + +output "cloudwatch_log_group_name" { + description = "Name of Cloudwatch log group" + value = local.enabled ? module.cloudwatch_log_group.log_group_name : null +} diff --git a/test/src/examples_complete_test.go b/test/src/examples_complete_test.go index 45dbc20..9f8a0de 100644 --- a/test/src/examples_complete_test.go +++ b/test/src/examples_complete_test.go @@ -39,7 +39,15 @@ func TestExamplesComplete(t *testing.T) { // Run `terraform output` to get the value of an output variable arn := terraform.Output(t, terraformOptions, "arn") + function_name := terraform.Output(t, terraformOptions, "function_name") + role_name := terraform.Output(t, terraformOptions, "role_name") + cloudwatch_log_group_name := terraform.Output(t, terraformOptions, "cloudwatch_log_group_name") + + // Validate values returned by terraform assert.NotNil(t, arn) + assert.Equal(t, "eg-ue2-test-" + randID + "-example-complete", function_name) + assert.Equal(t, "eg-ue2-test-" + randID + "-example-complete-us-east-2", role_name) + assert.Equal(t, "/aws/lambda/eg-ue2-test-" + randID + "-example-complete", cloudwatch_log_group_name) sess := session.Must(session.NewSessionWithOptions(session.Options{ SharedConfigState: session.SharedConfigEnable,