liatrio / dora-lambda-tf-module-demo

This is dora-lambda-deploy-demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dora-lambda-tf-module-demo

A Lambda Terraform Module repository for the DORA metrics demo.

To get started with DORA metrics, see this OpenTelemetry DORA Demo instructions.

Table Of Contents

  1. Prereqs
  2. Structure
  3. Getting Started
  4. Module Documentation

Prerequisites

  1. Terraform >= 0.14 (Specify the exact version in versions.tf)
  2. AWS CLI installed and configured
  3. Git
  4. pre-commit
  5. tflint
  6. tfsec

Project Structure

The project follows this directory structure:

project-root/
├── README.md
├── main.tf
├── providers.tf
├── variables.tf
├── outputs.tf
├── versions.tf
├── .pre-commit-config.yaml
├── modules/
│   ├── lambda_func/
│   │   ├── lambda.tf
│   │   ├── variables.tf
│   │   ├── api_gw.tf
│   │   ├── data.tf
│   │   ├── versions.tf
│   │   ├── vpc.tf
│   │   └── outputs.tf
│   └── ...
  • main.tf: This file contains the module that Terraform will deploy - essentially everything contained in /modules/lambda_func.
  • lambda.tf: This file contains the Lambda portion of the configuration and associated permissions in IAM.
  • vpc.tf: This file contains the VPC configuration to deploy Lambda in a private subnet.
  • api_gw.tf: This file contains the API Gateway configuration to expose the REST API for Lambda.
  • provider.tf: This file defines the provider and required version.
  • variables.tf: This file defines variables used in the Terraform configuration.
  • outputs.tf: This file defines any outputs from your Terraform project.
  • .pre-commit-config.yaml: This file contains configurations for pre-commit hooks.
  • code/.lambda_function.py: This file contains the python code that returns a "Hello World" message.

Instructions

1. Clone the Repository

First, clone this repository to your local machine.

git clone <repository_url>

2. Install pre-commit Hooks

Install the pre-commit hooks defined in .pre-commit-config.yaml.

pre-commit install

3. Initialize Terraform

Navigate to the project-root/ directory and initialize Terraform.

cd project-root/
terraform init

4. Configure Variables

Open variables.tf and configure the necessary variables. You can also create a terraform.tfvars file to set these values.

5. Plan and Apply

Run a plan to ensure everything looks good.

terraform plan

If the plan looks good, apply it.

terraform apply

You'll be prompted to confirm that you want to create the resources defined in your main.tf file. Type yes to proceed.

6. Outputs

After terraform apply completes, you'll see outputs defined in outputs.tf.

You can curl the invoke_url output to receive a "Hello World" message.

7. Cleanup

After you are done using the infrastructure or want to start over, run the following command to destroy all the resources created by Terraform:

terraform destroy

Usage of Modules

Modules in the modules/ directory can be used by referring to their path in the main.tf file. For example, to use the lambda_func module:

module "lambda_hello_world" {
  source = "./modules/lambda_func"
  // Variables specific to the lambda_func module
}

Pre-Commit Hooks

This repository uses pre-commit hooks to run terraform fmt, terraform validate before each commit. These hooks ensure that your Terraform files are correctly formatted and validated.

To Run Hooks Manually

You can also manually run the pre-commit hooks with the following command:

pre-commit run --all-files

To Skip Hooks

You can skip pre-commit hooks with the follow command:

git commit --no-verify -m "your commit message"

Terraform Module Documentation

Requirements

Name Version
terraform >= 1.0
archive >= 2.4
aws >= 4.66
null 3.2.2

Providers

Name Version
archive 2.4.2
aws 5.38.0
null 3.2.2

Modules

No modules.

Resources

Name Type
aws_api_gateway_deployment.api_deployment resource
aws_api_gateway_integration.lambda resource
aws_api_gateway_integration.lambda_root resource
aws_api_gateway_method.proxy resource
aws_api_gateway_method.proxy_root resource
aws_api_gateway_resource.proxy resource
aws_api_gateway_rest_api.api_gw resource
aws_iam_policy.lambda_policy resource
aws_iam_role.lambda_role resource
aws_iam_role_policy_attachment.lambda_policy_attachment resource
aws_lambda_function.test_hello_lambda resource
aws_lambda_permission.apigw resource
aws_security_group.lambda_sg resource
aws_subnet.lambda_pvt_subnet resource
aws_vpc.lambda_vpc resource
null_resource.function_binary resource
archive_file.function_archive data source

Inputs

Name Description Type Default Required
aws_region n/a string "us-east-1" no

Outputs

Name Description
binary_path n/a
invoke_url n/a
lambda_arn n/a

About

This is dora-lambda-deploy-demo


Languages

Language:HCL 86.2%Language:Go 10.2%Language:Makefile 2.3%Language:Ruby 1.2%