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

Adds validation to API Gateway Stage cache configuration #22861

Conversation

bpar476
Copy link

@bpar476 bpar476 commented Feb 1, 2022

Fails at plan step if cache_cluster_size is set but
cache_cluster_enabled is false or unset. Previously this plan would
continue to the apply step and fail after trying to deploy the stage
with a cryptic error message.

I just need a bit of help sorting out the acceptance test the - ExpectError isn't working. A different error from the terraform refresh is being propagated and caught by the ExpectError. I can see that the change is working and the error is occuring, I've also validated that the error occurs during a terraform plan by using the developer override on a simple terraform configuration. I'd also appreciate some guidance on the acceptance test coverage - specifically whether it's enough to cover only the update scenario or if there should be separate test cases for when this error occurs at creation and when it occurs at update.

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" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Relates OR Closes #22841

Output from acceptance testing:

stage_test.go:86: Step 5/6, expected an error with pattern, no match on: Error running pre-apply refresh: exit status 1
    Error: 1 error occurred:
        * error with API Gateway stage (ags-zmq20t827d-prod): cache_cluster_size is set to 0.5 but cache cluster is not enabled for this stage. Unset cache_cluster_size or set cache_cluster_enabled to true.

        with aws_api_gateway_stage.test,
        on terraform_plugin_test.tf line 55, in resource "aws_api_gateway_stage" "test":
        55: resource "aws_api_gateway_stage" "test" {
$ make testacc TESTS=TestAccAPIGatewayStage_cache PKG=apigateway

...

Fails at plan step if cache_cluster_size is set but
cache_cluster_enabled is false or unset. Previously this plan would
continue to the apply step and fail after trying to deploy the stage
with a cryptic error message.
@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/S Managed by automation to categorize the size of a PR. and removed needs-triage Waiting for first response or review from a maintainer. labels Feb 1, 2022
@bpar476
Copy link
Author

bpar476 commented Feb 1, 2022

For reference - here's the basic configuration I used to test that the error is raised locally:

provider "aws" {
  region = "us-east-2"
}

resource "aws_api_gateway_rest_api" "api" {
  name = "test-api"
}

resource "aws_api_gateway_deployment" "api_deployment" {
  rest_api_id = aws_api_gateway_rest_api.api.id
}


resource "aws_api_gateway_stage" "api_stage" {
  deployment_id = aws_api_gateway_deployment.api_deployment.id
  rest_api_id   = aws_api_gateway_rest_api.api.id
  stage_name    = "stage1"

  cache_cluster_enabled = false
  cache_cluster_size    = "0.5"
}

Results:

$ terraform plan
╷
│ Warning: Provider development overrides are in effect
│
│ The following provider development overrides are set in the CLI configuration:
│  - hashicorp/aws in /home/benpartridge/go/bin
│
│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases.
╵
╷
│ Error: 1 error occurred:
│       * error with API Gateway stage (): cache_cluster_size is set to 0.5 but cache cluster is not enabled for this stage. Unset cache_cluster_size or set cache_cluster_enabled to true.
│
│
│
│   with aws_api_gateway_stage.api_stage,
│   on main.tf line 18, in resource "aws_api_gateway_stage" "api_stage":
│   18: resource "aws_api_gateway_stage" "api_stage" {
│
╵

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Welcome @bpar476 👋

It looks like this is your first Pull Request submission to the Terraform AWS Provider! If you haven’t already done so please make sure you have checked out our CONTRIBUTING guide and FAQ to make sure your contribution is adhering to best practice and has all the necessary elements in place for a successful approval.

Also take a look at our FAQ which details how we prioritize Pull Requests for inclusion.

Thanks again, and welcome to the community! 😃

@bpar476
Copy link
Author

bpar476 commented Feb 14, 2022

Closing this in favour of #23091

@bpar476 bpar476 closed this Feb 14, 2022
@bpar476 bpar476 deleted the f-aws_apigateway_stage-cache-config-validation branch February 14, 2022 23:24
@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 May 18, 2022
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/S 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
1 participant