-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
aws_lambda_function data source doesn't fail when function doesn't exist #6966
Comments
…nd refactor testing to check data source state values against the resource state values References: * #5812 * hashicorp/terraform#10810 (comment) * #6966 Previously, the `aws_lambda_function` data source was utilizing the Read function from the `aws_lambda_function` resource. This legacy practice has longterm maintenance issues with missing schema and documentation updates. Here we implement a fresh new Read function for the data source that includes the following changes: * Properly error when Lambda Function is not found * Always return the `arn` attribute as unqualified (e.g. without a qualifier or version suffix) * Always return the `qualified_arn` attribute as qualified (e.g. with the qualifier or version suffix) * Always return the `tags` attribute The acceptance testing changes modernize and simplify the testing: * Utilize `resource.TestCheckResourceAttrPair()` where possible to ensure data source state values match appropriate resource state values * Consolidate random naming to single variable * Only provision VPC resources in VPC specific test Output from acceptance testing: ``` --- PASS: TestAccDataSourceAWSLambdaFunction_version (20.89s) --- PASS: TestAccDataSourceAWSLambdaFunction_environment (22.75s) --- PASS: TestAccDataSourceAWSLambdaFunction_alias (23.68s) --- PASS: TestAccDataSourceAWSLambdaFunction_basic (23.76s) --- PASS: TestAccDataSourceAWSLambdaFunction_layers (28.82s) --- PASS: TestAccDataSourceAWSLambdaFunction_vpc (36.48s) ```
Fix submitted: #7663 👍 |
The fix for this has been merged and will release in version 2.0.0 of the Terraform AWS Provider, likely in the next week or two. Thanks for reporting this, @apparentlymart! |
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
Terraform Version
I am currently testing with a v0.12.0 prerelease build, but I have verified that this bug is still present in master at the time I write this issue.
Affected Resource(s)
data.aws_lambda_function
Terraform Configuration Files
Expected Behavior
As with all data sources, the read request should fail with an error if the requested function doesn't exist.
Actual Behavior
Because the data source shares the same read function with the corresponding managed resource type, a failure results in an invalid object (with all of its attributes empty) being left in the state.
https://github.com/terraform-providers/terraform-provider-aws/blob/25303d5f4b90adab9d0f08d0d7b397cace7c3532/aws/data_source_aws_lambda_function.go#L151-L154
This is annoying because it causes the problem to be hidden and crop up instead as difficult-to-debug downstream problems, such as errors about required fields on other resources not being populated.
In my case, I was using the
arn
attribute to populate an IAM policy, leading to the following unhelpful error:This is resulting from it attempting to specify the
Resource
in the policy as the empty string, becausedata.aws_lambda_function.auth.arn
isn't populated.The text was updated successfully, but these errors were encountered: