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 resource: aws_apigatewayv2_api_mapping #9461

Merged

Conversation

ewbankkit
Copy link
Contributor

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

Another resource for #7004.

Release note for CHANGELOG:

FEATURES:

* New Resource: aws_api_gateway_v2_api_mapping (#7004)

Output from acceptance testing:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSAPIGateway2ApiMapping_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -parallel 20 -run=TestAccAWSAPIGateway2ApiMapping_ -timeout 120m
=== RUN   TestAccAWSAPIGateway2ApiMapping_basic
=== PAUSE TestAccAWSAPIGateway2ApiMapping_basic
=== RUN   TestAccAWSAPIGateway2ApiMapping_ApiMappingKey
=== PAUSE TestAccAWSAPIGateway2ApiMapping_ApiMappingKey
=== CONT  TestAccAWSAPIGateway2ApiMapping_basic
=== CONT  TestAccAWSAPIGateway2ApiMapping_ApiMappingKey
--- PASS: TestAccAWSAPIGateway2ApiMapping_basic (34.49s)
--- PASS: TestAccAWSAPIGateway2ApiMapping_ApiMappingKey (97.05s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	97.120s

Currently based on #8842, will need to rebase once that PR is merged.

@ewbankkit ewbankkit requested a review from a team July 23, 2019 16:53
@ghost ghost added size/XXL Managed by automation to categorize the size of a PR. provider Pertains to the provider itself, rather than any interaction with AWS. documentation Introduces or discusses updates to documentation. service/apigateway Issues and PRs that pertain to the apigateway service. service/apigatewayv2 Issues and PRs that pertain to the apigatewayv2 service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Jul 23, 2019
@ewbankkit
Copy link
Contributor Author

Includes

@ewbankkit ewbankkit force-pushed the issue-7004.aws_api_gateway_v2_api_mapping branch from 1ec8a49 to 84d856d Compare July 28, 2019 20:37
@ewbankkit
Copy link
Contributor Author

Rebased to fix merge conflict.
Acceptance tests:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSAPIGateway2ApiMapping_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -parallel 20 -run=TestAccAWSAPIGateway2ApiMapping_ -timeout 120m
=== RUN   TestAccAWSAPIGateway2ApiMapping_basic
=== PAUSE TestAccAWSAPIGateway2ApiMapping_basic
=== RUN   TestAccAWSAPIGateway2ApiMapping_ApiMappingKey
=== PAUSE TestAccAWSAPIGateway2ApiMapping_ApiMappingKey
=== CONT  TestAccAWSAPIGateway2ApiMapping_basic
=== CONT  TestAccAWSAPIGateway2ApiMapping_ApiMappingKey
--- PASS: TestAccAWSAPIGateway2ApiMapping_ApiMappingKey (52.60s)
--- PASS: TestAccAWSAPIGateway2ApiMapping_basic (72.66s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	72.707s

@bflad bflad added the new-resource Introduces a new resource. label Jul 31, 2019
aws/structure.go Outdated Show resolved Hide resolved
@bflad bflad removed the service/apigateway Issues and PRs that pertain to the apigateway service. label Apr 15, 2020
@ewbankkit
Copy link
Contributor Author

After merge of #9391 and #9232, incorporate all the feedback:

  • Migrate to Terraform provider SDK
  • Change resource name to aws_apigatewayv2_blah; Rename source files
  • Remove sidebar_current from documentation
  • Add subcategory: "API Gateway v2 (WebSocket and HTTP APIs)" to documentation
  • Change function names to ApiGatewayV2
  • Add _disappears acceptance test
  • Use multierror in any test sweeper

@ewbankkit ewbankkit changed the title New resource: aws_api_gateway_v2_api_mapping New resource: aws_apigatewayv2_api_mapping Apr 17, 2020
@ewbankkit ewbankkit force-pushed the issue-7004.aws_api_gateway_v2_api_mapping branch from 6f28b78 to 01bf3a5 Compare April 17, 2020 12:39
@ghost ghost added size/XL Managed by automation to categorize the size of a PR. and removed size/XXL Managed by automation to categorize the size of a PR. labels Apr 17, 2020
@ewbankkit ewbankkit force-pushed the issue-7004.aws_api_gateway_v2_api_mapping branch from 01bf3a5 to 7922b81 Compare April 17, 2020 12:41
@ewbankkit
Copy link
Contributor Author

Renamed resource to aws_apigatewayv2_api_mapping.
Re-ran acceptance tests:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSAPIGatewayV2ApiMapping'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSAPIGatewayV2ApiMapping -timeout 120m
=== RUN   TestAccAWSAPIGatewayV2ApiMapping
=== RUN   TestAccAWSAPIGatewayV2ApiMapping/createCertificate
=== RUN   TestAccAWSAPIGatewayV2ApiMapping/basic
=== RUN   TestAccAWSAPIGatewayV2ApiMapping/disappears
=== RUN   TestAccAWSAPIGatewayV2ApiMapping/ApiMappingKey
--- PASS: TestAccAWSAPIGatewayV2ApiMapping (118.36s)
    --- PASS: TestAccAWSAPIGatewayV2ApiMapping/createCertificate (3.25s)
    --- PASS: TestAccAWSAPIGatewayV2ApiMapping/basic (32.32s)
    --- PASS: TestAccAWSAPIGatewayV2ApiMapping/disappears (30.17s)
    --- PASS: TestAccAWSAPIGatewayV2ApiMapping/ApiMappingKey (52.61s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	118.433s

Closes #7004.

@ewbankkit
Copy link
Contributor Author

The acceptance tests require that an ACM certificate be created outside of Terraform configuration (and left dangling after the tests finish) as any certificate created as part of the test configuration is in an associated state when deletion is attempted. This seems to be because the API Gateway domain name has a backing CloudFront distribution (in an AWS-owned account) and that can take up to 60 minutes to delete:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSAPIGatewayV2ApiMapping_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSAPIGatewayV2ApiMapping_ -timeout 120m
=== RUN   TestAccAWSAPIGatewayV2ApiMapping_basic
=== PAUSE TestAccAWSAPIGatewayV2ApiMapping_basic
=== RUN   TestAccAWSAPIGatewayV2ApiMapping_ApiMappingKey
=== PAUSE TestAccAWSAPIGatewayV2ApiMapping_ApiMappingKey
=== CONT  TestAccAWSAPIGatewayV2ApiMapping_basic
=== CONT  TestAccAWSAPIGatewayV2ApiMapping_ApiMappingKey
--- FAIL: TestAccAWSAPIGatewayV2ApiMapping_basic (635.71s)
    testing.go:730: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.
        
        Error: errors during apply: Error deleting certificate: ResourceInUseException: Certificate arn:aws:acm:us-west-2:123456789012:certificate/e2e672f5-1d17-4338-bd8d-98881d622293 in account 123456789012 is in use.
        
        State: aws_acm_certificate.test:
          ID = arn:aws:acm:us-west-2:123456789012:certificate/e2e672f5-1d17-4338-bd8d-98881d622293
          provider = provider.aws
          arn = arn:aws:acm:us-west-2:123456789012:certificate/e2e672f5-1d17-4338-bd8d-98881d622293
          certificate_authority_arn = 
          certificate_body = 790e1bd1153e851211df8beaf27cd09ecb1d21bc
          domain_name = tf-acc-test-7526054328147068447.example.com
          domain_validation_options.# = 0
          options.# = 1
          options.0.certificate_transparency_logging_preference = DISABLED
          private_key = 21d2128df77fad2a11f6d8b94470538213c74f12
          subject_alternative_names.# = 0
          tags.% = 1
          tags.Name = tf-acc-test-7526054328147068447
          validation_emails.# = 0
          validation_method = NONE
--- FAIL: TestAccAWSAPIGatewayV2ApiMapping_ApiMappingKey (668.35s)
    testing.go:730: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.
        
        Error: errors during apply: Error deleting certificate: ResourceInUseException: Certificate arn:aws:acm:us-west-2:123456789012:certificate/59441bc8-10e1-4679-848b-3996e65b7bbf in account 123456789012 is in use.
        
        State: aws_acm_certificate.test:
          ID = arn:aws:acm:us-west-2:123456789012:certificate/59441bc8-10e1-4679-848b-3996e65b7bbf
          provider = provider.aws
          arn = arn:aws:acm:us-west-2:123456789012:certificate/59441bc8-10e1-4679-848b-3996e65b7bbf
          certificate_authority_arn = 
          certificate_body = a245b90590f966072471d91eb7d54c0d47d11185
          domain_name = tf-acc-test-7248658647982118682.example.com
          domain_validation_options.# = 0
          options.# = 1
          options.0.certificate_transparency_logging_preference = DISABLED
          private_key = cc95ddca77f902c828ef60aa931cb55b3b6614da
          subject_alternative_names.# = 0
          tags.% = 1
          tags.Name = tf-acc-test-7248658647982118682
          validation_emails.# = 0
          validation_method = NONE
FAIL
FAIL	github.com/terraform-providers/terraform-provider-aws/aws	668.512s
FAIL
GNUmakefile:26: recipe for target 'testacc' failed
make: *** [testacc] Error 1

@ewbankkit
Copy link
Contributor Author

Ready for review.

Copy link
Contributor

@gdavison gdavison left a comment

Choose a reason for hiding this comment

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

This might need a resource sweeper, but otherwise LGTM 🚀

--- PASS: TestAccAWSAPIGatewayV2ApiMapping (99.68s)
--- PASS: TestAccAWSAPIGatewayV2ApiMapping/createCertificate (1.54s)
--- PASS: TestAccAWSAPIGatewayV2ApiMapping/basic (15.64s)
--- PASS: TestAccAWSAPIGatewayV2ApiMapping/disappears (38.98s)
--- PASS: TestAccAWSAPIGatewayV2ApiMapping/ApiMappingKey (43.52s)

"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

Copy link
Contributor

Choose a reason for hiding this comment

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

Should this have a sweeper, or will the resources get cleaned up when other resources are deleted?

Copy link
Contributor Author

@ewbankkit ewbankkit Apr 18, 2020

Choose a reason for hiding this comment

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

It's the aws_acm_certificate that was created that needs sweeping - I'll add a sweeper as that resource doesn't have one currently - #12888.
If I try to sweep APIs with API mappings defined I get:

$ SWEEP=us-west-2 SWEEP_DIR=./aws/ SWEEPARGS=-sweep-run=aws_apigatewayv2_api make sweep
WARNING: This will destroy infrastructure. Use only in development accounts.
go test ./aws/ -v -sweep=us-west-2 -sweep-run=aws_apigatewayv2_api -timeout 60m
2020/04/18 17:56:38 [DEBUG] Running Sweepers for region (us-west-2):
2020/04/18 17:56:38 [DEBUG] Running Sweeper (aws_apigatewayv2_api) in region (us-west-2)
2020/04/18 17:56:38 [INFO] Building AWS auth structure
2020/04/18 17:56:38 [INFO] Setting AWS metadata API timeout to 100ms
2020/04/18 17:56:39 [INFO] Ignoring AWS metadata API endpoint at default location as it doesn't return any instance-id
2020/04/18 17:56:39 [INFO] AWS Auth provider used: "EnvProvider"
2020/04/18 17:56:39 [DEBUG] Trying to get account information via sts:GetCallerIdentity
2020/04/18 17:56:40 [DEBUG] Trying to get account information via sts:GetCallerIdentity
2020/04/18 17:56:41 [INFO] Deleting API Gateway v2 API: bvowp2c4b5
2020/04/18 17:56:41 [ERROR] error deleting API Gateway v2 API (bvowp2c4b5): BadRequestException: Deleting RestApi bvowp2c4b5 failed. Please remove all base path mappings related to the RestApi in your domains.
2020/04/18 17:56:41 [ERROR] Error running Sweeper (aws_apigatewayv2_api) in region (us-west-2): 1 error occurred:
	* error deleting API Gateway v2 API (bvowp2c4b5): BadRequestException: Deleting RestApi bvowp2c4b5 failed. Please remove all base path mappings related to the RestApi in your domains.

FAIL	github.com/terraform-providers/terraform-provider-aws/aws	3.718s
FAIL
GNUmakefile:19: recipe for target 'sweep' failed
make: *** [sweep] Error 1

That error message seems to be a holdover from API Gateway v1 but it means that domain names need to be deleted first, so I've added a dependency to the aws_apigatewayv2_api sweeper:

$ SWEEP=us-west-2 SWEEP_DIR=./aws/ SWEEPARGS=-sweep-run=aws_apigatewayv2_api make sweep
WARNING: This will destroy infrastructure. Use only in development accounts.
go test ./aws/ -v -sweep=us-west-2 -sweep-run=aws_apigatewayv2_api -timeout 60m
2020/04/18 18:14:38 [DEBUG] Running Sweepers for region (us-west-2):
2020/04/18 18:14:38 [DEBUG] Sweeper (aws_apigatewayv2_api) has dependency (aws_apigatewayv2_domain_name), running..
2020/04/18 18:14:38 [DEBUG] Running Sweeper (aws_apigatewayv2_domain_name) in region (us-west-2)
2020/04/18 18:14:38 [INFO] Building AWS auth structure
2020/04/18 18:14:38 [INFO] Setting AWS metadata API timeout to 100ms
2020/04/18 18:14:40 [INFO] Ignoring AWS metadata API endpoint at default location as it doesn't return any instance-id
2020/04/18 18:14:40 [INFO] AWS Auth provider used: "EnvProvider"
2020/04/18 18:14:40 [DEBUG] Trying to get account information via sts:GetCallerIdentity
2020/04/18 18:14:40 [DEBUG] Trying to get account information via sts:GetCallerIdentity
2020/04/18 18:14:41 [INFO] Deleting API Gateway v2 domain name: example-ws-api.example.com
2020/04/18 18:14:42 [DEBUG] Running Sweeper (aws_apigatewayv2_api) in region (us-west-2)
2020/04/18 18:14:42 [INFO] Building AWS auth structure
2020/04/18 18:14:42 [INFO] Setting AWS metadata API timeout to 100ms
2020/04/18 18:14:43 [INFO] Ignoring AWS metadata API endpoint at default location as it doesn't return any instance-id
2020/04/18 18:14:43 [INFO] AWS Auth provider used: "EnvProvider"
2020/04/18 18:14:43 [DEBUG] Trying to get account information via sts:GetCallerIdentity
2020/04/18 18:14:43 [DEBUG] Trying to get account information via sts:GetCallerIdentity
2020/04/18 18:14:44 [INFO] Deleting API Gateway v2 API: m36pbck0ii
2020/04/18 18:14:46 [DEBUG] Sweeper (aws_apigatewayv2_domain_name) already ran in region (us-west-2)
2020/04/18 18:14:46 Sweeper Tests ran successfully:
	- aws_apigatewayv2_domain_name
	- aws_apigatewayv2_api
ok  	github.com/terraform-providers/terraform-provider-aws/aws	7.842s

@gdavison gdavison added this to the v2.59.0 milestone Apr 17, 2020
@gdavison gdavison added the waiting-response Maintainers are waiting on response from community or contributor. label Apr 17, 2020
@gdavison gdavison merged commit 9e943b9 into hashicorp:master Apr 20, 2020
@gdavison gdavison removed the waiting-response Maintainers are waiting on response from community or contributor. label Apr 20, 2020
gdavison added a commit that referenced this pull request Apr 20, 2020
@ewbankkit ewbankkit deleted the issue-7004.aws_api_gateway_v2_api_mapping branch April 20, 2020 21:14
@ghost
Copy link

ghost commented Apr 24, 2020

This has been released in version 2.59.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 May 21, 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 May 21, 2020
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. new-resource Introduces a new resource. provider Pertains to the provider itself, rather than any interaction with AWS. service/apigatewayv2 Issues and PRs that pertain to the apigatewayv2 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.

4 participants