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

New Data Source: aws_lambda_function #2984

Merged
merged 2 commits into from
Apr 23, 2018
Merged

Conversation

loivis
Copy link
Contributor

@loivis loivis commented Jan 13, 2018

To get information of lambda function.

Attributes are returned from read function of aws_lambda_function resource. Most of the attributes for resource are available for data source. tags is one exception though because it doesn't exist if qualifier is specified.

@loivis
Copy link
Contributor Author

loivis commented Jan 13, 2018

Not sure why acceptance test for resource lambda function fails sometime and retry will just pass.

⎇  make testacc TEST=./aws TESTARGS='-run=TestAccAWSLambdaFunction'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSLambdaFunction -timeout 120m
=== RUN   TestAccAWSLambdaFunction_importLocalFile
--- PASS: TestAccAWSLambdaFunction_importLocalFile (40.69s)
=== RUN   TestAccAWSLambdaFunction_importLocalFile_VPC
--- PASS: TestAccAWSLambdaFunction_importLocalFile_VPC (37.28s)
=== RUN   TestAccAWSLambdaFunction_importS3
--- PASS: TestAccAWSLambdaFunction_importS3 (38.14s)
=== RUN   TestAccAWSLambdaFunction_basic
--- PASS: TestAccAWSLambdaFunction_basic (38.03s)
=== RUN   TestAccAWSLambdaFunction_concurrency
--- PASS: TestAccAWSLambdaFunction_concurrency (53.49s)
=== RUN   TestAccAWSLambdaFunction_concurrencyCycle
--- PASS: TestAccAWSLambdaFunction_concurrencyCycle (65.14s)
=== RUN   TestAccAWSLambdaFunction_updateRuntime
--- PASS: TestAccAWSLambdaFunction_updateRuntime (55.47s)
=== RUN   TestAccAWSLambdaFunction_expectFilenameAndS3Attributes
--- PASS: TestAccAWSLambdaFunction_expectFilenameAndS3Attributes (16.65s)
=== RUN   TestAccAWSLambdaFunction_envVariables
--- PASS: TestAccAWSLambdaFunction_envVariables (83.29s)
=== RUN   TestAccAWSLambdaFunction_encryptedEnvVariables
--- FAIL: TestAccAWSLambdaFunction_encryptedEnvVariables (66.91s)
	testing.go:513: Step 1 error: Check failed: Check 4/5 error: aws_lambda_function.lambda_function_test: Attribute 'environment.0.variables.foo' not found
