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

data-source/aws_lambda_function: Return unqualified arn attribute by default, properly return error for missing function #7663

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Feb 23, 2019

Builds on #5812
Closes #6966
Additional reference: hashicorp/terraform#10810 (comment)

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

Configuration workarounds such as the following can now be removed:

# This configuration contains previous workarounds, which can be removed after upgrading to version 2.0.0 of the Terraform AWS Provider

# This workaround was used to ensure the arn attribute was never qualified
data "aws_lambda_function" "workaround1" {
  function_name = "example"
  qualifier     = ""
}

# This workaround was used to manually fix the arn attribute which was qualified with :$LATEST previously
data "aws_lambda_function" "workaround2" {
  function_name = "example"
}

output "unqualified_arn" {
  value = "${replace(data.aws_lambda_function.workaround2.arn, ":$LATEST", "")}"
}

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)

@bflad bflad added bug Addresses a defect in current functionality. breaking-change Introduces a breaking change in current functionality; usually deferred to the next major release. service/lambda Issues and PRs that pertain to the lambda service. labels Feb 23, 2019
@bflad bflad added this to the v2.0.0 milestone Feb 23, 2019
@bflad bflad requested a review from a team February 23, 2019 05:54
@ghost ghost added size/XL Managed by automation to categorize the size of a PR. documentation Introduces or discusses updates to documentation. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Feb 23, 2019
…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)
```
@bflad bflad force-pushed the stefansundin-data_source_aws_lambda_function-remove-default-qualifier branch from 0a21383 to ba9e4de Compare February 23, 2019 06:00
@bflad bflad merged commit 6b59e78 into master Feb 24, 2019
@bflad bflad deleted the stefansundin-data_source_aws_lambda_function-remove-default-qualifier branch February 24, 2019 15:00
bflad added a commit that referenced this pull request Feb 24, 2019
bflad added a commit that referenced this pull request Feb 24, 2019
@ghost
Copy link

ghost commented Mar 31, 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 Mar 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking-change Introduces a breaking change in current functionality; usually deferred to the next major release. bug Addresses a defect in current functionality. documentation Introduces or discusses updates to documentation. 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.

aws_lambda_function data source doesn't fail when function doesn't exist
3 participants