From eff1b030cd27893321b0fc2b00242c00703771b7 Mon Sep 17 00:00:00 2001 From: Mohamed Elasmar <71043312+moelasmar@users.noreply.github.com> Date: Thu, 7 Jul 2022 21:44:18 -0700 Subject: [PATCH 1/7] feat: Add SAM Metadata resources to enable the integration with SAM CLI tool. --- main.tf | 55 ++++++++++++++++++++++++++++++++ modules/docker-build/main.tf | 14 ++++++++ modules/docker-build/versions.tf | 4 +++ 3 files changed, 73 insertions(+) diff --git a/main.tf b/main.tf index e090e96e..968246e3 100644 --- a/main.tf +++ b/main.tf @@ -108,6 +108,33 @@ resource "aws_lambda_function" "this" { depends_on = [null_resource.archive, aws_s3_object.lambda_package, aws_cloudwatch_log_group.lambda] } +# This resource contains the extra information required by SAM CLI to provide the testing capabilities +# 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_this" { + count = local.create && 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 + # resource + resource_name = "aws_lambda_function.this[0]", + resource_type = "ZIP_LAMBDA_FUNCTION", + + # The Lambda function source code. + original_source_code = jsonencode(var.source_path), + + # a property to let SAM CLI knows where to find the Lambda function source code if the provided + # value for original_source_code attribute is map. + source_code_property = "path", + + # A property to let SAM CLI knows where to find the Lambda function built output + built_output_path = data.external.archive_prepare[0].result.filename + } + + # SAM CLI can run terraform apply -target metadata resource, and this will apply the building + # resources as well + depends_on = [data.external.archive_prepare, null_resource.archive] +} + resource "aws_lambda_layer_version" "this" { count = local.create && var.create_layer ? 1 : 0 @@ -129,6 +156,34 @@ resource "aws_lambda_layer_version" "this" { depends_on = [null_resource.archive, aws_s3_object.lambda_package] } +# This resource contains the extra information required by SAM CLI to provide the testing capabilities +# 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_this" { + count = local.create && 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 + # resource + resource_name = "aws_lambda_layer_version.this[0]", + resource_type = "LAMBDA_LAYER", + + # The Lambda layer source code. + original_source_code = jsonencode(var.source_path), + + # a property to let SAM CLI knows where to find the Lambda layer source code if the provided + # value for original_source_code attribute is map. + source_code_property = "path", + + # A property to let SAM CLI knows where to find the Lambda layer built output + built_output_path = data.external.archive_prepare[0].result.filename + } + + # SAM CLI can run terraform apply -target metadata resource, and this will apply the building + # resources as well + depends_on = [data.external.archive_prepare, null_resource.archive] +} + resource "aws_s3_object" "lambda_package" { count = local.create && var.store_on_s3 && var.create_package ? 1 : 0 diff --git a/modules/docker-build/main.tf b/modules/docker-build/main.tf index 6dd15cc4..941ddbac 100644 --- a/modules/docker-build/main.tf +++ b/modules/docker-build/main.tf @@ -21,6 +21,20 @@ resource "docker_registry_image" "this" { keep_remotely = var.keep_remotely } +# This resource contains the extra information required by SAM CLI to provide the testing capabilities +# to the TF application. This resource will maintain the metadata information about the image type lambda +# functions. It will contain the information required to build the docker image locally. +resource "null_resource" "sam_metadata_docker_registry_image_this" { + triggers = { + resource_type = "IMAGE_LAMBDA_FUNCTION", + docker_context = var.source_path, + docker_file = var.docker_file_path, + docker_build_args = jsonencode(var.build_args), + docker_tag = var.image_tag + } + depends_on = [docker_registry_image.this] +} + resource "aws_ecr_repository" "this" { count = var.create_ecr_repo ? 1 : 0 diff --git a/modules/docker-build/versions.tf b/modules/docker-build/versions.tf index 87ea2d45..c5d4190d 100644 --- a/modules/docker-build/versions.tf +++ b/modules/docker-build/versions.tf @@ -10,5 +10,9 @@ terraform { source = "kreuzwerker/docker" version = ">= 2.12" } + null = { + source = "hashicorp/null" + version = ">= 2.0" + } } } From e73faa39b58908b9eec2e995b7fdeec4bed2d2fa Mon Sep 17 00:00:00 2001 From: Mohamed Elasmar <71043312+moelasmar@users.noreply.github.com> Date: Thu, 7 Jul 2022 21:58:59 -0700 Subject: [PATCH 2/7] fix the formatting issues --- main.tf | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/main.tf b/main.tf index 968246e3..bba5b191 100644 --- a/main.tf +++ b/main.tf @@ -113,11 +113,11 @@ resource "aws_lambda_function" "this" { # and what are the resources that contain the building logic. resource "null_resource" "sam_metadata_aws_lambda_function_this" { count = local.create && var.create_package && var.create_function && !var.create_layer ? 1 : 0 - triggers = { + triggers = { # This is a way to let SAM CLI correlates between the Lambda function resource, and this metadata # resource - resource_name = "aws_lambda_function.this[0]", - resource_type = "ZIP_LAMBDA_FUNCTION", + resource_name = "aws_lambda_function.this[0]", + resource_type = "ZIP_LAMBDA_FUNCTION", # The Lambda function source code. original_source_code = jsonencode(var.source_path), @@ -127,7 +127,7 @@ resource "null_resource" "sam_metadata_aws_lambda_function_this" { source_code_property = "path", # A property to let SAM CLI knows where to find the Lambda function built output - built_output_path = data.external.archive_prepare[0].result.filename + built_output_path = data.external.archive_prepare[0].result.filename } # SAM CLI can run terraform apply -target metadata resource, and this will apply the building @@ -165,8 +165,8 @@ resource "null_resource" "sam_metadata_aws_lambda_layer_version_this" { triggers = { # This is a way to let SAM CLI correlates between the Lambda layer resource, and this metadata # resource - resource_name = "aws_lambda_layer_version.this[0]", - resource_type = "LAMBDA_LAYER", + resource_name = "aws_lambda_layer_version.this[0]", + resource_type = "LAMBDA_LAYER", # The Lambda layer source code. original_source_code = jsonencode(var.source_path), @@ -176,7 +176,7 @@ resource "null_resource" "sam_metadata_aws_lambda_layer_version_this" { source_code_property = "path", # A property to let SAM CLI knows where to find the Lambda layer built output - built_output_path = data.external.archive_prepare[0].result.filename + built_output_path = data.external.archive_prepare[0].result.filename } # SAM CLI can run terraform apply -target metadata resource, and this will apply the building From 39e45b65e2c421f5932e5456c3ab4897dc0ee0da Mon Sep 17 00:00:00 2001 From: Mohamed Elasmar <71043312+moelasmar@users.noreply.github.com> Date: Thu, 7 Jul 2022 22:17:28 -0700 Subject: [PATCH 3/7] updating the readme docs --- README.md | 2 ++ modules/docker-build/README.md | 3 +++ 2 files changed, 5 insertions(+) diff --git a/README.md b/README.md index 6f47a04f..6b6eef1c 100644 --- a/README.md +++ b/README.md @@ -655,6 +655,8 @@ No modules. | [aws_s3_object.lambda_package](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_object) | resource | | [local_file.archive_plan](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource | | [null_resource.archive](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | +| [null_resource.sam_metadata_aws_lambda_function_this](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | +| [null_resource.sam_metadata_aws_lambda_layer_version_this](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | | [aws_arn.log_group_arn](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/arn) | data source | | [aws_cloudwatch_log_group.lambda](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/cloudwatch_log_group) | data source | | [aws_iam_policy.tracing](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy) | data source | diff --git a/modules/docker-build/README.md b/modules/docker-build/README.md index 07da548f..6e99636b 100644 --- a/modules/docker-build/README.md +++ b/modules/docker-build/README.md @@ -55,6 +55,7 @@ module "docker_image" { | [terraform](#requirement\_terraform) | >= 0.13.1 | | [aws](#requirement\_aws) | >= 3.35 | | [docker](#requirement\_docker) | >= 2.12 | +| [null](#requirement\_null) | >= 2.0 | ## Providers @@ -62,6 +63,7 @@ module "docker_image" { |------|---------| | [aws](#provider\_aws) | >= 3.35 | | [docker](#provider\_docker) | >= 2.12 | +| [null](#provider\_null) | >= 2.0 | ## Modules @@ -74,6 +76,7 @@ No modules. | [aws_ecr_lifecycle_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecr_lifecycle_policy) | resource | | [aws_ecr_repository.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecr_repository) | resource | | [docker_registry_image.this](https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources/registry_image) | resource | +| [null_resource.sam_metadata_docker_registry_image_this](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | | [aws_caller_identity.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source | | [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source | From 8acaa098304e7a90e7a39c77ee898d98bb9e67e7 Mon Sep 17 00:00:00 2001 From: Mohamed Elasmar <71043312+moelasmar@users.noreply.github.com> Date: Thu, 28 Jul 2022 14:53:58 -0700 Subject: [PATCH 4/7] Adding some documentation about using SAM CLI for testing. --- README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/README.md b/README.md index 6b6eef1c..ba6a1c2e 100644 --- a/README.md +++ b/README.md @@ -526,6 +526,35 @@ module "lambda_function_existing_package_from_remote_url" { } ``` +## How to use AWS SAM CLI to test Lambda Function? +[AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-command-reference.html) is an open source tool that help the developers to initiate, build, test, and deploy serverless +applications. Currently, SAM CLI tool only supports CFN applications, but SAM CLI team is working on a feature to extend the testing capabilities to support terraform applications (check this [Github issue](https://github.com/aws/aws-sam-cli/issues/3154) +to be updated about the incoming releases, and features included in each release for the Terraform support feature). + +SAM CLI provides two ways of testing, local testing, and testing on-cloud (Accelerate). + +### Local Testing +Using SAM CLI, you can invoke the lambda functions defined in the terraform application locally using the [sam local invoke](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-local-invoke.html) +command, providing the function terraform address, or function name, and to set the `hook-package-id` to `terraform` to tell SAM CLI that the underlying project is a terraform application. + +You can execute the `sam local invoke` command from your terraform application root directory as following: +``` +sam local invoke --hook-package-id terraform module.hello_world_function.aws_lambda_function.this[0] +``` +You can also pass an event to your lambda function, or overwrite its environment variables. Check [here](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-invoke.html) for more information. + +You can also invoke your lambda function in debugging mode, and step-through your lambda function source code locally in your preferred editor. Check [here](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-debugging.html) for more information. + +### Testing on-cloud (Accelerate) +You can use AWS SAM CLI to quickly test your application on your AWS development account. Using SAM Accelerate, you will be able to develop your lambda functions locally, +and once you save your updates, SAM CLI will update your development account with the updated Lambda functions. So, you can test it on cloud, and if there is any bug, +you can quickly update the code, and SAM CLI will take care of pushing it to the cloud. Check [here](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/accelerate.html) for more information about SAM Accelerate. + +You can execute the `sam sync` command from your terraform application root directory as following: +``` +sam sync --hook-package-id terraform --watch +``` + ## How to deploy and manage Lambda Functions? ### Simple deployments From f68132403a8e8564065d328dbf8a3420ddedced5 Mon Sep 17 00:00:00 2001 From: Mohamed Elasmar <71043312+moelasmar@users.noreply.github.com> Date: Tue, 23 Aug 2022 01:05:15 -0700 Subject: [PATCH 5/7] resolve pr comments --- README.md | 2 +- main.tf | 16 ++++++++-------- modules/docker-build/main.tf | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index ba6a1c2e..4285ef07 100644 --- a/README.md +++ b/README.md @@ -531,7 +531,7 @@ module "lambda_function_existing_package_from_remote_url" { applications. Currently, SAM CLI tool only supports CFN applications, but SAM CLI team is working on a feature to extend the testing capabilities to support terraform applications (check this [Github issue](https://github.com/aws/aws-sam-cli/issues/3154) to be updated about the incoming releases, and features included in each release for the Terraform support feature). -SAM CLI provides two ways of testing, local testing, and testing on-cloud (Accelerate). +SAM CLI provides two ways of testing: local testing and testing on-cloud (Accelerate). ### Local Testing Using SAM CLI, you can invoke the lambda functions defined in the terraform application locally using the [sam local invoke](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-local-invoke.html) diff --git a/main.tf b/main.tf index bba5b191..ac43cb42 100644 --- a/main.tf +++ b/main.tf @@ -116,15 +116,15 @@ resource "null_resource" "sam_metadata_aws_lambda_function_this" { triggers = { # This is a way to let SAM CLI correlates between the Lambda function resource, and this metadata # resource - resource_name = "aws_lambda_function.this[0]", - resource_type = "ZIP_LAMBDA_FUNCTION", + resource_name = "aws_lambda_function.this[0]" + resource_type = "ZIP_LAMBDA_FUNCTION" # The Lambda function source code. - original_source_code = jsonencode(var.source_path), + original_source_code = jsonencode(var.source_path) # a property to let SAM CLI knows where to find the Lambda function source code if the provided # value for original_source_code attribute is map. - source_code_property = "path", + source_code_property = "path" # A property to let SAM CLI knows where to find the Lambda function built output built_output_path = data.external.archive_prepare[0].result.filename @@ -165,15 +165,15 @@ resource "null_resource" "sam_metadata_aws_lambda_layer_version_this" { triggers = { # This is a way to let SAM CLI correlates between the Lambda layer resource, and this metadata # resource - resource_name = "aws_lambda_layer_version.this[0]", - resource_type = "LAMBDA_LAYER", + resource_name = "aws_lambda_layer_version.this[0]" + resource_type = "LAMBDA_LAYER" # The Lambda layer source code. - original_source_code = jsonencode(var.source_path), + original_source_code = jsonencode(var.source_path) # a property to let SAM CLI knows where to find the Lambda layer source code if the provided # value for original_source_code attribute is map. - source_code_property = "path", + source_code_property = "path" # A property to let SAM CLI knows where to find the Lambda layer built output built_output_path = data.external.archive_prepare[0].result.filename diff --git a/modules/docker-build/main.tf b/modules/docker-build/main.tf index dd478fb0..dcf2e7f1 100644 --- a/modules/docker-build/main.tf +++ b/modules/docker-build/main.tf @@ -26,10 +26,10 @@ resource "docker_registry_image" "this" { # functions. It will contain the information required to build the docker image locally. resource "null_resource" "sam_metadata_docker_registry_image_this" { triggers = { - resource_type = "IMAGE_LAMBDA_FUNCTION", - docker_context = var.source_path, - docker_file = var.docker_file_path, - docker_build_args = jsonencode(var.build_args), + resource_type = "IMAGE_LAMBDA_FUNCTION" + docker_context = var.source_path + docker_file = var.docker_file_path + docker_build_args = jsonencode(var.build_args) docker_tag = var.image_tag } depends_on = [docker_registry_image.this] From 3acd61263c147c1efd2d7d6ed8eb73bd7f1f6c9e Mon Sep 17 00:00:00 2001 From: Anton Babenko Date: Mon, 31 Oct 2022 16:00:35 +0100 Subject: [PATCH 6/7] Fixed style a bit --- README.md | 1 + main.tf | 111 ++++++++++++++++++----------------- modules/docker-build/main.tf | 31 +++++----- 3 files changed, 73 insertions(+), 70 deletions(-) diff --git a/README.md b/README.md index 727ccedd..9efede69 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ This Terraform module is the part of [serverless.tf framework](https://github.co 3. Create, update, and publish AWS Lambda Function and Lambda Layer - [see usage](#usage). 4. Create static and dynamic aliases for AWS Lambda Function - [see usage](#usage), see [modules/alias](https://github.com/terraform-aws-modules/terraform-aws-lambda/tree/master/modules/alias). 5. Do complex deployments (eg, rolling, canary, rollbacks, triggers) - [read more](#deployment), see [modules/deploy](https://github.com/terraform-aws-modules/terraform-aws-lambda/tree/master/modules/deploy). +6. Use AWS SAM CLI to test Lambda Function - [read more](#sam_cli_integration). ## Features diff --git a/main.tf b/main.tf index 8e668fdd..0746dfcf 100644 --- a/main.tf +++ b/main.tf @@ -126,33 +126,6 @@ resource "aws_lambda_function" "this" { ] } -# This resource contains the extra information required by SAM CLI to provide the testing capabilities -# 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_this" { - count = local.create && 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 - # resource - resource_name = "aws_lambda_function.this[0]" - resource_type = "ZIP_LAMBDA_FUNCTION" - - # The Lambda function source code. - original_source_code = jsonencode(var.source_path) - - # a property to let SAM CLI knows where to find the Lambda function source code if the provided - # value for original_source_code attribute is map. - source_code_property = "path" - - # A property to let SAM CLI knows where to find the Lambda function built output - built_output_path = data.external.archive_prepare[0].result.filename - } - - # SAM CLI can run terraform apply -target metadata resource, and this will apply the building - # resources as well - depends_on = [data.external.archive_prepare, null_resource.archive] -} - resource "aws_lambda_layer_version" "this" { count = local.create && var.create_layer ? 1 : 0 @@ -174,34 +147,6 @@ resource "aws_lambda_layer_version" "this" { depends_on = [null_resource.archive, aws_s3_object.lambda_package] } -# This resource contains the extra information required by SAM CLI to provide the testing capabilities -# 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_this" { - count = local.create && 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 - # resource - resource_name = "aws_lambda_layer_version.this[0]" - resource_type = "LAMBDA_LAYER" - - # The Lambda layer source code. - original_source_code = jsonencode(var.source_path) - - # a property to let SAM CLI knows where to find the Lambda layer source code if the provided - # value for original_source_code attribute is map. - source_code_property = "path" - - # A property to let SAM CLI knows where to find the Lambda layer built output - built_output_path = data.external.archive_prepare[0].result.filename - } - - # SAM CLI can run terraform apply -target metadata resource, and this will apply the building - # resources as well - depends_on = [data.external.archive_prepare, null_resource.archive] -} - resource "aws_s3_object" "lambda_package" { count = local.create && var.store_on_s3 && var.create_package ? 1 : 0 @@ -381,3 +326,59 @@ resource "aws_lambda_function_url" "this" { } } } + +# This resource contains the extra information required by SAM CLI to provide the testing capabilities +# 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_this" { + count = local.create && 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 + # resource + resource_name = "aws_lambda_function.this[0]" + resource_type = "ZIP_LAMBDA_FUNCTION" + + # The Lambda function source code. + original_source_code = jsonencode(var.source_path) + + # a property to let SAM CLI knows where to find the Lambda function source code if the provided + # value for original_source_code attribute is map. + source_code_property = "path" + + # A property to let SAM CLI knows where to find the Lambda function built output + built_output_path = data.external.archive_prepare[0].result.filename + } + + # SAM CLI can run terraform apply -target metadata resource, and this will apply the building + # resources as well + depends_on = [data.external.archive_prepare, null_resource.archive] +} + +# This resource contains the extra information required by SAM CLI to provide the testing capabilities +# 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_this" { + count = local.create && 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 + # resource + resource_name = "aws_lambda_layer_version.this[0]" + resource_type = "LAMBDA_LAYER" + + # The Lambda layer source code. + original_source_code = jsonencode(var.source_path) + + # a property to let SAM CLI knows where to find the Lambda layer source code if the provided + # value for original_source_code attribute is map. + source_code_property = "path" + + # A property to let SAM CLI knows where to find the Lambda layer built output + built_output_path = data.external.archive_prepare[0].result.filename + } + + # SAM CLI can run terraform apply -target metadata resource, and this will apply the building + # resources as well + depends_on = [data.external.archive_prepare, null_resource.archive] +} diff --git a/modules/docker-build/main.tf b/modules/docker-build/main.tf index b81ee541..4ef71597 100644 --- a/modules/docker-build/main.tf +++ b/modules/docker-build/main.tf @@ -21,21 +21,6 @@ resource "docker_registry_image" "this" { keep_remotely = var.keep_remotely } -# This resource contains the extra information required by SAM CLI to provide the testing capabilities -# to the TF application. This resource will maintain the metadata information about the image type lambda -# functions. It will contain the information required to build the docker image locally. -resource "null_resource" "sam_metadata_docker_registry_image_this" { - triggers = { - resource_type = "IMAGE_LAMBDA_FUNCTION" - docker_context = var.source_path - docker_file = var.docker_file_path - docker_build_args = jsonencode(var.build_args) - docker_tag = var.image_tag - built_image_uri = docker_registry_image.this.name - } - depends_on = [docker_registry_image.this] -} - resource "aws_ecr_repository" "this" { count = var.create_ecr_repo ? 1 : 0 @@ -56,3 +41,19 @@ resource "aws_ecr_lifecycle_policy" "this" { policy = var.ecr_repo_lifecycle_policy repository = local.ecr_repo } + +# This resource contains the extra information required by SAM CLI to provide the testing capabilities +# to the TF application. This resource will maintain the metadata information about the image type lambda +# functions. It will contain the information required to build the docker image locally. +resource "null_resource" "sam_metadata_docker_registry_image_this" { + triggers = { + resource_type = "IMAGE_LAMBDA_FUNCTION" + docker_context = var.source_path + docker_file = var.docker_file_path + docker_build_args = jsonencode(var.build_args) + docker_tag = var.image_tag + built_image_uri = docker_registry_image.this.name + } + + depends_on = [docker_registry_image.this] +} From 8c1f7e3589eb0b39c5350566c9db494b82acd0ca Mon Sep 17 00:00:00 2001 From: Anton Babenko Date: Thu, 3 Nov 2022 11:40:43 +0100 Subject: [PATCH 7/7] Removed _this from the resource names --- README.md | 4 ++-- main.tf | 4 ++-- modules/docker-build/README.md | 2 +- modules/docker-build/main.tf | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9195e244..f470ffe6 100644 --- a/README.md +++ b/README.md @@ -712,8 +712,8 @@ No modules. | [aws_s3_object.lambda_package](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_object) | resource | | [local_file.archive_plan](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource | | [null_resource.archive](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | -| [null_resource.sam_metadata_aws_lambda_function_this](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | -| [null_resource.sam_metadata_aws_lambda_layer_version_this](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | +| [null_resource.sam_metadata_aws_lambda_function](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | +| [null_resource.sam_metadata_aws_lambda_layer_version](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | | [aws_arn.log_group_arn](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/arn) | data source | | [aws_cloudwatch_log_group.lambda](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/cloudwatch_log_group) | data source | | [aws_iam_policy.tracing](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy) | data source | diff --git a/main.tf b/main.tf index 0746dfcf..1264c2a7 100644 --- a/main.tf +++ b/main.tf @@ -330,7 +330,7 @@ resource "aws_lambda_function_url" "this" { # This resource contains the extra information required by SAM CLI to provide the testing capabilities # 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_this" { +resource "null_resource" "sam_metadata_aws_lambda_function" { count = local.create && var.create_package && var.create_function && !var.create_layer ? 1 : 0 triggers = { @@ -358,7 +358,7 @@ resource "null_resource" "sam_metadata_aws_lambda_function_this" { # This resource contains the extra information required by SAM CLI to provide the testing capabilities # 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_this" { +resource "null_resource" "sam_metadata_aws_lambda_layer_version" { count = local.create && var.create_package && var.create_layer ? 1 : 0 triggers = { diff --git a/modules/docker-build/README.md b/modules/docker-build/README.md index 940a399e..b835a325 100644 --- a/modules/docker-build/README.md +++ b/modules/docker-build/README.md @@ -76,7 +76,7 @@ No modules. | [aws_ecr_lifecycle_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecr_lifecycle_policy) | resource | | [aws_ecr_repository.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecr_repository) | resource | | [docker_registry_image.this](https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources/registry_image) | resource | -| [null_resource.sam_metadata_docker_registry_image_this](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | +| [null_resource.sam_metadata_docker_registry_image](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | | [aws_caller_identity.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source | | [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source | diff --git a/modules/docker-build/main.tf b/modules/docker-build/main.tf index 4ef71597..c96cfbee 100644 --- a/modules/docker-build/main.tf +++ b/modules/docker-build/main.tf @@ -45,7 +45,7 @@ resource "aws_ecr_lifecycle_policy" "this" { # This resource contains the extra information required by SAM CLI to provide the testing capabilities # to the TF application. This resource will maintain the metadata information about the image type lambda # functions. It will contain the information required to build the docker image locally. -resource "null_resource" "sam_metadata_docker_registry_image_this" { +resource "null_resource" "sam_metadata_docker_registry_image" { triggers = { resource_type = "IMAGE_LAMBDA_FUNCTION" docker_context = var.source_path