- Newest
- Most votes
- Most comments
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
Relevant content
asked 3 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.