Skip to content

API Gateway get-stage call returns out of date information

0

I'm attempting to use terraform to update my API Gateway Stage. After manually updating my configuration to inactivate my cache cluster, aws cli calls still show my cacheClusterSize of having 0.5. It correctly shows the cacheClusterEnabled field as false though. Why would the cacheClusterSize still come back in the response if the cacheClusterEnabled field is set to false? This is causing problems with my "terraform apply" command, since each time I go to apply other changes it tries to remove the 0.5 cacheClusterSize that doesn't actually exist.

Steps to reproduce:

  1. Have an api gateway stage with cache cluster enabled and set to 0.5GB.
  2. Use the apigateway get-stage cli call to retrieve information on the stage.
  3. Manually disable the stage cache in the console.
  4. Use the apigateway get-stage cli call again to retrieve information on the stage. Notice that the cache will show as not enabled, but the cacheClusterSize remains.
1 Answer
0
Accepted Answer

The behavior you're experiencing with the API Gateway get-stage call returning seemingly outdated information is actually expected behavior, although it can be confusing.

When you disable the cache cluster for a stage in API Gateway, the cacheClusterEnabled field is set to false, which is correctly reflected in the get-stage response. However, the cacheClusterSize field remains in the response even when caching is disabled. This is because API Gateway retains the last known cache cluster size configuration, even if the cache is currently disabled.

This retention of the cacheClusterSize serves a purpose. If you were to re-enable caching for the stage, API Gateway would use this retained size as the default, allowing for a quicker setup if you decide to turn caching back on.

For Terraform, this can indeed cause issues as you've noticed. Terraform sees the cacheClusterSize field in the response and assumes it needs to manage this setting, even though the cache is disabled.

To resolve this issue in your Terraform configuration, you can use a conditional expression to only set the cacheClusterSize when caching is enabled. For example:

resource "aws_api_gateway_stage" "example" {
# ... other configuration ...
cache_cluster_enabled = false
cache_cluster_size    = var.cache_cluster_enabled ? var.cache_cluster_size : null
}

This way, when caching is disabled (cache_cluster_enabled = false), Terraform will not try to manage the cache_cluster_size at all, avoiding the conflict you're experiencing.

Remember, the presence of cacheClusterSize in the API response doesn't mean there's an actual cache cluster running. It's just a configuration value that API Gateway retains for potential future use.
Sources
GetStage - Amazon API Gateway
UpdateStage - Amazon API Gateway
Stage - Amazon API Gateway

answered 2 years ago

  • The answer about the get-stage api call makes sense on keeping the cacheClusterSize attribute around, thank you. Changing the terraform code to what is described above, doesn't work though since terraform still tries to delete the cacheClusterSize attribute.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.