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 support for lambda permission import #9369

Merged
merged 9 commits into from
Aug 2, 2019

Conversation

chaspy
Copy link
Contributor

@chaspy chaspy commented Jul 16, 2019

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" comments, they generate extra noise for pull request followers and do not help prioritize the request

Fixes #9357

Release note for CHANGELOG:

resource/aws_lambda_permission: Support resource import

Output from acceptance testing:

make testacc TESTARGS='-run=TestAccAWSCloudWatchEventTarget_basic' 
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -parallel 20 -run=TestAccAWSCloudWatchEventTarget_basic -timeout 120m
?   	github.com/terraform-providers/terraform-provider-aws	[no test files]
=== RUN   TestAccAWSCloudWatchEventTarget_basic
=== PAUSE TestAccAWSCloudWatchEventTarget_basic
=== CONT  TestAccAWSCloudWatchEventTarget_basic
--- PASS: TestAccAWSCloudWatchEventTarget_basic (58.64s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	58.721s

@ghost ghost added size/S 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. documentation Introduces or discusses updates to documentation. labels Jul 16, 2019
@chaspy chaspy force-pushed the chaspy/import_lambda_permission branch from f9ff909 to 973f7ed Compare July 21, 2019 17:46
@chaspy chaspy marked this pull request as ready for review July 21, 2019 17:52
@chaspy chaspy requested a review from a team July 21, 2019 17:52
@bflad bflad added the enhancement Requests to existing resources that expand the functionality or scope. label Jul 24, 2019
@chaspy
Copy link
Contributor Author

chaspy commented Jul 28, 2019

@ryndaniels Please review 🙏

Copy link
Contributor

@ryndaniels ryndaniels left a comment

Choose a reason for hiding this comment

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

Hi @chaspy 👋 Thanks for this contribution! Overall this looks good - there's just a couple changes we'd like to see in the tests and the docs, so if you're able to make those and re-run the acceptance tests on your end, we can keep moving forward with this. Thanks! 😄

aws/resource_aws_lambda_permission_test.go Show resolved Hide resolved
website/docs/r/lambda_permission.html.markdown Outdated Show resolved Hide resolved
@chaspy chaspy force-pushed the chaspy/import_lambda_permission branch from 8c884cc to d3fde85 Compare July 30, 2019 10:39
@ghost ghost added size/M Managed by automation to categorize the size of a PR. and removed size/S Managed by automation to categorize the size of a PR. labels Jul 30, 2019
@chaspy
Copy link
Contributor Author

chaspy commented Jul 30, 2019

$ make testacc TESTARGS='-run=TestAccAWSCloudWatchEventTarget_basic'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -parallel 20 -run=TestAccAWSCloudWatchEventTarget_basic -timeout 120m

=== RUN   TestAccAWSCloudWatchEventTarget_basic
=== PAUSE TestAccAWSCloudWatchEventTarget_basic
=== CONT  TestAccAWSCloudWatchEventTarget_basic
--- PASS: TestAccAWSCloudWatchEventTarget_basic (67.61s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	67.690s

$ make testacc TESTARGS='-run=TestAccAWSLambdaPermission_withRawFunctionName' 
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -parallel 20 -run=TestAccAWSLambdaPermission_withRawFunctionName -timeout 120m

=== RUN   TestAccAWSLambdaPermission_withRawFunctionName
=== PAUSE TestAccAWSLambdaPermission_withRawFunctionName
=== CONT  TestAccAWSLambdaPermission_withRawFunctionName
--- FAIL: TestAccAWSLambdaPermission_withRawFunctionName (112.13s)
    testing.go:568: Step 1 error: Cannot import non-existent remote object: While attempting to import an existing object to aws_lambda_permission.allow_cloudwatch, the provider detected that no object exists with the given id. Only pre-existing objects can be imported; check that the id is correct and that it is associated with the provider's configured region or endpoint, or use "terraform apply" to create a new remote object for this resource.
FAIL
FAIL	github.com/terraform-providers/terraform-provider-aws/aws	112.194s

😥

@ryndaniels
Copy link
Contributor

Hi @chaspy! Thanks for the quick turnaround on those changes! I took a look at the new test failures you were seeing and I think I've found what's going on. It looks like there's a few mismatches in statementId and ResourceName in the different test blocks that are causing the failures we're seeing.

One way that we could simplify the tests and fix those would be to create a ImportStateIdFunc function, the same way you did in #9431. I was working on testing that out locally, and realized that we'll need a bit more logic to handle TestAccAWSLambdaPermission_withQualifier and TestAccAWSLambdaPermission_withStatementIdPrefix correctly. I'm going to go ahead and continue working on getting those finished, and I'll keep this PR updated as I do. 🙂

@ryndaniels
Copy link
Contributor

Latest acceptance test output:

--- PASS: TestLambdaPermissionGetFunctionNameFromLambdaArn_valid (0.00s)
--- PASS: TestLambdaPermissionUnmarshalling (0.00s)
--- PASS: TestLambdaPermissionGetQualifierFromLambdaAliasOrVersionArn_invalid (0.00s)
--- PASS: TestLambdaPermissionGetFunctionNameFromLambdaArn_invalid (0.00s)
--- PASS: TestLambdaPermissionGetQualifierFromLambdaAliasOrVersionArn_alias (0.00s)
--- PASS: TestLambdaPermissionGetQualifierFromLambdaAliasOrVersionArn_version (0.00s)
--- PASS: TestLambdaPermissionGetQualifierFromLambdaAliasOrVersionArn_govcloud (0.00s)
--- PASS: TestLambdaPermissionGetFunctionNameFromGovCloudLambdaArn (0.00s)
--- PASS: TestAccAWSLambdaPermission_withS3 (27.53s)
--- PASS: TestAccAWSLambdaPermission_withIAMRole (27.65s)
--- PASS: TestAccAWSLambdaPermission_withQualifier (27.97s)
--- PASS: TestAccAWSLambdaPermission_withRawFunctionName (28.06s)
--- PASS: TestAccAWSLambdaPermission_basic (27.91s)
--- PASS: TestAccAWSLambdaPermission_withStatementIdPrefix (28.22s)
--- PASS: TestAccAWSLambdaPermission_withSNS (28.23s)
--- PASS: TestAccAWSLambdaPermission_multiplePerms (34.30s)
--- PASS: TestAccAWSLambdaPermission_StatementId_Duplicate (83.63s)

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.

LGTM once the suggested changes are made and the testing passes 👍

@ryndaniels ryndaniels merged commit e29ff96 into hashicorp:master Aug 2, 2019
@ryndaniels ryndaniels added this to the v2.23.0 milestone Aug 2, 2019
@ghost
Copy link

ghost commented Aug 7, 2019

This has been released in version 2.23.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 Nov 2, 2019

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 Nov 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. enhancement Requests to existing resources that expand the functionality or scope. service/lambda Issues and PRs that pertain to the lambda service. size/M 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.

Support import for aws_lambda_permssion resource
3 participants