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

b-cachekeyparameters-29910 #29991

Merged
merged 13 commits into from
Mar 15, 2023
Merged

b-cachekeyparameters-29910 #29991

merged 13 commits into from
Mar 15, 2023

Conversation

deepan83
Copy link
Contributor

@deepan83 deepan83 commented Mar 14, 2023

Description

This PR looks to address 2 open issues where the addition of a new request parameter removes caching settings (via cacheKeyParameters on integration) on existing request parameters.

Analysis

  1. The issue (confirmed via observing the provider logs when the test runs and debugging the provider code) is that when you add a new supporting request parameter to support a new cache key parameter, Terraform recognises the change in the request parameter set but sends a replace op via an update method call in (https://gh.neting.cc.mcas.ms/hashicorp/terraform-provider-aws/blob/main/internal/service/apigateway/flex.go) for existing request parameters with unchanged values in addition to add ops for new request parameters. The replace op is effectively remove and add so it recreates the request parameter but this action removes any previous caching setting on the parameter (and from the cacheKeyParameters list on the integration resource)
  2. This hence will also be an issue when you add a new request parameter without adding it to the cacheKeyParameters. Any previous request parameters that had caching set on them will lose them.

Implemented Fix

  1. Stop the replace operation when the request parameter already exists and its value hasn't changed
  2. When the parameter exists but the value has changed, then replace needs doing but subsequently it also needs to be added back to the cacheParameterKeys list if it existed originally there

Closes

Closes #29910.
Closes #25736.

References

Output from Acceptance Testing

$ make testacc TESTS=TestAccAPIGatewayIntegration_CacheKeyUpdate_parameters PKG=apigateway
TF_ACC=1 go test ./internal/service/apigateway/... -v -count 1 -parallel 20 -run='TestAccAPIGatewayIntegration_CacheKeyUpdate_parameters'  -timeout 180m
=== RUN   TestAccAPIGatewayIntegration_CacheKeyUpdate_parameters
=== PAUSE TestAccAPIGatewayIntegration_CacheKeyUpdate_parameters
=== CONT  TestAccAPIGatewayIntegration_CacheKeyUpdate_parameters
add/cacheKeyParameters/method.request.querystring.test12023-03-14T14:07:36.953Z [WARN]  sdk.helper_schema: Previously configured provider being re-configured. This can cause issues in concurrent testing if the configurations are not equal.: tf_req_id=05af2e85-9450-c507-1509-5dab9d9ca62f tf_provider_addr=registry.terraform.io/hashicorp/aws tf_rpc=ConfigureProvider tf_mux_provider="*schema.GRPCProviderServer"
--- PASS: TestAccAPIGatewayIntegration_CacheKeyUpdate_parameters (40.85s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/apigateway	64.798s
Successfully remade target file `testacc'.
...

New to GO and first contribution to Terraform so fully happy to be guided, the above new test would fail without the fix code with a After applying this test step and performing a 'terraform refresh', the plan was not empty.' message with the parameter in question but I havent been able to add a failing assert without the fix code (despite the test step leaving the gateway in the state with the issue described)

@github-actions
Copy link

Community Note

Voting for Prioritization

  • Please vote on this pull request by adding a 👍 reaction to the original post to help the community and maintainers prioritize this pull request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

For Submitters

  • Review the contribution guide relating to the type of change you are making to ensure all of the necessary steps have been taken.
  • For new resources and data sources, use skaff to generate scaffolding with comments detailing common expectations.
  • Whether or not the branch has been rebased will not impact prioritization, but doing so is always a welcome surprise.

@github-actions github-actions bot added service/apigateway Issues and PRs that pertain to the apigateway service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. needs-triage Waiting for first response or review from a maintainer. size/L Managed by automation to categorize the size of a PR. and removed needs-triage Waiting for first response or review from a maintainer. labels Mar 14, 2023
@deepan83 deepan83 marked this pull request as ready for review March 14, 2023 14:24
deepan83 and others added 7 commits March 14, 2023 21:12
Acceptance test output:

% make testacc TESTARGS='-run=TestAccAPIGatewayAccount_' PKG=apigateway
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/apigateway/... -v -count 1 -parallel 20  -run=TestAccAPIGatewayAccount_ -timeout 180m
=== RUN   TestAccAPIGatewayAccount_basic
=== PAUSE TestAccAPIGatewayAccount_basic
=== CONT  TestAccAPIGatewayAccount_basic
--- PASS: TestAccAPIGatewayAccount_basic (145.91s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/apigateway	151.265s
@github-actions github-actions bot added size/XL Managed by automation to categorize the size of a PR. and removed size/L Managed by automation to categorize the size of a PR. labels Mar 15, 2023
Copy link
Contributor

@ewbankkit ewbankkit left a comment

Choose a reason for hiding this comment

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

LGTM 🚀.

% make testacc TESTARGS='-run=TestAccAPIGatewayMethod_\|TestAccAPIGatewayMethodResponse_' PKG=apigateway ACCTEST_PARALLELISM=3
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/apigateway/... -v -count 1 -parallel 3  -run=TestAccAPIGatewayMethod_\|TestAccAPIGatewayMethodResponse_ -timeout 180m
=== RUN   TestAccAPIGatewayMethodResponse_basic
=== PAUSE TestAccAPIGatewayMethodResponse_basic
=== RUN   TestAccAPIGatewayMethodResponse_disappears
=== PAUSE TestAccAPIGatewayMethodResponse_disappears
=== RUN   TestAccAPIGatewayMethod_basic
=== PAUSE TestAccAPIGatewayMethod_basic
=== RUN   TestAccAPIGatewayMethod_customAuthorizer
=== PAUSE TestAccAPIGatewayMethod_customAuthorizer
=== RUN   TestAccAPIGatewayMethod_cognitoAuthorizer
=== PAUSE TestAccAPIGatewayMethod_cognitoAuthorizer
=== RUN   TestAccAPIGatewayMethod_customRequestValidator
=== PAUSE TestAccAPIGatewayMethod_customRequestValidator
=== RUN   TestAccAPIGatewayMethod_disappears
=== PAUSE TestAccAPIGatewayMethod_disappears
=== RUN   TestAccAPIGatewayMethod_operationName
=== PAUSE TestAccAPIGatewayMethod_operationName
=== CONT  TestAccAPIGatewayMethodResponse_basic
=== CONT  TestAccAPIGatewayMethod_cognitoAuthorizer
=== CONT  TestAccAPIGatewayMethod_operationName
=== CONT  TestAccAPIGatewayMethod_cognitoAuthorizer
    method_test.go:110: Step 1/3 error: After applying this test step, the plan was not empty.
        stdout:
        
        
        Terraform used the selected providers to generate the following execution
        plan. Resource actions are indicated with the following symbols:
          ~ update in-place
        
        Terraform will perform the following actions:
        
          # aws_cognito_user_pool.pool will be updated in-place
          ~ resource "aws_cognito_user_pool" "pool" {
                id                        = "us-west-2_bdxo99mUD"
                name                      = "tf-acc-test-112159726476929413"
                # (8 unchanged attributes hidden)
        
              ~ account_recovery_setting {
                  - recovery_mechanism {
                      - name     = "verified_email" -> null
                      - priority = 1 -> null
                    }
                  - recovery_mechanism {
                      - name     = "verified_phone_number" -> null
                      - priority = 2 -> null
                    }
                }
        
        
        
        
                # (4 unchanged blocks hidden)
            }
        
        Plan: 0 to add, 1 to change, 0 to destroy.
--- FAIL: TestAccAPIGatewayMethod_cognitoAuthorizer (22.06s)
=== CONT  TestAccAPIGatewayMethod_disappears
--- PASS: TestAccAPIGatewayMethodResponse_basic (52.98s)
=== CONT  TestAccAPIGatewayMethod_customRequestValidator
--- PASS: TestAccAPIGatewayMethod_operationName (86.27s)
=== CONT  TestAccAPIGatewayMethod_basic
--- PASS: TestAccAPIGatewayMethod_customRequestValidator (68.40s)
=== CONT  TestAccAPIGatewayMethod_customAuthorizer
--- PASS: TestAccAPIGatewayMethod_disappears (138.06s)
=== CONT  TestAccAPIGatewayMethodResponse_disappears
--- PASS: TestAccAPIGatewayMethodResponse_disappears (65.05s)
--- PASS: TestAccAPIGatewayMethod_customAuthorizer (104.20s)
--- PASS: TestAccAPIGatewayMethod_basic (252.43s)
FAIL
FAIL	github.com/hashicorp/terraform-provider-aws/internal/service/apigateway	351.254s
FAIL
make: *** [testacc] Error 1
% make testacc TESTARGS='-run=TestAccAPIGatewayIntegration_' PKG=apigateway ACCTEST_PARALLELISM=3
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/apigateway/... -v -count 1 -parallel 3  -run=TestAccAPIGatewayIntegration_ -timeout 180m
=== RUN   TestAccAPIGatewayIntegration_basic
=== PAUSE TestAccAPIGatewayIntegration_basic
=== RUN   TestAccAPIGatewayIntegration_contentHandling
=== PAUSE TestAccAPIGatewayIntegration_contentHandling
=== RUN   TestAccAPIGatewayIntegration_CacheKey_parameters
=== PAUSE TestAccAPIGatewayIntegration_CacheKey_parameters
=== RUN   TestAccAPIGatewayIntegration_CacheKeyUpdate_parameters
=== PAUSE TestAccAPIGatewayIntegration_CacheKeyUpdate_parameters
=== RUN   TestAccAPIGatewayIntegration_integrationType
=== PAUSE TestAccAPIGatewayIntegration_integrationType
=== RUN   TestAccAPIGatewayIntegration_TLS_insecureSkipVerification
=== PAUSE TestAccAPIGatewayIntegration_TLS_insecureSkipVerification
=== RUN   TestAccAPIGatewayIntegration_disappears
=== PAUSE TestAccAPIGatewayIntegration_disappears
=== CONT  TestAccAPIGatewayIntegration_basic
=== CONT  TestAccAPIGatewayIntegration_integrationType
=== CONT  TestAccAPIGatewayIntegration_disappears
--- PASS: TestAccAPIGatewayIntegration_disappears (17.85s)
=== CONT  TestAccAPIGatewayIntegration_CacheKey_parameters
--- PASS: TestAccAPIGatewayIntegration_CacheKey_parameters (32.43s)
=== CONT  TestAccAPIGatewayIntegration_CacheKeyUpdate_parameters
--- PASS: TestAccAPIGatewayIntegration_CacheKeyUpdate_parameters (32.64s)
=== CONT  TestAccAPIGatewayIntegration_contentHandling
--- PASS: TestAccAPIGatewayIntegration_basic (120.04s)
=== CONT  TestAccAPIGatewayIntegration_TLS_insecureSkipVerification
--- PASS: TestAccAPIGatewayIntegration_contentHandling (62.11s)
--- PASS: TestAccAPIGatewayIntegration_TLS_insecureSkipVerification (55.46s)
--- PASS: TestAccAPIGatewayIntegration_integrationType (683.81s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/apigateway	689.284s
% make testacc TESTARGS='-run=TestAccAPIGatewayAccount_' PKG=apigateway
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/apigateway/... -v -count 1 -parallel 20  -run=TestAccAPIGatewayAccount_ -timeout 180m
=== RUN   TestAccAPIGatewayAccount_basic
=== PAUSE TestAccAPIGatewayAccount_basic
=== CONT  TestAccAPIGatewayAccount_basic
--- PASS: TestAccAPIGatewayAccount_basic (145.91s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/apigateway	151.265s

The failure is unrelated to this change and has started occurring recently in our CI (#30030).

@ewbankkit
Copy link
Contributor

@deepan83 Thanks for the contribution 🎉 👏.

@ewbankkit ewbankkit merged commit eb02d81 into hashicorp:main Mar 15, 2023
@github-actions github-actions bot added this to the v4.59.0 milestone Mar 15, 2023
@github-actions
Copy link

This functionality has been released in v4.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. Thank you!

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/apigateway Issues and PRs that pertain to the apigateway 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
2 participants