Skip to content
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

Merged
merged 18 commits into from
Dec 1, 2020
Merged

Add lambda container image support #16512

merged 18 commits into from
Dec 1, 2020

Conversation

bnusunny
Copy link
Contributor

@bnusunny bnusunny commented Dec 1, 2020

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Relates OR Closes #0000

Release note for CHANGELOG:

ENHANCEMENTS

* resource/aws_lambda_function: Lambda support for Container Image

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccAWSLambdaFunction_imageConfig'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSLambdaFunction_imageConfig -timeout 120m
=== RUN   TestAccAWSLambdaFunction_imageConfig
=== PAUSE TestAccAWSLambdaFunction_imageConfig
=== CONT  TestAccAWSLambdaFunction_imageConfig
--- PASS: TestAccAWSLambdaFunction_imageConfig (244.64s)
PASS
ok      github.com/terraform-providers/terraform-provider-aws/aws       247.662s

$ make testacc TESTARGS='-run=TestAccAWSLambdaFunction_basic'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSLambdaFunction_basic -timeout 120m
=== RUN   TestAccAWSLambdaFunction_basic
=== PAUSE TestAccAWSLambdaFunction_basic
=== CONT  TestAccAWSLambdaFunction_basic
--- PASS: TestAccAWSLambdaFunction_basic (90.28s)
PASS
ok      github.com/terraform-providers/terraform-provider-aws/aws       93.439s

@bnusunny bnusunny requested a review from a team as a code owner December 1, 2020 20:00
@ghost ghost added size/XL Managed by automation to categorize the size of a PR. service/lambda Issues and PRs that pertain to the lambda service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Dec 1, 2020
@bflad bflad added this to the v3.19.0 milestone Dec 1, 2020
@bflad bflad added the enhancement Requests to existing resources that expand the functionality or scope. label Dec 1, 2020
@bflad bflad linked an issue Dec 1, 2020 that may be closed by this pull request
Optional: true,
ConflictsWith: []string{"filename", "s3_bucket", "s3_key", "s3_object_version"},
},
"package_type": {
Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor

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)

Copy link
Collaborator

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...

Copy link
Contributor

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 is Image, image_uri must be set and none of filename or s3_* can be set
  • if package_type is Zip, image_uri and image_config cannot be set and either filename or some combination of s3_* 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"},
Copy link
Collaborator

@DrFaust92 DrFaust92 Dec 1, 2020

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.

Copy link
Contributor

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": {
Copy link
Collaborator

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?

Copy link
Contributor

@gdavison gdavison left a 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"),
Copy link
Contributor

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

Suggested change
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$")),
Copy link
Contributor

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

Suggested change
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$")),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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$")),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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")
Copy link
Contributor

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

@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Dec 1, 2020
@gdavison gdavison removed the needs-triage Waiting for first response or review from a maintainer. label Dec 1, 2020
@gdavison
Copy link
Contributor

gdavison commented Dec 1, 2020

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

@gdavison gdavison merged commit a47e360 into hashicorp:master Dec 1, 2020
gdavison added a commit that referenced this pull request Dec 1, 2020
@ghost
Copy link

ghost commented Dec 1, 2020

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!

@ghost
Copy link

ghost commented Jan 1, 2021

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!

@ghost ghost locked as resolved and limited conversation to collaborators Jan 1, 2021
@justinretzolk justinretzolk added the partner Contribution from a partner. label May 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. partner Contribution from a partner. service/lambda Issues and PRs that pertain to the lambda service. size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lambda Container Support
6 participants