Skip to content

Commit

Permalink
feat!: Disable creation of SAM metadata null-resources by default (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonbabenko authored Aug 9, 2023
1 parent 5b2eb57 commit 9c9603c
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 177 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ repos:
rev: v1.81.0
hooks:
- id: terraform_fmt
- id: terraform_wrapper_module_for_each
- id: terraform_validate
- id: terraform_docs
args:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ No modules.
| <a name="input_create_layer"></a> [create\_layer](#input\_create\_layer) | Controls whether Lambda Layer resource should be created | `bool` | `false` | no |
| <a name="input_create_package"></a> [create\_package](#input\_create\_package) | Controls whether Lambda package should be created | `bool` | `true` | no |
| <a name="input_create_role"></a> [create\_role](#input\_create\_role) | Controls whether IAM role for Lambda Function should be created | `bool` | `true` | no |
| <a name="input_create_sam_metadata"></a> [create\_sam\_metadata](#input\_create\_sam\_metadata) | Controls whether the SAM metadata null resource should be created | `bool` | `false` | no |
| <a name="input_create_unqualified_alias_allowed_triggers"></a> [create\_unqualified\_alias\_allowed\_triggers](#input\_create\_unqualified\_alias\_allowed\_triggers) | Whether to allow triggers on unqualified alias pointing to $LATEST version | `bool` | `true` | no |
| <a name="input_create_unqualified_alias_async_event_config"></a> [create\_unqualified\_alias\_async\_event\_config](#input\_create\_unqualified\_alias\_async\_event\_config) | Whether to allow async event configuration on unqualified alias pointing to $LATEST version | `bool` | `true` | no |
| <a name="input_create_unqualified_alias_lambda_function_url"></a> [create\_unqualified\_alias\_lambda\_function\_url](#input\_create\_unqualified\_alias\_lambda\_function\_url) | Whether to use unqualified alias pointing to $LATEST version in Lambda Function URL | `bool` | `true` | no |
Expand Down
4 changes: 2 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ resource "aws_lambda_function_url" "this" {
# to the TF application. The required data is where SAM CLI can find the Lambda function source code
# and what are the resources that contain the building logic.
resource "null_resource" "sam_metadata_aws_lambda_function" {
count = local.create && var.create_package && var.create_function && !var.create_layer ? 1 : 0
count = local.create && var.create_sam_metadata && var.create_package && var.create_function && !var.create_layer ? 1 : 0

triggers = {
# This is a way to let SAM CLI correlates between the Lambda function resource, and this metadata
Expand Down Expand Up @@ -405,7 +405,7 @@ resource "null_resource" "sam_metadata_aws_lambda_function" {
# to the TF application. The required data is where SAM CLI can find the Lambda layer source code
# and what are the resources that contain the building logic.
resource "null_resource" "sam_metadata_aws_lambda_layer_version" {
count = local.create && var.create_package && var.create_layer ? 1 : 0
count = local.create && var.create_sam_metadata && var.create_package && var.create_layer ? 1 : 0

triggers = {
# This is a way to let SAM CLI correlates between the Lambda layer resource, and this metadata
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ variable "create_lambda_function_url" {
default = false
}

variable "create_sam_metadata" {
description = "Controls whether the SAM metadata null resource should be created"
type = bool
default = false
}

variable "putin_khuylo" {
description = "Do you agree that Putin doesn't respect Ukrainian sovereignty and territorial integrity? More info: https://en.wikipedia.org/wiki/Putin_khuylo!"
type = bool
Expand Down
44 changes: 19 additions & 25 deletions wrappers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ terraform {
inputs = {
defaults = { # Default values
create = true
handler = "index.lambda_handler"
runtime = "python3.8"
create = true
tags = {
Terraform = "true"
Environment = "dev"
Expand All @@ -47,9 +45,7 @@ module "wrapper" {
source = "terraform-aws-modules/lambda/aws//wrappers"
defaults = { # Default values
create = true
handler = "index.lambda_handler"
runtime = "python3.8"
create = true
tags = {
Terraform = "true"
Environment = "dev"
Expand All @@ -68,38 +64,36 @@ module "wrapper" {
}
```

## Example: Manage multiple Lambdas in one Terragrunt layer
## Example: Manage multiple S3 buckets in one Terragrunt layer

`eu-west-1/lambdas/terragrunt.hcl`:
`eu-west-1/s3-buckets/terragrunt.hcl`:

```hcl
terraform {
source = "tfr:///terraform-aws-modules/lambda/aws//wrappers"
source = "tfr:///terraform-aws-modules/s3-bucket/aws//wrappers"
# Alternative source:
# source = "git::[email protected]:terraform-aws-modules/terraform-aws-lambda.git//wrappers?ref=master"
# source = "git::[email protected]:terraform-aws-modules/terraform-aws-s3-bucket.git//wrappers?ref=master"
}
inputs = {
defaults = {
create = true
handler = "index.lambda_handler"
runtime = "python3.8"
tags = {
Terraform = "true"
Environment = "dev"
}
force_destroy = true
attach_elb_log_delivery_policy = true
attach_lb_log_delivery_policy = true
attach_deny_insecure_transport_policy = true
attach_require_latest_tls_policy = true
}
items = {
lambda1 = {
function_name = "my-lambda1"
description = "My awesome lambda function"\
source_path = "../src/lambda-function1"
bucket1 = {
bucket = "my-random-bucket-1"
}
lambda2 = {
function_name = "my-lambda2"
description = "My second awesome lambda function"
source_path = "../src/lambda-function2"
bucket2 = {
bucket = "my-random-bucket-2"
tags = {
Secure = "probably"
}
}
}
}
Expand Down
59 changes: 28 additions & 31 deletions wrappers/alias/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ This wrapper does not implement any extra functionality.

```hcl
terraform {
source = "tfr:///terraform-aws-modules/lambda/aws"
source = "tfr:///terraform-aws-modules/lambda/aws//wrappers/alias"
# Alternative source:
# source = "git::[email protected]:terraform-aws-modules/terraform-aws-lambda.git//wrappers/alias?ref=master"
}
inputs = {
defaults = { # Default values
create = true
refresh_alias = true
create = true
tags = {
Terraform = "true"
Environment = "dev"
}
}
items = {
Expand All @@ -42,8 +45,11 @@ module "wrapper" {
source = "terraform-aws-modules/lambda/aws//wrappers/alias"
defaults = { # Default values
create = true
refresh_alias = true
create = true
tags = {
Terraform = "true"
Environment = "dev"
}
}
items = {
Expand All @@ -58,45 +64,36 @@ module "wrapper" {
}
```

## Example: Manage multiple aliases in one Terragrunt layer
## Example: Manage multiple S3 buckets in one Terragrunt layer

`eu-west-1/lambda-aliases/terragrunt.hcl`:
`eu-west-1/s3-buckets/terragrunt.hcl`:

```hcl
terraform {
source = "tfr:///terraform-aws-modules/lambda/aws//wrappers/alias"
source = "tfr:///terraform-aws-modules/s3-bucket/aws//wrappers"
# Alternative source:
# source = "git::[email protected]:terraform-aws-modules/terraform-aws-lambda.git//wrappers/alias?ref=master"
}
dependency "lambda1" {
config_path = "../lambdas/lambda1"
}
dependency "lambda2" {
config_path = "../lambdas/lambda2"
# source = "git::[email protected]:terraform-aws-modules/terraform-aws-s3-bucket.git//wrappers?ref=master"
}
inputs = {
defaults = {
refresh_alias = true
allowed_triggers = {
AnotherAPIGatewayAny = {
service = "apigateway"
source_arn = "arn:aws:execute-api:eu-west-1:135367859851:abcdedfgse/*/*/*"
}
}
force_destroy = true
attach_elb_log_delivery_policy = true
attach_lb_log_delivery_policy = true
attach_deny_insecure_transport_policy = true
attach_require_latest_tls_policy = true
}
items = {
alias1 = {
name = "my-random-alias-1"
function_name = dependency.lambda1.outputs.lambda_function_name
function_version = dependency.lambda1.outputs.lambda_function_version
bucket1 = {
bucket = "my-random-bucket-1"
}
alias2 = {
name = "my-random-alias-2"
function_name = dependency.lambda2.outputs.lambda_function_name
function_version = dependency.lambda2.outputs.lambda_function_version
bucket2 = {
bucket = "my-random-bucket-2"
tags = {
Secure = "probably"
}
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions wrappers/alias/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ module "wrapper" {
create_qualified_alias_async_event_config = try(each.value.create_qualified_alias_async_event_config, var.defaults.create_qualified_alias_async_event_config, true)
create_version_allowed_triggers = try(each.value.create_version_allowed_triggers, var.defaults.create_version_allowed_triggers, true)
create_qualified_alias_allowed_triggers = try(each.value.create_qualified_alias_allowed_triggers, var.defaults.create_qualified_alias_allowed_triggers, true)
name = try(each.value.name, var.defaults.name, null)
description = try(each.value.description, var.defaults.description, null)
function_name = try(each.value.function_name, var.defaults.function_name, null)
function_version = try(each.value.function_version, var.defaults.function_version, null)
name = try(each.value.name, var.defaults.name, "")
description = try(each.value.description, var.defaults.description, "")
function_name = try(each.value.function_name, var.defaults.function_name, "")
function_version = try(each.value.function_version, var.defaults.function_version, "")
routing_additional_version_weights = try(each.value.routing_additional_version_weights, var.defaults.routing_additional_version_weights, {})
maximum_event_age_in_seconds = try(each.value.maximum_event_age_in_seconds, var.defaults.maximum_event_age_in_seconds, null)
maximum_retry_attempts = try(each.value.maximum_retry_attempts, var.defaults.maximum_retry_attempts, null)
destination_on_failure = try(each.value.destination_on_failure, var.defaults.destination_on_failure, null)
destination_on_success = try(each.value.destination_on_success, var.defaults.destination_on_success, null)
allowed_triggers = try(each.value.allowed_triggers, var.defaults.allowed_triggers, {})
event_source_mapping = try(each.value.event_source_mapping, var.defaults.event_source_mapping, {})

}
2 changes: 1 addition & 1 deletion wrappers/alias/versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
terraform {
required_version = ">= 0.13"
required_version = ">= 0.13.1"
}
70 changes: 18 additions & 52 deletions wrappers/deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ terraform {
inputs = {
defaults = { # Default values
create_app = true
create = true
tags = {
Terraform = "true"
Environment = "dev"
Expand All @@ -45,7 +45,7 @@ module "wrapper" {
source = "terraform-aws-modules/lambda/aws//wrappers/deploy"
defaults = { # Default values
create_app = true
create = true
tags = {
Terraform = "true"
Environment = "dev"
Expand All @@ -64,70 +64,36 @@ module "wrapper" {
}
```

## Example: Manage multiple deployment via AWS CodeDeploy in one Terragrunt layer
## Example: Manage multiple S3 buckets in one Terragrunt layer

`eu-west-1/lambda-deploys/terragrunt.hcl`:
`eu-west-1/s3-buckets/terragrunt.hcl`:

```hcl
terraform {
source = "tfr:///terraform-aws-modules/lambda/aws//wrappers/deploy"
source = "tfr:///terraform-aws-modules/s3-bucket/aws//wrappers"
# Alternative source:
# source = "git::[email protected]:terraform-aws-modules/terraform-aws-lambda.git//wrappers/deploy?ref=master"
}
dependency "aliases" {
config_path = "../lambdas-aliases/"
}
dependency "lambda1" {
config_path = "../lambdas/lambda1"
}
dependency "lambda2" {
config_path = "../lambdas/lambda2"
# source = "git::[email protected]:terraform-aws-modules/terraform-aws-s3-bucket.git//wrappers?ref=master"
}
inputs = {
defaults = {
create_app = true
reate_deployment_group = true
create_deployment = true
run_deployment = true
wait_deployment_completion = true
triggers = {
start = {
events = ["DeploymentStart"]
name = "DeploymentStart"
target_arn = "arn:aws:sns:eu-west-1:135367859851:sns1"
}
success = {
events = ["DeploymentSuccess"]
name = "DeploymentSuccess"
target_arn = "arn:aws:sns:eu-west-1:135367859851:sns2"
}
}
force_destroy = true
tags = {
Terraform = "true"
Environment = "dev"
}
attach_elb_log_delivery_policy = true
attach_lb_log_delivery_policy = true
attach_deny_insecure_transport_policy = true
attach_require_latest_tls_policy = true
}
items = {
deploy1 = {
app_name = "my-random-app-1"
deployment_group_name = "something1"
alias_name = dependency.aliases.outputs.wrapper.alias1.lambda_alias_name
function_name = dependency.lambda1.outputs.lambda_function_name
target_version = dependency.lambda1.outputs.lambda_function_version
bucket1 = {
bucket = "my-random-bucket-1"
}
deploy2 = {
app_name = "my-random-app-2"
deployment_group_name = "something2"
alias_name = dependency.aliases.outputs.wrapper.alias2.lambda_alias_name
function_name = dependency.lambda2.outputs.lambda_function_name
target_version = dependency.lambda2.outputs.lambda_function_version
bucket2 = {
bucket = "my-random-bucket-2"
tags = {
Secure = "probably"
}
}
}
}
Expand Down
Loading

0 comments on commit 9c9603c

Please sign in to comment.