github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/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 terraform { 7 # This module is now only being tested with Terraform 0.13.x. However, to make upgrading easier, we are setting 8 # 0.12.26 as the minimum version, as that version added support for required_providers with source URLs, making it 9 # forwards compatible with 0.13.x code. 10 required_version = ">= 0.12.26" 11 } 12 13 provider "archive" { 14 version = "1.3" 15 } 16 17 data "archive_file" "zip" { 18 type = "zip" 19 source_dir = "${path.module}/src" 20 output_path = "${path.module}/${var.function_name}.zip" 21 } 22 23 resource "aws_lambda_function" "lambda" { 24 filename = data.archive_file.zip.output_path 25 source_code_hash = data.archive_file.zip.output_base64sha256 26 function_name = var.function_name 27 role = aws_iam_role.lambda.arn 28 handler = "lambda" 29 runtime = "go1.x" 30 } 31 32 resource "aws_iam_role" "lambda" { 33 name = var.function_name 34 assume_role_policy = data.aws_iam_policy_document.policy.json 35 } 36 37 data "aws_iam_policy_document" "policy" { 38 statement { 39 actions = ["sts:AssumeRole"] 40 principals { 41 type = "Service" 42 identifiers = ["lambda.amazonaws.com"] 43 } 44 } 45 }