A Lambda Terraform Module repository for the DORA metrics demo.
To get started with DORA metrics, see this OpenTelemetry DORA Demo instructions.
- Terraform >= 0.14 (Specify the exact version in
versions.tf
) - AWS CLI installed and configured
- Git
- pre-commit
- tflint
- tfsec
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.
First, clone this repository to your local machine.
git clone <repository_url>
Install the pre-commit hooks defined in .pre-commit-config.yaml
.
pre-commit install
Navigate to the project-root/
directory and initialize Terraform.
cd project-root/
terraform init
Open variables.tf
and configure the necessary variables. You can also create
a terraform.tfvars
file to set these values.
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.
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.
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
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
}
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.
You can also manually run the pre-commit hooks with the following command:
pre-commit run --all-files
You can skip pre-commit hooks with the follow command:
git commit --no-verify -m "your commit message"
Name | Version |
---|---|
terraform | >= 1.0 |
archive | >= 2.4 |
aws | >= 4.66 |
null | 3.2.2 |
Name | Version |
---|---|
archive | 2.4.2 |
aws | 5.38.0 |
null | 3.2.2 |
No modules.
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 |
Name | Description | Type | Default | Required |
---|---|---|---|---|
aws_region | n/a | string |
"us-east-1" |
no |
Name | Description |
---|---|
binary_path | n/a |
invoke_url | n/a |
lambda_arn | n/a |