Skip to content

Default, empty, or null serverless_cache_usage_limits variable causes provider inconsistency error #268

@oycyc

Description

@oycyc

Describe the Bug

When serverless_cache_usage_limits is set to an empty object {} (or left unset, defaulting to {}) or null, the module creates an empty cache_usage_limits block in the aws_elasticache_serverless_cache resource. AWS rejects this empty block during apply, causing a "Provider produced inconsistent result after apply" error.

Steps to Reproduce

  1. Call the module with serverless_enabled = true
  2. Either:
    • Set serverless_cache_usage_limits = null, OR
    • Don't set serverless_cache_usage_limits at all (uses default, which is currently {})
  3. Run tofu apply
Image

Error Message

Error: Provider produced inconsistent result after apply

When applying changes to module.valkey_redis.aws_elasticache_serverless_cache.default[0], 
provider "provider["registry.opentofu.org/hashicorp/aws"]" produced an unexpected new value:
.cache_usage_limits: block count changed from 1 to 0.

Plan Output

The plan shows an empty block being created:

cache_usage_limits {
}

Root Cause

The variable default value is {} (empty object), which causes the dynamic block to iterate once but produce no nested content:

dynamic "cache_usage_limits" {
  for_each = try([var.serverless_cache_usage_limits], [])
  # When var is {}, this becomes [{}], creating an empty block

AWS/the provider expects either:

  • No cache_usage_limits block at all, OR
  • A cache_usage_limits block with at least one nested data_storage or ecpu_per_second block

Even if we explicitly pass in null as serverless_cache_usage_limits, it will go back to the default of {}.

Suggested Fix

Change the current default of {} to null

variable "serverless_cache_usage_limits" {
  type        = map(any)
  default     = null
  description = "The usage limits for the serverless cache"
}

Expected Behavior

See above.

Steps to Reproduce

See above.

Screenshots

No response

Environment

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug🐛 An issue with the system

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions