Skip to content

Commit

Permalink
docs: Terraform reference for SAR Lambda Layer (#716)
Browse files Browse the repository at this point in the history
Co-authored-by: heitorlessa <[email protected]>
  • Loading branch information
DanyC97 and heitorlessa authored Oct 1, 2021
1 parent dbe45da commit 68c810e
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,54 @@ 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"
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.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"

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

0 comments on commit 68c810e

Please sign in to comment.