From bcdb540b581da2e9948b900dfabe9aa926d95911 Mon Sep 17 00:00:00 2001 From: DanyC97 Date: Thu, 30 Sep 2021 22:01:20 +0100 Subject: [PATCH 1/5] docs: Install the lambda SAR layer using Terraform Currently the documentation provides example of installing the deploying the SAR app using various frameworks. This commit extend the list by providing a Terraform example. --- docs/index.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/docs/index.md b/docs/index.md index 781a96e2eb3..e7016896c4e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -124,6 +124,47 @@ If using SAM, you can include this SAR App as part of your shared Layers stack, ) ``` +=== "Terraform" + + ```ruby hl_lines="24-25" + terraform { + required_version = "~> 0.13" + required_providers { + aws = "~> 3.50.0" + } + } + + provider "aws" { + region = "us-east-1" + } + + resource "aws_serverlessapplicationrepository_cloudformation_stack" "deploy_sar_stack" { + name = "aws-lambda-powertools-python-layer" + + application_id = data.aws_serverlessapplicationrepository_application.sar_app.application_id + semantic_version = data.aws_serverlessapplicationrepository_application.sar_app.semantic_version + capabilities = [ + "CAPABILITY_IAM", + "CAPABILITY_NAMED_IAM" + ] + } + + data "aws_serverlessapplicationrepository_application" "sar_app" { + application_id = "arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer" + semantic_version = var.aws_powertools_version + } + + variable "aws_powertools_version" { + type = string + default = "1.20.2" + description = "The AWS Powertools release version" + } + + output "deployed_powertools_sar_version" { + value = data.aws_serverlessapplicationrepository_application.app.semantic_version + } + ``` + ??? tip "Example of least-privileged IAM permissions to deploy Layer" > Credits to [mwarkentin](https://github.com/mwarkentin) for providing the scoped down IAM permissions. From bd05763af0913f318a4e5539562b86a616b1a7ef Mon Sep 17 00:00:00 2001 From: heitorlessa Date: Fri, 1 Oct 2021 13:13:42 +0200 Subject: [PATCH 2/5] chore: use `terraform` HCL highlighter Signed-off-by: heitorlessa --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index e7016896c4e..40dc8687f51 100644 --- a/docs/index.md +++ b/docs/index.md @@ -126,7 +126,7 @@ If using SAM, you can include this SAR App as part of your shared Layers stack, === "Terraform" - ```ruby hl_lines="24-25" + ```terraform hl_lines="24-25" terraform { required_version = "~> 0.13" required_providers { From de554024d82376eb0be454a317a0d0d7fe6b2249 Mon Sep 17 00:00:00 2001 From: heitorlessa Date: Fri, 1 Oct 2021 13:24:20 +0200 Subject: [PATCH 3/5] fix: increase highlight, fix output var typo Signed-off-by: heitorlessa --- docs/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index 40dc8687f51..7c9af10c550 100644 --- a/docs/index.md +++ b/docs/index.md @@ -126,7 +126,7 @@ If using SAM, you can include this SAR App as part of your shared Layers stack, === "Terraform" - ```terraform hl_lines="24-25" + ```terraform hl_lines="12-13 15-20 23-25" terraform { required_version = "~> 0.13" required_providers { @@ -161,7 +161,7 @@ If using SAM, you can include this SAR App as part of your shared Layers stack, } output "deployed_powertools_sar_version" { - value = data.aws_serverlessapplicationrepository_application.app.semantic_version + value = data.aws_serverlessapplicationrepository_application.sar_app.semantic_version } ``` From ff82df0b5c733eb4b74277db34295b80b838205a Mon Sep 17 00:00:00 2001 From: heitorlessa Date: Fri, 1 Oct 2021 13:33:30 +0200 Subject: [PATCH 4/5] feat: add layers ARN in the output Signed-off-by: heitorlessa --- docs/index.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 7c9af10c550..92bd22c5883 100644 --- a/docs/index.md +++ b/docs/index.md @@ -126,7 +126,7 @@ If using SAM, you can include this SAR App as part of your shared Layers stack, === "Terraform" - ```terraform hl_lines="12-13 15-20 23-25" + ```terraform hl_lines="12-13 15-20 23-25 40" terraform { required_version = "~> 0.13" required_providers { @@ -163,6 +163,11 @@ If using SAM, you can include this SAR App as part of your shared Layers stack, output "deployed_powertools_sar_version" { value = data.aws_serverlessapplicationrepository_application.sar_app.semantic_version } + + # Fetch Lambda Powertools Layer ARN from deployed SAR App + output "aws_lambda_powertools_layer_arn" { + value = aws_serverlessapplicationrepository_cloudformation_stack.deploy_sar_stack.outputs.LayerVersionArn + } ``` ??? tip "Example of least-privileged IAM permissions to deploy Layer" From e053bb2e4e6c3e66a8fa0a1489bd512879676d8d Mon Sep 17 00:00:00 2001 From: heitorlessa Date: Fri, 1 Oct 2021 13:34:17 +0200 Subject: [PATCH 5/5] chore: add credit where is due Signed-off-by: heitorlessa --- docs/index.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/index.md b/docs/index.md index 92bd22c5883..b79a2e7074f 100644 --- a/docs/index.md +++ b/docs/index.md @@ -126,6 +126,8 @@ If using SAM, you can include this SAR App as part of your shared Layers stack, === "Terraform" + > Credits to [Dani Comnea](https://github.com/DanyC97) for providing the Terraform equivalent. + ```terraform hl_lines="12-13 15-20 23-25 40" terraform { required_version = "~> 0.13"