Skip to content

Commit

Permalink
Merge pull request #1209 from santiagoaws/d-improve-awscc_lambda_perm…
Browse files Browse the repository at this point in the history
…ission

docs: add example for awscc_lambda_permission
  • Loading branch information
ewbankkit authored Oct 12, 2023
2 parents bd98c3d + de1e373 commit 4e1bd3f
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 2 deletions.
61 changes: 59 additions & 2 deletions docs/resources/lambda_permission.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "awscc_lambda_permission Resource - terraform-provider-awscc"
subcategory: ""
description: |-
Expand All @@ -10,6 +9,64 @@ description: |-

Resource Type definition for AWS::Lambda::Permission

## Example Usage

### With SNS

To use awscc_lambda_permission with SNS

```terraform
# Creates a Permission to to allow SNS to execute a Lambda function
# This example assumes you have a valid lambdatets.zip
# created on the same directory where you are running your terraform file
resource "awscc_lambda_permission" "with_sns" {
statement_id = "AllowExecutionFromSNS"
action = "lambda:InvokeFunction"
function_name = awscc_lambda_function.func.function_name
principal = "sns.amazonaws.com"
source_arn = awscc_sns_topic.default.arn
}
resource "awscc_sns_topic" "default" {
name = "call-lambda-maybe"
}
resource "awscc_sns_topic_subscription" "lambda" {
topic_arn = awscc_sns_topic.default.arn
protocol = "lambda"
endpoint = awscc_lambda_function.func.arn
}
resource "awscc_lambda_function" "func" {
filename = "lambdatest.zip"
function_name = "lambda_called_from_sns"
role = awscc_iam_role.default.arn
handler = "exports.handler"
runtime = "nodejs16.x"
}
resource "awscc_iam_role" "default" {
name = "iam_for_lambda_with_sns"
# Terraform's "jsonencode" function converts a
# Terraform expression result to valid JSON syntax.
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Sid = ""
Principal = {
Service = "lambda.amazonaws.com"
}
},
]
})
}
```


<!-- schema generated by tfplugindocs -->
Expand Down Expand Up @@ -39,4 +96,4 @@ Import is supported using the following syntax:

```shell
$ terraform import awscc_lambda_permission.example <resource ID>
```
```
50 changes: 50 additions & 0 deletions examples/resources/awscc_lambda_permission/lambda_permission.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Creates a Permission to to allow SNS to execute a Lambda function
# This example assumes you have a valid lambdatets.zip
# created on the same directory where you are running your terraform file


resource "awscc_lambda_permission" "with_sns" {
statement_id = "AllowExecutionFromSNS"
action = "lambda:InvokeFunction"
function_name = awscc_lambda_function.func.function_name
principal = "sns.amazonaws.com"
source_arn = awscc_sns_topic.default.arn
}

resource "awscc_sns_topic" "default" {
name = "call-lambda-maybe"
}

resource "awscc_sns_topic_subscription" "lambda" {
topic_arn = awscc_sns_topic.default.arn
protocol = "lambda"
endpoint = awscc_lambda_function.func.arn
}

resource "awscc_lambda_function" "func" {
filename = "lambdatest.zip"
function_name = "lambda_called_from_sns"
role = awscc_iam_role.default.arn
handler = "exports.handler"
runtime = "nodejs16.x"
}

resource "awscc_iam_role" "default" {
name = "iam_for_lambda_with_sns"

# Terraform's "jsonencode" function converts a
# Terraform expression result to valid JSON syntax.
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Sid = ""
Principal = {
Service = "lambda.amazonaws.com"
}
},
]
})
}
30 changes: 30 additions & 0 deletions templates/resources/lambda_permission.md.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}"
subcategory: ""
description: |-
{{ .Description | plainmarkdown | trimspace | prefixlines " " }}
---

# {{.Name}} ({{.Type}})

{{ .Description | trimspace }}

## Example Usage

### With SNS

To use {{.Name}} with SNS

{{ tffile (printf "examples/resources/%s/lambda_permission.tf" .Name)}}


{{ .SchemaMarkdown | trimspace }}
{{- if .HasImport }}

## Import

Import is supported using the following syntax:

{{ codefile "shell" .ImportFile }}

{{- end }}

0 comments on commit 4e1bd3f

Please sign in to comment.