=== RUN   TestAccAWSLambdaFunction_versioned
--- PASS: TestAccAWSLambdaFunction_versioned (37.98s)
=== RUN   TestAccAWSLambdaFunction_DeadLetterConfig
--- PASS: TestAccAWSLambdaFunction_DeadLetterConfig (37.96s)
=== RUN   TestAccAWSLambdaFunction_DeadLetterConfigUpdated
--- PASS: TestAccAWSLambdaFunction_DeadLetterConfigUpdated (52.98s)
=== RUN   TestAccAWSLambdaFunction_nilDeadLetterConfig
--- PASS: TestAccAWSLambdaFunction_nilDeadLetterConfig (15.72s)
=== RUN   TestAccAWSLambdaFunction_tracingConfig
--- PASS: TestAccAWSLambdaFunction_tracingConfig (52.04s)
=== RUN   TestAccAWSLambdaFunction_VPC
--- PASS: TestAccAWSLambdaFunction_VPC (35.89s)
=== RUN   TestAccAWSLambdaFunction_VPCUpdate
--- PASS: TestAccAWSLambdaFunction_VPCUpdate (51.68s)
=== RUN   TestAccAWSLambdaFunction_VPC_withInvocation
--- PASS: TestAccAWSLambdaFunction_VPC_withInvocation (57.75s)
=== RUN   TestAccAWSLambdaFunction_s3
--- PASS: TestAccAWSLambdaFunction_s3 (34.87s)
=== RUN   TestAccAWSLambdaFunction_localUpdate
--- PASS: TestAccAWSLambdaFunction_localUpdate (47.31s)
=== RUN   TestAccAWSLambdaFunction_localUpdate_nameOnly
--- PASS: TestAccAWSLambdaFunction_localUpdate_nameOnly (47.18s)
=== RUN   TestAccAWSLambdaFunction_s3Update_basic
--- PASS: TestAccAWSLambdaFunction_s3Update_basic (71.41s)
=== RUN   TestAccAWSLambdaFunction_s3Update_unversioned
--- PASS: TestAccAWSLambdaFunction_s3Update_unversioned (55.60s)
=== RUN   TestAccAWSLambdaFunction_runtimeValidation_noRuntime
--- PASS: TestAccAWSLambdaFunction_runtimeValidation_noRuntime (1.40s)
=== RUN   TestAccAWSLambdaFunction_runtimeValidation_nodeJs43
--- PASS: TestAccAWSLambdaFunction_runtimeValidation_nodeJs43 (36.50s)
=== RUN   TestAccAWSLambdaFunction_runtimeValidation_python27
--- PASS: TestAccAWSLambdaFunction_runtimeValidation_python27 (35.95s)
=== RUN   TestAccAWSLambdaFunction_runtimeValidation_java8
--- PASS: TestAccAWSLambdaFunction_runtimeValidation_java8 (37.37s)
=== RUN   TestAccAWSLambdaFunction_tags
--- PASS: TestAccAWSLambdaFunction_tags (67.01s)
=== RUN   TestAccAWSLambdaFunction_runtimeValidation_python36
--- PASS: TestAccAWSLambdaFunction_runtimeValidation_python36 (37.45s)
FAIL
exit status 1
FAIL	github.com/terraform-providers/terraform-provider-aws/aws	1309.176s
make: *** [testacc] Error 1

