Skip to content

Commit

Permalink
lambda terraform initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
zLukas committed Oct 6, 2023
1 parent a240013 commit 283ba3f
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
33 changes: 33 additions & 0 deletions terraform/modules/lambda/iam.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
data "aws_iam_policy_document" "lambda_assume_role" {
statement {
effect = "Allow"

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

actions = ["sts:AssumeRole"]
}
}

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

data "aws_iam_policy_document" "lambda_policy_doc" {
statement {
effect = "Allow"
actions = var.lambda_iam_actions

resources = var.lambda_iam_resources
}
}

resource "aws_iam_policy" "lambda_permissions" {
name = "lambda_permissions"
path = "/"
description = "IAM policy for Lambda"
policy = data.aws_iam_policy_document.lambda_policy_doc.json
}
18 changes: 18 additions & 0 deletions terraform/modules/lambda/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
resource "aws_lambda_function" "test_lambda" {
# If the file is not in the current working directory you will need to include a
# path.module in the filename.
filename = "lambda_function_payload.zip"
function_name = "lambda_function_name"
role = aws_iam_role.iam_for_lambda.arn
handler = "index.test"

source_code_hash = data.archive_file.lambda.output_base64sha256

runtime = "nodejs18.x"

environment {
variables = {
foo = "bar"
}
}
}
Empty file.
5 changes: 5 additions & 0 deletions terraform/modules/lambda/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
provider "aws" {
region = var.region
access_key = var.access_key
secret_key = var.secret_key
}
30 changes: 30 additions & 0 deletions terraform/modules/lambda/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
variable access_key {
type = string
}

variable secret_key {
type = string
}

variable region {
type = string
}

variable lambda_name {
type = string
}

variable env_vars {
type = list(object({
name = string
value = string
}))
}

variable lambda_iam_actions {
type = list(string)
}

variable lambda_iam_resources {
type = list(string)
}

0 comments on commit 283ba3f

Please sign in to comment.