Add lambda container image support#16512
Conversation
# Conflicts: # website/docs/r/lambda_function.html.markdown
| Optional: true, | ||
| ConflictsWith: []string{"filename", "s3_bucket", "s3_key", "s3_object_version"}, | ||
| }, | ||
| "package_type": { |
There was a problem hiding this comment.
Can't this just be computed based on s3 / code or image?
There was a problem hiding this comment.
I mean, you can now end up in a situation where a user will choose a ZIP and an image which isn't correct
There was a problem hiding this comment.
(I know there's a validator but why even need it)
There was a problem hiding this comment.
What if AWS adds support for another archive type later on? im assuming the API was designed to be open for expansion in the future, we should follow the API. https://www.joelonsoftware.com/2002/11/11/the-law-of-leaky-abstractions/ and such...
There was a problem hiding this comment.
Good catch. We typically don't automatically set parameters like this. We should, however, add validation along the lines of:
- if
package_typeisImage,image_urimust be set and none offilenameors3_*can be set - if
package_typeisZip,image_uriandimage_configcannot be set and eitherfilenameor some combination ofs3_*must be set
| Type: schema.TypeString, | ||
| Optional: true, | ||
| ConflictsWith: []string{"s3_bucket", "s3_key", "s3_object_version"}, | ||
| ConflictsWith: []string{"s3_bucket", "s3_key", "s3_object_version", "image_uri"}, |
There was a problem hiding this comment.
Maybe a good chance to substitute with ExactlyOneOf: []string{"filename", "s3_bucket", "image_uri"} this will save the custom check below.
There was a problem hiding this comment.
Good idea. We should probably also set RequiredWith: []string{"s3_key"} on s3_bucket
| Default: lambda.PackageTypeZip, | ||
| ValidateFunc: validation.StringInSlice(lambda.PackageType_Values(), false), | ||
| }, | ||
| "image_config": { |
There was a problem hiding this comment.
this doesnt conflict with zip type arguments?
gdavison
left a comment
There was a problem hiding this comment.
A couple tweaks to the tests
| testAccCheckResourceAttrRegionalARN(resourceName, "arn", "lambda", fmt.Sprintf("function:%s", funcName)), | ||
| testAccCheckAwsLambdaFunctionInvokeArn(resourceName, &conf), | ||
| resource.TestCheckResourceAttr(resourceName, "package_type", lambda.PackageTypeImage), | ||
| resource.TestCheckResourceAttrSet(resourceName, "image_uri"), |
There was a problem hiding this comment.
This isn't needed since we're checking the value below
| resource.TestCheckResourceAttrSet(resourceName, "image_uri"), |
| testAccCheckAwsLambdaFunctionInvokeArn(resourceName, &conf), | ||
| resource.TestCheckResourceAttr(resourceName, "package_type", lambda.PackageTypeImage), | ||
| resource.TestCheckResourceAttrSet(resourceName, "image_uri"), | ||
| resource.TestMatchResourceAttr(resourceName, "image_uri", regexp.MustCompile("lambda-image-function:latest$")), |
There was a problem hiding this comment.
We can check for this to match imageLatestID from above
| resource.TestMatchResourceAttr(resourceName, "image_uri", regexp.MustCompile("lambda-image-function:latest$")), | |
| resource.TestCheckResourceAttr(resourceName, "image_uri", imageLatestID), |
| Config: testAccAWSLambdaImageConfigUpdateCode(funcName, policyName, roleName, sgName, imageV1ID), | ||
| Check: resource.ComposeTestCheckFunc( | ||
| testAccCheckAwsLambdaFunctionExists(resourceName, funcName, &conf), | ||
| resource.TestMatchResourceAttr(resourceName, "image_uri", regexp.MustCompile("lambda-image-function:v1$")), |
There was a problem hiding this comment.
| resource.TestMatchResourceAttr(resourceName, "image_uri", regexp.MustCompile("lambda-image-function:v1$")), | |
| resource.TestCheckResourceAttr(resourceName, "image_uri", imageV1ID), |
| Config: testAccAWSLambdaImageConfigUpdateConfig(funcName, policyName, roleName, sgName, imageV2ID), | ||
| Check: resource.ComposeTestCheckFunc( | ||
| testAccCheckAwsLambdaFunctionExists(resourceName, funcName, &conf), | ||
| resource.TestMatchResourceAttr(resourceName, "image_uri", regexp.MustCompile("lambda-image-function:v2$")), |
There was a problem hiding this comment.
| resource.TestMatchResourceAttr(resourceName, "image_uri", regexp.MustCompile("lambda-image-function:v2$")), | |
| resource.TestCheckResourceAttr(resourceName, "image_uri", imageV2ID), |
| if !hasFilename && !bucketOk && !keyOk && !versionOk { | ||
| return errors.New("filename or s3_* attributes must be set") | ||
| if !hasFilename && !bucketOk && !keyOk && !versionOk && !hasImageUri { | ||
| return errors.New("filename, s3_* or image_uri attributes must be set") |
There was a problem hiding this comment.
This change is causing a failure in the test TestAccAWSLambdaFunction_expectFilenameAndS3Attributes
|
Thanks for the validation suggestions, @stack72 and @DrFaust92. We're going to add those in later so that we can get the container support released today |
|
This has been released in version 3.19.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks! |
|
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
Community Note
Relates OR Closes #0000
Release note for CHANGELOG:
Output from acceptance testing: