Last active
December 6, 2020 01:02
-
-
Save karl-cardenas-coding/cdffce4a3a1e576f542e3aad6cae543a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################ | |
# Lambda Resources Option 3 - Multiple Lambdas | |
################################################ | |
#In this scenario the Lambda is zipped and upload outside of the terraform execution | |
resource "aws_lambda_function" "test_lambda" { | |
s3_bucket = var.code-bucket | |
s3_key = local.signedSourceList[index(local.trimPrefix, "lambda")] | |
# ^ Returns "signed/lambda-3ed11736-6655-4448-935d-659cd0428b90.zip" | |
.... | |
.... | |
} | |
resource "aws_lambda_function" "test_lambda_2" { | |
s3_bucket = var.code-bucket | |
s3_key = local.signedSourceList[index(local.trimPrefix, "postBooks")] | |
# ^ Returns "signed/postBooks-fa44bbee-9f5b-455d-7cfd-14450e4679d.zip" | |
.... | |
.... | |
} | |
data "aws_s3_bucket_objects" "signedLambdas" { | |
bucket = var.code-bucket | |
prefix = "signed/" | |
} | |
locals { | |
signedSourceList = data.aws_s3_bucket_objects.signedLambdas.keys | |
lambdaSource = try(local.signedSourceList[0], null) | |
trimPrefix = [ for item in local.signedSourceList : split("-", trimprefix(item, "signed/"))[0]] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment