Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add null/label context tags to the aws_lambda_function resource #44

Merged
merged 2 commits into from Oct 11, 2023
Merged

fix: Add null/label context tags to the aws_lambda_function resource #44

merged 2 commits into from Oct 11, 2023

Conversation

natemccurdy
Copy link
Contributor

@natemccurdy natemccurdy commented Oct 6, 2023

What

Use tags = module.this.tags on the aws_lambda_function resource.

Why

Prior to this, the aws_lambda_function resource was not getting tagged at all
when passing just the null/label context into the module.

For example, this would end up with a completely untagged Lambda function even
though I am passing the context from a standard null/label declaration:

module "test" {
  source  = "cloudposse/lambda-function/aws"
  version = "0.5.1"

  function_name = "${module.this.id}-test"
  attributes    = ["foo"]
  description   = var.lambda_description
  s3_bucket     = var.lambda_s3_bucket
  s3_key        = var.lambda_s3_key
  runtime       = var.lambda_runtime
  handler       = var.lambda_handler
  context       = module.this.context
}

To get any tags on the lambda, the tags attribute must be used:

module "test" {
  source  = "cloudposse/lambda-function/aws"
  version = "0.5.1"

  function_name = "${module.this.id}-test"
  attributes    = ["foo"]
  description   = var.lambda_description
  s3_bucket     = var.lambda_s3_bucket
  s3_key        = var.lambda_s3_key
  runtime       = var.lambda_runtime
  handler       = var.lambda_handler
  context       = module.this.context
  tags          = module.this.tags
}

This has a couple of problems:

  1. The attributes list is missing from the resultant set of tags.
  2. The requirement of passing an explicit tags attribute is not how other CloudPosse modules work.

Outcome

  • The aws_lambda_function resource is tagged with the implicit tags passed in via context.
  • Tags from the tags variable are still present, but are now merged with the tags from context.
  • This module follows the convetion of other CloudPosse modules.
  • People used to CloudPosse modules will have an easier time using this module.

Gowiem
Gowiem previously approved these changes Oct 9, 2023
@Gowiem
Copy link
Member

Gowiem commented Oct 9, 2023

/terratest

Gowiem
Gowiem previously approved these changes Oct 9, 2023
@Gowiem
Copy link
Member

Gowiem commented Oct 9, 2023

/terratest

@Gowiem Gowiem added patch A minor, backward compatible change minor New features that do not break anything and removed minor New features that do not break anything labels Oct 9, 2023
README.md Outdated Show resolved Hide resolved
docs/terraform.md Outdated Show resolved Hide resolved
Problem:
Prior to this, the `aws_lambda_function` resource was not getting tagged at all
when passing just the null/label context into the module.

For example, this would end up with a completely untagged Lambda function even
though I am passing the context from a standard null/label declaration:

```
module "test" {
  source  = "cloudposse/lambda-function/aws"
  version = "0.5.1"

  function_name = "${module.this.id}-test"
  attributes    = ["foo"]
  description   = var.lambda_description
  s3_bucket     = var.lambda_s3_bucket
  s3_key        = var.lambda_s3_key
  runtime       = var.lambda_runtime
  handler       = var.lambda_handler
  context       = module.this.context
}
```

To get any tags on the lambda, the `tags` attribute must be used:

```
module "test" {
  source  = "cloudposse/lambda-function/aws"
  version = "0.5.1"

  function_name = "${module.this.id}-test"
  attributes    = ["foo"]
  description   = var.lambda_description
  s3_bucket     = var.lambda_s3_bucket
  s3_key        = var.lambda_s3_key
  runtime       = var.lambda_runtime
  handler       = var.lambda_handler
  context       = module.this.context
  tags          = module.this.tags
}
```

The requirement of passing an explicit `tags` attribute is not how other
CloudPosse modules work. In most other CloudPosse modules, you can just pass
around a null/label context and the tags will automatically show up in child
resources.

Solution:

Use `tags = module.this.tags` on the `aws_lambda_function` resource.

Outcome:

* The `aws_lambda_function` resource is tagged with the implicit tags passed in via `context`.
* Tags from the `tags` variable are still present, but are now merged with the tags from `context`.
* This module follows the convetion of other CloudPosse modules.
* People used to CloudPosse modules will have an easier time using this module.
@milldr
Copy link
Sponsor Member

milldr commented Oct 11, 2023

/terratest

@milldr
Copy link
Sponsor Member

milldr commented Oct 11, 2023

/terratest

@milldr milldr enabled auto-merge (squash) October 11, 2023 21:34
@milldr milldr merged commit 18b8620 into cloudposse:main Oct 11, 2023
10 checks passed
@natemccurdy
Copy link
Contributor Author

Thanks @milldr 🍻

@natemccurdy natemccurdy deleted the fix/tags branch October 11, 2023 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch A minor, backward compatible change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants