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

[d/aws_lambda_function] Remove default qualifier #5812

Merged
merged 1 commit into from
Feb 24, 2019
Merged

[d/aws_lambda_function] Remove default qualifier #5812

merged 1 commit into from
Feb 24, 2019

Conversation

stefansundin
Copy link
Contributor

@stefansundin stefansundin commented Sep 7, 2018

Changes proposed in this pull request:

  • Remove the default qualifier from aws_lambda_function data source to make arn property consistent.

I spent a few hours trying to debug a problem until I realized that the aws_lambda_function data source was appending :$LATEST to the arn.

Intuitively, aws_lambda_function.lambda.arn and data.aws_lambda_function.lambda.arn would return the same value.

resource "aws_lambda_function" "lambda" {
  function_name    = "test-lambda"
  filename         = "test-lambda.zip"
  handler          = "test-lambda"
  source_code_hash = "${data.archive_file.test-lambda.output_base64sha256}"
  role             = "${aws_iam_role.test-lambda.arn}"
  runtime          = "go1.x"
  memory_size      = 128
  timeout          = 30
  description      = "Test"
}
data "aws_lambda_function" "lambda" {
  function_name = "test-lambda"
}

But this is required at the moment:

data "aws_lambda_function" "lambda" {
  function_name = "test-lambda"
  qualifier     = ""
}

In my use case, I was trying to use the data source together with aws_cloudwatch_log_subscription_filter before I realized that my destination_arn had :$LATEST appended. Adding qualifier="" solved it.

I have tried to see what difference $LATEST does, but I think only the arn changes. I have compared the output from aws lambda get-function --function-name test-lambda and aws lambda get-function --function-name test-lambda --qualifier '$LATEST' and only FunctionArn changes. I have not been able to otherwise identify any reason for the default value.

Thank you!!

Output from acceptance testing:

$ make testacc TEST=./aws TESTARGS='-run=TestAccDataSourceAWSLambdaFunction_basic'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccDataSourceAWSLambdaFunction_basic -timeout 120m
=== RUN   TestAccDataSourceAWSLambdaFunction_basic
--- PASS: TestAccDataSourceAWSLambdaFunction_basic (26.74s)
PASS
ok  	github.com/stefansundin/terraform-provider-aws/aws	26.784s


$ make testacc TEST=./aws TESTARGS='-run=TestAccDataSourceAWSLambdaFunction_basic'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccDataSourceAWSLambdaFunction_basic -timeout 120m
=== RUN   TestAccDataSourceAWSLambdaFunction_basic
--- PASS: TestAccDataSourceAWSLambdaFunction_basic (36.77s)
PASS
ok  	github.com/stefansundin/terraform-provider-aws/aws	36.808s


$ make testacc TEST=./aws TESTARGS='-run=TestAccDataSourceAWSLambdaFunction_version'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccDataSourceAWSLambdaFunction_version -timeout 120m
=== RUN   TestAccDataSourceAWSLambdaFunction_version
--- PASS: TestAccDataSourceAWSLambdaFunction_version (36.27s)
PASS
ok  	github.com/stefansundin/terraform-provider-aws/aws	36.315s


$ make testacc TEST=./aws TESTARGS='-run=TestAccDataSourceAWSLambdaFunction_alias'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccDataSourceAWSLambdaFunction_alias -timeout 120m
=== RUN   TestAccDataSourceAWSLambdaFunction_alias
--- PASS: TestAccDataSourceAWSLambdaFunction_alias (37.04s)
PASS
ok  	github.com/stefansundin/terraform-provider-aws/aws	37.069s


$ make testacc TEST=./aws TESTARGS='-run=TestAccDataSourceAWSLambdaFunction_vpc'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccDataSourceAWSLambdaFunction_vpc -timeout 120m
=== RUN   TestAccDataSourceAWSLambdaFunction_vpc
--- PASS: TestAccDataSourceAWSLambdaFunction_vpc (36.80s)
PASS
ok  	github.com/stefansundin/terraform-provider-aws/aws	36.832s


$ make testacc TEST=./aws TESTARGS='-run=TestAccDataSourceAWSLambdaFunction_environment'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccDataSourceAWSLambdaFunction_environment -timeout 120m
=== RUN   TestAccDataSourceAWSLambdaFunction_environment
--- PASS: TestAccDataSourceAWSLambdaFunction_environment (28.10s)
PASS
ok  	github.com/stefansundin/terraform-provider-aws/aws	28.139s

(by the way, is there an easy way to run a list of acceptance tests? I tried adding multiple -run but it didn't work)

@bflad bflad added 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 Sep 19, 2018
@bflad bflad added this to the v2.0.0 milestone Nov 12, 2018
bflad added a commit that referenced this pull request 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 merged commit 6c490f1 into hashicorp:master Feb 24, 2019
@bflad
Copy link
Contributor

bflad commented Feb 24, 2019

Thanks for submitting this @stefansundin! This change was included with #7663, which covers a full set of changes for the aws_lambda_function data source in version 2.0.0 of the Terraform AWS Provider. Full notes are available in the CHANGELOG and the Version 2 Upgrade Guide. 🎉

@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. service/lambda Issues and PRs that pertain to the lambda service.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants