Skip to content

Commit 68c810e

Browse files
DanyC97heitorlessa
andauthored
docs: Terraform reference for SAR Lambda Layer (#716)
Co-authored-by: heitorlessa <[email protected]>
1 parent dbe45da commit 68c810e

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

docs/index.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,54 @@ If using SAM, you can include this SAR App as part of your shared Layers stack,
124124
)
125125
```
126126

127+
=== "Terraform"
128+
129+
> Credits to [Dani Comnea](https://github.com/DanyC97) for providing the Terraform equivalent.
130+
131+
```terraform hl_lines="12-13 15-20 23-25 40"
132+
terraform {
133+
required_version = "~> 0.13"
134+
required_providers {
135+
aws = "~> 3.50.0"
136+
}
137+
}
138+
139+
provider "aws" {
140+
region = "us-east-1"
141+
}
142+
143+
resource "aws_serverlessapplicationrepository_cloudformation_stack" "deploy_sar_stack" {
144+
name = "aws-lambda-powertools-python-layer"
145+
146+
application_id = data.aws_serverlessapplicationrepository_application.sar_app.application_id
147+
semantic_version = data.aws_serverlessapplicationrepository_application.sar_app.semantic_version
148+
capabilities = [
149+
"CAPABILITY_IAM",
150+
"CAPABILITY_NAMED_IAM"
151+
]
152+
}
153+
154+
data "aws_serverlessapplicationrepository_application" "sar_app" {
155+
application_id = "arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer"
156+
semantic_version = var.aws_powertools_version
157+
}
158+
159+
variable "aws_powertools_version" {
160+
type = string
161+
default = "1.20.2"
162+
description = "The AWS Powertools release version"
163+
}
164+
165+
output "deployed_powertools_sar_version" {
166+
value = data.aws_serverlessapplicationrepository_application.sar_app.semantic_version
167+
}
168+
169+
# Fetch Lambda Powertools Layer ARN from deployed SAR App
170+
output "aws_lambda_powertools_layer_arn" {
171+
value = aws_serverlessapplicationrepository_cloudformation_stack.deploy_sar_stack.outputs.LayerVersionArn
172+
}
173+
```
174+
127175
??? tip "Example of least-privileged IAM permissions to deploy Layer"
128176

129177
> Credits to [mwarkentin](https://github.com/mwarkentin) for providing the scoped down IAM permissions.

0 commit comments

Comments
 (0)