⎇  make testacc TEST=./aws TESTARGS='-run=TestAccAWSLambdaFunction_encryptedEnvVariables'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSLambdaFunction_encryptedEnvVariables -timeout 120m
=== RUN   TestAccAWSLambdaFunction_encryptedEnvVariables
--- PASS: TestAccAWSLambdaFunction_encryptedEnvVariables (78.43s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	78.474s

@loivis
Copy link
Contributor Author

loivis commented Jan 14, 2018

  make testacc TEST=./aws TESTARGS='-run=TestAccDataSourceAWSLambdaFunction_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccDataSourceAWSLambdaFunction_ -timeout 120m
=== RUN   TestAccDataSourceAWSLambdaFunction_basic
--- PASS: TestAccDataSourceAWSLambdaFunction_basic (41.44s)
=== RUN   TestAccDataSourceAWSLambdaFunction_version
--- PASS: TestAccDataSourceAWSLambdaFunction_version (41.08s)
=== RUN   TestAccDataSourceAWSLambdaFunction_alias
--- PASS: TestAccDataSourceAWSLambdaFunction_alias (42.43s)
=== RUN   TestAccDataSourceAWSLambdaFunction_vpc
--- PASS: TestAccDataSourceAWSLambdaFunction_vpc (37.63s)
=== RUN   TestAccDataSourceAWSLambdaFunction_environment
--- PASS: TestAccDataSourceAWSLambdaFunction_environment (40.64s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	203.260s

@Ninir Ninir added enhancement Requests to existing resources that expand the functionality or scope. new-resource Introduces a new resource. service/lambda Issues and PRs that pertain to the lambda service. labels Jan 15, 2018
@Puneeth-n
Copy link
Contributor

@Lovis see my issue #2959

@loivis
Copy link
Contributor Author

loivis commented Jan 16, 2018

@Puneeth-n thanks. good to know there is a fix.

@Puneeth-n
Copy link
Contributor

@loivis Nope. No fix.

@t-pascal
Copy link

Plus one for this feature. I have recently needed to import lambda function qualified alias as a data source.

@kazeshini178
Copy link

Any idea when this would be merged into the master branch/released would be really useful?

Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

Sorry for the delay in getting this reviewed. I have some concerns with resource changes breaking modules/outputs. Please let us know if you have any questions.

Otherwise, it looks to be in pretty decent shape.

@@ -161,6 +161,11 @@ func resourceAwsLambdaFunction() *schema.Resource {
Optional: true,
Computed: true,
},
"source_code_size": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Two things:

  • This does not look configurable -- we should remove Optional: true
  • Its not documented in the resource documentation

params := &lambda.GetFunctionInput{
FunctionName: aws.String(d.Get("function_name").(string)),
}

// qualifier for lambda function data source
qualifier, qualifierExistance := d.GetOk("qualifier")
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally speaking, if there starts being logic like this in a shared resource/data source read function, we will want to not reuse the function.

Copy link
Contributor Author

@loivis loivis Apr 21, 2018

Choose a reason for hiding this comment

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

Agree but not sure in this case. It's a choice of duplicating the whole function or adding a few lines to current function. Maybe add qualifier attribute to resource as well although it will always be $LATEST for resource?

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 always adjust this later if necessary as its probably fine the way it currently is. 👍

if vpcSetErr != nil {
return fmt.Errorf("Failed setting vpc_config: %s", vpcSetErr)
vpcConfig := flattenLambdaVpcConfigResponse(function.VpcConfig)
if vpcConfig != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

This will likely break module/output usage. Why was this changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't really recall what I was thinking at that time 🤔

if err := d.Set("environment", flattenLambdaEnvironment(function.Environment)); err != nil {
log.Printf("[ERR] Error setting environment for Lambda Function (%s): %s", d.Id(), err)
environment := flattenLambdaEnvironment(function.Environment)
if environment != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here. This will likely break module/output usage. Why was this changed?

@bflad bflad added waiting-response Maintainers are waiting on response from community or contributor. new-data-source Introduces a new data source. and removed enhancement Requests to existing resources that expand the functionality or scope. new-resource Introduces a new resource. labels Apr 21, 2018
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Apr 21, 2018
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Apr 21, 2018
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Apr 21, 2018
@bflad bflad removed the waiting-response Maintainers are waiting on response from community or contributor. label Apr 23, 2018
@bflad bflad added this to the v1.16.0 milestone Apr 23, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

Thanks for the PR adjustments, this looks great! 🚀

35 tests passed (all tests)
=== RUN   TestAccAWSLambdaFunction_importS3
--- PASS: TestAccAWSLambdaFunction_importS3 (31.87s)
=== RUN   TestAccAWSLambdaFunction_importLocalFile
--- PASS: TestAccAWSLambdaFunction_importLocalFile (90.78s)
=== RUN   TestAccAWSLambdaFunction_importLocalFile_VPC
--- PASS: TestAccAWSLambdaFunction_importLocalFile_VPC (96.75s)
=== RUN   TestAccAWSLambdaFunction_expectFilenameAndS3Attributes
--- PASS: TestAccAWSLambdaFunction_expectFilenameAndS3Attributes (118.00s)
=== RUN   TestAccAWSLambdaFunction_nilDeadLetterConfig
--- PASS: TestAccAWSLambdaFunction_nilDeadLetterConfig (123.49s)
=== RUN   TestAccAWSLambdaFunction_s3
--- PASS: TestAccAWSLambdaFunction_s3 (20.84s)
=== RUN   TestAccAWSLambdaFunction_VPC
--- PASS: TestAccAWSLambdaFunction_VPC (53.65s)
=== RUN   TestAccDataSourceAWSLambdaFunction_environment
--- PASS: TestAccDataSourceAWSLambdaFunction_environment (145.22s)
=== RUN   TestAccAWSLambdaFunction_concurrencyCycle
--- PASS: TestAccAWSLambdaFunction_concurrencyCycle (148.29s)
=== RUN   TestAccDataSourceAWSLambdaFunction_vpc
--- PASS: TestAccDataSourceAWSLambdaFunction_vpc (183.58s)
=== RUN   TestAccAWSLambdaFunction_runtimeValidation_noRuntime
--- PASS: TestAccAWSLambdaFunction_runtimeValidation_noRuntime (0.88s)
=== RUN   TestAccAWSLambdaFunction_updateRuntime
--- PASS: TestAccAWSLambdaFunction_updateRuntime (187.02s)
=== RUN   TestAccAWSLambdaFunction_s3Update_unversioned
--- PASS: TestAccAWSLambdaFunction_s3Update_unversioned (40.62s)
=== RUN   TestAccAWSLambdaFunction_localUpdate
--- PASS: TestAccAWSLambdaFunction_localUpdate (44.85s)
=== RUN   TestAccAWSLambdaFunction_envVariables
--- PASS: TestAccAWSLambdaFunction_envVariables (193.20s)
=== RUN   TestAccAWSLambdaFunction_versioned
--- PASS: TestAccAWSLambdaFunction_versioned (241.47s)
=== RUN   TestAccAWSLambdaFunction_DeadLetterConfigUpdated
--- PASS: TestAccAWSLambdaFunction_DeadLetterConfigUpdated (256.48s)
=== RUN   TestAccAWSLambdaFunction_runtimeValidation_python36
--- PASS: TestAccAWSLambdaFunction_runtimeValidation_python36 (74.15s)
=== RUN   TestAccDataSourceAWSLambdaFunction_alias
--- PASS: TestAccDataSourceAWSLambdaFunction_alias (317.89s)
=== RUN   TestAccAWSLambdaFunction_runtimeValidation_nodeJs43
--- PASS: TestAccAWSLambdaFunction_runtimeValidation_nodeJs43 (136.04s)
=== RUN   TestAccAWSLambdaFunction_runtimeValidation_java8
--- PASS: TestAccAWSLambdaFunction_runtimeValidation_java8 (138.79s)
=== RUN   TestAccAWSLambdaFunction_concurrency
--- PASS: TestAccAWSLambdaFunction_concurrency (349.50s)
=== RUN   TestAccDataSourceAWSLambdaFunction_version
--- PASS: TestAccDataSourceAWSLambdaFunction_version (349.82s)
=== RUN   TestAccAWSLambdaFunction_VPCUpdate
--- PASS: TestAccAWSLambdaFunction_VPCUpdate (259.20s)
=== RUN   TestAccAWSLambdaFunction_versionedUpdate
--- PASS: TestAccAWSLambdaFunction_versionedUpdate (391.44s)
=== RUN   TestAccAWSLambdaFunction_localUpdate_nameOnly
--- PASS: TestAccAWSLambdaFunction_localUpdate_nameOnly (250.17s)
=== RUN   TestAccAWSLambdaFunction_tags
--- PASS: TestAccAWSLambdaFunction_tags (209.43s)
=== RUN   TestAccAWSLambdaFunction_DeadLetterConfig
--- PASS: TestAccAWSLambdaFunction_DeadLetterConfig (429.69s)
=== RUN   TestAccAWSLambdaFunction_basic
--- PASS: TestAccAWSLambdaFunction_basic (443.10s)
=== RUN   TestAccAWSLambdaFunction_runtimeValidation_python27
--- PASS: TestAccAWSLambdaFunction_runtimeValidation_python27 (259.04s)
=== RUN   TestAccAWSLambdaFunction_encryptedEnvVariables
--- PASS: TestAccAWSLambdaFunction_encryptedEnvVariables (462.26s)
=== RUN   TestAccDataSourceAWSLambdaFunction_basic
--- PASS: TestAccDataSourceAWSLambdaFunction_basic (469.13s)
=== RUN   TestAccAWSLambdaFunction_s3Update_basic
--- PASS: TestAccAWSLambdaFunction_s3Update_basic (431.48s)
=== RUN   TestAccAWSLambdaFunction_VPC_withInvocation
--- PASS: TestAccAWSLambdaFunction_VPC_withInvocation (493.76s)
=== RUN   TestAccAWSLambdaFunction_tracingConfig
--- PASS: TestAccAWSLambdaFunction_tracingConfig (599.84s)

@bflad bflad merged commit 25f0a3e into hashicorp:master Apr 23, 2018
bflad added a commit that referenced this pull request Apr 23, 2018
@bflad
Copy link
Contributor

bflad commented Apr 25, 2018

This has been released in version 1.16.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Apr 6, 2020

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 and limited conversation to collaborators Apr 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new-data-source Introduces a new data source. service/lambda Issues and PRs that pertain to the lambda service. size/XL Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants