github.com/terraform-modules-krish/terratest@v0.29.0/examples/terraform-aws-lambda-example/main.tf (about) 1 # --------------------------------------------------------------------------------------------------------------------- 2 # AWS LAMBDA TERRAFORM EXAMPLE 3 # See test/terraform_aws_lambda_example_test.go for how to write automated tests for this code. 4 # --------------------------------------------------------------------------------------------------------------------- 5 6 provider "archive" { 7 version = "1.3" 8 } 9 10 data "archive_file" "zip" { 11 type = "zip" 12 source_dir = "${path.module}/src" 13 output_path = "${path.module}/${var.function_name}.zip" 14 } 15 16 resource "aws_lambda_function" "lambda" { 17 filename = data.archive_file.zip.output_path 18 source_code_hash = data.archive_file.zip.output_base64sha256 19 function_name = var.function_name 20 role = aws_iam_role.lambda.arn 21 handler = "lambda" 22 runtime = "go1.x" 23 } 24 25 resource "aws_iam_role" "lambda" { 26 name = var.function_name 27 assume_role_policy = data.aws_iam_policy_document.policy.json 28 } 29 30 data "aws_iam_policy_document" "policy" { 31 statement { 32 actions = ["sts:AssumeRole"] 33 principals { 34 type = "Service" 35 identifiers = ["lambda.amazonaws.com"] 36 } 37 } 38 }