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,