Search code examples
amazon-web-servicesterraformterraform-provider-awsamazon-elasticache

Creating custom parameter group in AWS Elasticache based on default groups


I am trying to create custom parameter group in AWS Elasticache.

I'd like to use a default parameter group as a base (group named default.redis5.0.cluster.on, as there is everything else I need but just one property I'd like to change), see https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/ParameterGroups.Redis.html for more details about default parameter groups

My basic assumption would be that I'd need to copy the default parameter group values to a Terraform resource and then just modify the only parameter I need to change. However, this would produce huge list of parameters and wouldn't seem the simplest way to do this.

If I need to do copy parameters in the default.redis5.0.cluster.on parameter group, then I'd need to have those in Terraform. Is there a way to import a default resource group as Terraform configuration?


Solution

  • It's possible to create parameter group with family = redis5.0 that has got almost identical parameters with the default parameter group default.redis5.0.cluster.on.

    I ended up doing JSON diff for the properties in the two parameter groups: default.redis5.0and default.redis5.0.cluster.onand there was just one parameter difference. First, get the parameter groups as JSON:

    aws elasticache describe-cache-parameters --cache-parameter-group-name default.redis5.0.cluster.on > default.redis5.0.cluster.on.json
    aws elasticache describe-cache-parameters --cache-parameter-group-name default.redis5.0 > default.redis5.0.json
    

    Then do a JSON diff for the two files to obtain parameters that are different. There was only one, cluster-enabled so after that it was trivial to do a custom resource group that had same parameter values as default.redis5.0.cluster.on this way:

    resource "aws_elasticache_parameter_group" "aws_elasticache_parameter_group" {
      name        = "cache-params"
      family      = "redis5.0"
      description = "The parameter group has same values as default parameter group default.redis5.0.cluster.on"
    
      parameter {
        name  = "cluster-enabled"
        value = "yes"
      }
    }