Skip to content

Commit

Permalink
Bugfix: Revert Breaking Change in v0.6.0 (#79)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
milldr authored Aug 28, 2024
1 parent 1ea7770 commit 71c4d31
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 4 deletions.
6 changes: 3 additions & 3 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions examples/complete/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions examples/complete/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ terraform {
source = "hashicorp/aws"
version = ">= 3.0"
}
archive = {
source = "hashicorp/archive"
version = ">= 2.0"
}
}
}
5 changes: 4 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
5 changes: 5 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 8 additions & 0 deletions test/src/examples_complete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 71c4d31

Please sign in to comment.