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