hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.74k stars 9.1k forks source link

[Enhancement]: Infer `package_type=Image` when `image_uri` is set in `aws_lambda_function` #37784

Open Eitol opened 3 months ago

Eitol commented 3 months ago

Terraform Core Version

1.8.4

AWS Provider Version

5.50.0

Affected Resource(s)

aws_lambda_function

Expected Behavior

Lambda function created

Actual Behavior

The function creation fails with the error: "handler and runtime must be set when PackageType is Zip"

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

resource "aws_lambda_function" "my_lambda" {
  image_uri     = "the image uri"
  function_name = "function_name"
  role          = "arn:aws:iam::101131818121:role/some-role"
  handler       = "index.handler"
  package_type  = "Image"
  runtime       = "nodejs20.x"
  timeout       = "30"
  memory_size   = local.lambda_memory
}

Steps to Reproduce

Create a resource aws_lambda_function with the field package_type empty. Get an error

Debug Output

No response

Panic Output

No response

Important Factoids

When the image_uri is set, the package_type must be explicitly set to 'Image' to avoid errors related to the handler and runtime settings.

References

https://github.com/hashicorp/terraform-provider-aws/issues/21864 https://github.com/hashicorp/terraform-provider-aws/pull/19514

https://stackoverflow.com/questions/76862775/what-is-this-terraform-error-trying-to-tell-me-about-image-configuration-blocks

Would you like to implement a fix?

Yes

github-actions[bot] commented 3 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

justinretzolk commented 2 weeks ago

Hey @Eitol 👋 Thank you for taking the time to raise this! In this case, the provider is behaving as I would expect it to. The package_type argument has a default vault of Zip (this is mentioned in the documentation). When using the Zip package type, the API is reporting that handler and runtime must be set as well -- the error that's then returned by Terraform.

Explicitly setting the package_type to Image is what I would expect to be necessary here. That said, I believe this is something we could validate at the plan stage, which would be more of an enhancement request. Does that seem correct to you?

Eitol commented 2 weeks ago

Hi, yes. I think that's correct. Ideally, since image_uri has been indicated, it is understood that an image is to be used. Therefore, indicating package_type=Image is redundant.