-
Notifications
You must be signed in to change notification settings - Fork 9.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add lambda container image support #16512
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't this just be computed based on s3 / code or image?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I know there's a validator but why even need it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. We typically don't automatically set parameters like this. We should, however, add validation along the lines of:
- if
package_type
isImage
,image_uri
must be set and none offilename
ors3_*
can be set - if
package_type
isZip
,image_uri
andimage_config
cannot be set and eitherfilename
or some combination ofs3_*
must be set
@@ -47,22 +48,57 @@ func resourceAwsLambdaFunction() *schema.Resource { | |||
"filename": { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesnt conflict with zip type arguments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: