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

Suggestion: Add new outputs #332

Open
aoki-h-jp opened this issue Jul 14, 2024 · 0 comments
Open

Suggestion: Add new outputs #332

aoki-h-jp opened this issue Jul 14, 2024 · 0 comments

Comments

@aoki-h-jp
Copy link

Hi, I often use your terraform module because it is very useful to make a layer!

Suggestion

I want to use the layers I created in a cross account, so I need to grant permissions on terraform as follows.

module "lambda_layer_requests" {
  source              = "git::https://github.com/enter-at/terraform-aws-lambda-layer.git?ref=main"
  layer_name          = "cmn-layer-python-requests"
  source_type         = "python"
  package_file        = "./modules/lambda_layer/requests/requirements.txt"
  compatible_runtimes = ["python3.8", "python3.9", "python3.10", "python3.11", "python3.12"]
}

resource "aws_lambda_layer_version_permission" "allow_cross_account_access_requests" {
  for_each = {
    "dev-XXX" = "123456789012",
    "stg-XXX" = "123456789012",
    "prd-XXX" = "123456789012"
  }

  layer_name     = module.lambda_layer_requests.layer_arn
  version_number = tonumber(split(":", module.lambda_layer_requests.arn)[length(split(":", module.lambda_layer_requests.arn)) - 1])
  statement_id   = "AllowCrossAccountAccess-requests-${each.key}"
  principal      = each.value
  action         = "lambda:GetLayerVersion"
}

I would like to make a suggestion about the version_number. This implementation can get the version_number, but I would like to avoid this implementation because it is like a hard-coded.

So, Can you implement on output.tf like this?

output "version_number" {
  value       = tonumber(split(":", aws_lambda_layer_version.main.arn)[length(split(":", aws_lambda_layer_version.main.arn)) - 1])
  description = "The Lamba layer version number."
}

I hope this module will be used by more developers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant