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

Existing cache_key_parameters become uncached when new parameters are added #25736

Closed
joecritch opened this issue Jul 7, 2022 · 3 comments · Fixed by #29991 or #40124
Closed

Existing cache_key_parameters become uncached when new parameters are added #25736

joecritch opened this issue Jul 7, 2022 · 3 comments · Fixed by #29991 or #40124
Labels
bug Addresses a defect in current functionality. service/apigateway Issues and PRs that pertain to the apigateway service.
Milestone

Comments

@joecritch
Copy link

Terraform CLI and Terraform AWS Provider Version

Terraform v1.2.3
on darwin_arm64
+ provider registry.terraform.io/hashicorp/aws v4.21.0

(also broken on aws provider v3.x)

Affected Resource(s)

  • aws_api_gateway_*

Terraform Configuration Files

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.0"
    }
  }
}

provider "aws" {
  profile = "default"
  region = "us-east-1"
}

locals {
    api_name = "about_example"
    api_host = "http://api.example.com"
    api_stage_name = "dev"

    api_method_request_parameters = {
      "method.request.path.proxy" = true
      "method.request.header.Accept-Language" = false
      "method.request.querystring.test1" = false
      # "method.request.querystring.test2" = false
    }

    api_integration_cache_key_parameters = [
      "method.request.path.proxy",
      "method.request.header.Accept-Language",
      "method.request.querystring.test1"#,
      #"method.request.querystring.test2",
    ]
    
    api_integration_request_parameters = {
      "integration.request.path.proxy" = "method.request.path.proxy"
      "integration.request.header.Accept-Language" = "method.request.header.Accept-Language"
    }
}

resource "aws_api_gateway_rest_api" "about_example" {
  name = local.api_name
}

resource "aws_api_gateway_resource" "about_example" {
  parent_id   = aws_api_gateway_rest_api.about_example.root_resource_id
  rest_api_id = aws_api_gateway_rest_api.about_example.id
  path_part   = "{proxy+}"
}

resource "aws_api_gateway_method" "about_example" {
  authorization = "NONE"
  http_method   = "ANY"
  resource_id   = aws_api_gateway_resource.about_example.id
  rest_api_id   = aws_api_gateway_rest_api.about_example.id
  request_parameters = local.api_method_request_parameters
}

resource "aws_api_gateway_integration" "about_example" {
  http_method = aws_api_gateway_method.about_example.http_method
  integration_http_method = aws_api_gateway_method.about_example.http_method
  resource_id = aws_api_gateway_resource.about_example.id
  rest_api_id = aws_api_gateway_rest_api.about_example.id
  type        = "HTTP_PROXY"
  uri = "${format("%s/{proxy}", "${local.api_host}")}"
  passthrough_behavior     = "WHEN_NO_MATCH"
  timeout_milliseconds = 29000
  cache_key_parameters = local.api_integration_cache_key_parameters
  cache_namespace = "${local.api_stage_name}"
  request_parameters = local.api_integration_request_parameters
}

resource "aws_api_gateway_deployment" "about_example" {
  rest_api_id = aws_api_gateway_rest_api.about_example.id

  lifecycle {
    create_before_destroy = true
  }
}

resource "aws_api_gateway_stage" "about_example" {
  deployment_id = aws_api_gateway_deployment.about_example.id
  rest_api_id   = aws_api_gateway_rest_api.about_example.id
  stage_name    = local.api_stage_name
  cache_cluster_enabled = true
  cache_cluster_size = 0.5
}

resource "aws_api_gateway_method_settings" "all" {
  rest_api_id = aws_api_gateway_rest_api.about_example.id
  stage_name  = aws_api_gateway_stage.about_example.stage_name
  method_path = "*/*"

  settings {
    caching_enabled = true
    cache_ttl_in_seconds = 30
  }
}

Expected Behavior

When you add a new cache key parameter and a corresponding method request parameter (of the same name) to main.tf, it should be added to the `URL Query String Parameters' list, checked as 'Cached'. All other parameters should remain in-tact.

Actual Behavior

When you add the cache key parameter and method request parameter, it adds it, but it also unchecks the 'Cached' checkbox on all previous parameters.

Steps to Reproduce

  1. Run the example code, and terraform apply
  2. In the example main.tf, add a new test parameter to api_method_request_parameters and api_integration_request_parameters
  3. Run terraform apply
  4. Check AWS console (it will be broken at this point)
  5. Run terraform apply again
  6. Check AWS console again (it will be fixed at this point)

Output

First apply (when it breaks):

first-apply

Second apply (when it fixes):

second-apply

References

Here's a video of the issue...

Kapture.2022-07-07.at.21.10.03.mp4
@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. service/apigateway Issues and PRs that pertain to the apigateway service. labels Jul 7, 2022
@justinretzolk justinretzolk added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Jul 20, 2022
@felsteadd
Copy link

We've raised a similar issue today #29910

@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 issue 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 similar to this, 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 16, 2023
@YakDriver YakDriver reopened this Nov 14, 2024
@github-actions github-actions bot modified the milestones: v4.59.0, v5.76.0 Nov 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/apigateway Issues and PRs that pertain to the apigateway service.
Projects
None yet
4 participants