This template sets up a basic AWS Lambda function with an IAM role and a zipped source file.

Terraform Template

data "archive_file" "lambda" {
}

data "aws_iam_policy_document" "assume_role" {

  statement {
    actions = ["sts:AssumeRole"]
    effect = "Allow"

    principals {
      identifiers = ["lambda.amazonaws.com"]
      type = "Service"
    }
  }
}

resource "aws_iam_role" "iam_for_lambda" {
  assume_role_policy = data.aws_iam_policy_document.assume_role.json
  name = "iam_for_lambda"
}

resource "aws_lambda_function" "test_lambda" {
}