Terraform部署AWS ElastiCache Redis时config-file参数报错问题
AWS ElastiCache Redis 自定义配置的 Terraform 问题解决
我在编写Terraform代码部署AWS ElastiCache Redis实例时,想沿用本地Redis的方式通过redis.conf配置文件来配置实例,于是写了这段代码:
resource "aws_elasticache_parameter_group" "redis_parameter_group" { name = "cache-params" family = "redis5.0" description = "custom Redis parameter group to use redis.conf" parameter { name = "config-file" value = file("${path.module}/config/redis.conf") # path to custom redis.conf file } }
执行terraform apply时遇到报错:
Could not find parameter with name: config-file
问题原因与解决方法
- AWS ElastiCache是托管式Redis服务,不支持通过
config-file参数直接加载本地的redis.conf文件,这是本地自建Redis的用法,不适用于ElastiCache。 - 正确操作是把
redis.conf里的配置项逐一拆解,在aws_elasticache_parameter_group的parameter块中单独设置每个参数。 - 示例(假设你的
redis.conf包含maxmemory 1gb和maxmemory-policy allkeys-lru两个配置):
resource "aws_elasticache_parameter_group" "redis_parameter_group" { name = "cache-params" family = "redis5.0" description = "custom Redis parameter group" parameter { name = "maxmemory" value = "1gb" } parameter { name = "maxmemory-policy" value = "allkeys-lru" } }
- 注意:并非所有本地Redis的配置项都能在ElastiCache中配置,具体可查看AWS官方文档中ElastiCache Redis支持的参数清单。
内容的提问来源于stack exchange,提问作者blackstorm
相关产品推荐
相关产品推荐

